public SOM(int inputDims, int outputDims, int width = 10, int height = 10, double alpha = 0.9, double beta = 0.1) { InputDims = inputDims; OutputDims = outputDims; Width = width; Height = height; Alpha = alpha; Beta = beta; Radius = 4; _nodes = new Vector[width, height]; for (int x = 0; x <= _nodes.GetUpperBound(0); x++) { for (int y = 0; y <= _nodes.GetUpperBound(1); y++) { Random rnd = new Random(); var node = new Vector(); node.Input = new double[inputDims]; for (int i = 0; i < InputDims; i++) { node.Input[i] = rnd.NextDouble(); } node.Output = new double[outputDims]; for (int i = 0; i < OutputDims; i++) { node.Output[i] = rnd.NextDouble(); } _nodes[x, y] = node; } } }
public static MeshBuilder RectGrid(Vector[,] points, bool closed0 = false, bool closed1 = false) { var mb = new MeshBuilder(); var rows = points.GetUpperBound(0) + 1; var columns = points.GetUpperBound(1) + 1; var index0 = 0; for (var i = 0; i < rows; i++) { for (var j = 0; j < columns; j++) { mb.Vertices.Add(points[i, j]); } } mb.MakeRectGridFaces(index0, rows, columns, closed0, closed1); return(mb); }
int[] FindBMU(double[] v) { int[] coord = new int[2]; double minSum = -1.0; for (int row = 0; row <= _nodes.GetUpperBound(0); row++) { for (int col = 0; col <= _nodes.GetUpperBound(1); col++) { var a = _nodes[row, col].Input.Zip(v, (v1, v2) => Math.Pow((v1 - v2), 2)).Sum(); if (minSum > a || minSum < 0) { minSum = a; coord[X] = row; coord[Y] = col; } } } return(coord); }