public NeuralNetwork(int[] Layer, ActivationStrategy ActivationFunction) { Layers = new MLPLayer[Layer.Length - 1]; for (int i = 0; i < Layers.Length; i++) { Layers[i] = new MLPLayer(); Layers[i].InitializeLayer(Layer[i], Layer[i + 1], ActivationFunction); if (i < Layers.Length - 1) { this.layerBuild += Layer[i] + "-"; } else { this.layerBuild += Layer[i]; } } this.Activation = ActivationFunction; }
private void CreateNetworkByTxt(string fileName) { StreamReader sr; try { sr = new StreamReader(fileName); } catch (FileNotFoundException) { MessageBox.Show("Nincs ilyen file!"); return; } catch (Exception) { MessageBox.Show("Ismeretlen hiba"); return; } string[] atm = sr.ReadLine().Split(':'); //0-> Layers | 1 -> Activation Function nn = new NeuralNetwork(getLayersBuild(atm), getActi(atm)); List <MLPLayer> atmLayers = new List <MLPLayer>(); while (!sr.EndOfStream) { string[] atm2 = sr.ReadLine().Split(':'); int atmNumberOfInputs = Convert.ToInt32(atm2[0].ToString()); int atmNumberOfOutputs = Convert.ToInt32(atm2[1].ToString()); MLPLayer atmLayer = new MLPLayer(); atmLayer.NumberOfInput = atmNumberOfInputs; atmLayer.NumberOfOutput = atmNumberOfOutputs; atmLayer.ActivationStrategy = nn.Activation; double[] atmOutputs = new double[atmNumberOfOutputs]; atm = sr.ReadLine().Split(':'); for (int i = 0; i < atmOutputs.Length; i++) { atmOutputs[i] = Convert.ToDouble(atm[i].ToString()); } atmLayer.Output = atmOutputs; double[] atmInputs = new double[atmNumberOfInputs]; atm = sr.ReadLine().Split(':'); for (int i = 0; i < atmInputs.Length; i++) { atmInputs[i] = Convert.ToDouble(atm[i].ToString()); } atmLayer.Input = atmInputs; double[,] atmWeights = new double[atmNumberOfOutputs, atmNumberOfInputs]; for (int i = 0; i < atmNumberOfOutputs; i++) { atm = sr.ReadLine().Split(':'); for (int k = 0; k < atmNumberOfInputs; k++) { atmWeights[i, k] = Convert.ToDouble(atm[k].ToString()); } } atmLayer.Weights = atmWeights; //double[,] atmWeightsDelta = new double[atmNumberOfOutputs, atmNumberOfInputs]; //for (int i = 0; i < atmNumberOfOutputs; i++) //{ // atm = sr.ReadLine().Split(':'); // for (int k = 0; k < atmNumberOfInputs; k++) // { // atmWeightsDelta[i, k] = Convert.ToDouble(atm[k].ToString()); // } //} //atmLayer.WeightsDelta = atmWeightsDelta; //double[] atmgamma = new double[atmNumberOfOutputs]; //atm = sr.ReadLine().Split(':'); //for (int i = 0; i < atmOutputs.Length; i++) //{ // atmgamma[i] = Convert.ToDouble(atm[i].ToString()); //} //atmLayer.Gamma = atmgamma; //double[] atmerror = new double[atmNumberOfOutputs]; //atm = sr.ReadLine().Split(':'); //for (int i = 0; i < atmOutputs.Length; i++) //{ // atmerror[i] = Convert.ToDouble(atm[i].ToString()); //} //atmLayer.Error = atmerror; atmLayers.Add(atmLayer); } nn.Layers = atmLayers.ToArray(); sr.Close(); //MessageBox.Show("Sikeres"); //MessageBox.Show(nn.Activation.ToString()); }