谁能告诉如何从训练好的网络中获取/分配集群类/标签。
这是代码示例,让您了解我如何执行它:
Accord.Math.Random.Generator.Seed = 0;
int numberOfInputs = 3;
int hiddenNeurons = 25;
double[][] input =
{
new double[] { -1, -1, -1 },
new double[] { -1, 1, -1 },
new double[] { 1, -1, -1 },
new double[] { 1, 1, -1 },
new double[] { -1, -1, 1 },
new double[] { -1, 1, 1 },
new double[] { 1, -1, 1 },
new double[] { 1, 1, 1 },
// ...
};
var network = new DistanceNetwork(numberOfInputs, hiddenNeurons);
var teacher = new SOMLearning(network);
double error = double.PositiveInfinity;
for (int i = 0; i < 1000; i++)
error = teacher.RunEpoch(input);
// how can I know/assign class/label of each item in input array?
雅阁示例可能会进一步提供帮助:
群集 (SOM(
特别是本节:
for (int y = 0, i = 0; y < 100; y++)
{
// for all pixels
for (int x = 0; x < 100; x++, i++, ptr += 6)
{
Neuron neuron = layer.Neurons[i];
// red
ptr[2] = ptr[2 + 3] = ptr[2 + stride] = ptr[2 + 3 + stride] =
(byte)Math.Max(0, Math.Min(255, neuron.Weights[0]));
// green
ptr[1] = ptr[1 + 3] = ptr[1 + stride] = ptr[1 + 3 + stride] =
(byte)Math.Max(0, Math.Min(255, neuron.Weights[1]));
// blue
ptr[0] = ptr[0 + 3] = ptr[0 + stride] = ptr[0 + 3 + stride] =
(byte)Math.Max(0, Math.Min(255, neuron.Weights[2]));
}
ptr += offset;
ptr += stride;
}