Answer the question
In order to leave comments, you need to log in
Point clustering using the Kohonen network. How to change weight coefficients?
The network has two inputs (coordinates of points x and y) and two outputs - one of them is 1, the other 0 (according to which
cluster the point belongs to). Submitting successively (separately) points to the input, configure the network so that it acquires the ability to determine which cluster the point belongs to. Choose the coefficient by decreasing it from step to step according to the rule (50-i)/100, and for each neuron this will be its own value , and the weights of only one (winning) neuron will be adjusted at each step.
I'm just getting started with neural networks. The program incorrectly identifies the cluster. The error, probably, is in changing the weight coefficients, now I am changing them according to the formula w (new) \u003d w (old) + a (speed coefficient) * (w (new) - x (incoming vector)). Tell me please.
class Network
{
/// <summary>
/// Массив для хранения отмасшатированных сигналов
/// </summary>
public double[,] mul = new double[2, 2];
/// <summary>
/// Массив для хранения весов
/// </summary>
public double[,] weight = new double[2, 2];
/// <summary>
/// Входящий вектор. Координата [x,y]
/// </summary>
public int[] input = new int[2];
/// <summary>
/// Суммы отмасштабированных сигналов
/// </summary>
public double[] sum = new double[2];
/// <summary>
/// Итерация обучения. Используется для модификация коэф-та скорости обучения.
/// </summary>
public int[] iter = new int[2] {0,0};
public Network()
{
Random r = new Random();
// Инициализация весов случайными числами
for (int x = 0; x < 2; x++)
{
for (int y = 0; y < 2; y++)
{
weight[x, y] = r.NextDouble() * 1;
}
}
}
public int GetRez(int[] inP)
{
input = inP;
// Масштабирование сигналов
for (int x = 0; x < 2; x++)
{
for (int y = 0; y < 2; y++)
{
// Умножаем его сигнал на вес и сохраняем в массив
mul[x, y] = input[x] * weight[x, y];
}
}
// Сумматор сигналов
for (int x = 0; x < 2; x++)
{
for (int y = 0; y < 2; y++)
{
sum[y] += mul[x, y];
}
}
// Определение нейрона "победителя"
if (sum[0] > sum[1])
{
// коэф изменения
double ch = (50 - iter[0]) / 100.0;
// изменение весовых коэф
weight[0, 1] = weight[0, 1] + ch * (input[0] - weight[0, 1]);
weight[1, 0] = weight[1, 0] + ch * (input[1] - weight[1, 0]);
iter[0]++;
return 1;
}
else
{
// коэф изменения
double ch = (50 - iter[1]) / 100.0;
// изменение весовых коэф
weight[0, 0] = weight[0, 0] + ch * (input[0] - weight[0, 0]);
weight[1, 1] = weight[1, 1] + ch * (input[1] - weight[1, 1]);
iter[1]++;
return 0;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question