private void InitializeNetwork() { IsLearningRightNow = false; wpfGraphics.Clear(); X = new double[10000, 2]; Y = new double[10000, 3]; for (int x = 0; x < 100; x++) { for (int y = 0; y < 100; y++) { X[x * 100 + y, 0] = (double)(((double)(x - 50)) / 50); X[x * 100 + y, 1] = (double)(((double)(y - 50)) / 50); Y[x * 100 + y, 0] = getDouble((GetPixelColor(TestBitmap, x, y).R)); Y[x * 100 + y, 1] = getDouble((GetPixelColor(TestBitmap, x, y).G)); Y[x * 100 + y, 2] = getDouble((GetPixelColor(TestBitmap, x, y).B)); } } Layer[] layers = new Layer[2 + HiddenLayers.Count()]; layers[0] = new Layer(LayerType.Input, X, ActivationFunction.RELU); for (int i = 1; i < HiddenLayers.Count() + 1; i++) { layers[i] = HiddenLayers[i - 1]; } layers[layers.Count() - 1] = new Layer(LayerType.Output, Y, ActivationFunction.Tanh); nn = new NEngine(layers, Y, LearningRate, 0, BatchSize); nn.ForwardPropagation(); }
private void AddNewPoint(MouseButton mb) { IsLearningRightNow = false; Point p = new Point(PanelX, PanelY); if (mb == MouseButton.Left) { BluePoint.Add(p); } else { OrangePoint.Add(p); } wpfGraphics.Clear(); DrawPoints(); double[,] X = new double[BluePoint.Count() + OrangePoint.Count(), 2]; double[,] Y = new double[BluePoint.Count() + OrangePoint.Count(), 2]; for (int i = 0; i < BluePoint.Count(); i++) { X[i, 0] = BluePoint[i].X / 300; X[i, 1] = BluePoint[i].Y / 300; Y[i, 0] = 1; Y[i, 1] = -1; } for (int i = BluePoint.Count(); i < BluePoint.Count() + OrangePoint.Count(); i++) { X[i, 0] = (OrangePoint[i - BluePoint.Count()].X / 300); X[i, 1] = (OrangePoint[i - BluePoint.Count()].Y / 300); Y[i, 0] = -1; Y[i, 1] = 1; } MatrixExtensions.Unsort(ref X, ref Y); X.SplitMatrix(out X2, out TestX, LearnToTest); Y.SplitMatrix(out Y2, out TestY, LearnToTest); Layer[] layers = new Layer[2 + HiddenLayers.Count()]; layers[0] = new Layer(LayerType.Input, X2, ActivationFunction.Tanh); for (int i = 1; i < HiddenLayers.Count() + 1; i++) { layers[i] = HiddenLayers[i - 1]; } layers[layers.Count() - 1] = new Layer(LayerType.Output, Y2, ActivationFunction.Tanh); nn = new NEngine(layers, Y2, LearningRate, 0); nn.ForwardPropagation().Print(); }