public static void UpdateCentresActivitiesAndCordinatesKohonen(int minX, int minY, Centre[,] centresMatrix, List <Point> points, Centre winner, Centre tired, int randomIndex) { for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { double deltaX = 0; double deltaY = 0; if (((i == (minX - 1) && j == minY) || (i == (minX + 1) && j == minY) || (i == minX && j == (minY - 1)) || (i == minX && j == (minY - 1))) && centresMatrix[i, j] != tired ) { deltaX = points[randomIndex].x - centresMatrix[i, j].x; deltaY = points[randomIndex].y - centresMatrix[i, j].y; centresMatrix[i, j].x += currentLearningRate * 0.5 * deltaX; centresMatrix[i, j].y += currentLearningRate * 0.5 * deltaY; } if (neighborhood == Neighborhood.far) { if (((i == (minX - 1) && j == (minY - 1)) || (i == (minX - 1) && j == (minY + 1)) || (i == (minX + 1) && j == (minY - 1)) || (i == (minX - 1) && j == (minY - 1))) && centresMatrix[i, j] != tired ) { deltaX = points[randomIndex].x - centresMatrix[i, j].x; deltaY = points[randomIndex].y - centresMatrix[i, j].y; centresMatrix[i, j].x += currentLearningRate * 0.25 * deltaX; centresMatrix[i, j].y += currentLearningRate * 0.25 * deltaY; } } if (centresMatrix[i, j] == winner) { deltaX = points[randomIndex].x - winner.x; deltaY = points[randomIndex].y - winner.y; winner.x += currentLearningRate * 1 * deltaX; winner.y += currentLearningRate * 1 * deltaY; winner.activity -= 0.5; } if (centresMatrix[i, j] != winner) { centresMatrix[i, j].activity += 1.0 / (rows * columns); } } } }
public static void FindWinnerCordinates(ref int x, ref int y, Centre[,] centresMatrix, Centre winner) { for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { if (centresMatrix[i, j] == winner) { x = i; y = j; } } } }