private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Application.Exit(); an.Save("BPNNBrain.net"); dn.Save("SOMBrain.net"); }
private void button2_Click(object sender, EventArgs e) { saveFileDialog1.FileName = null; var r = saveFileDialog1.ShowDialog(); if (r != System.Windows.Forms.DialogResult.Cancel) { if (File.Exists(saveFileDialog1.FileName)) { var f = MessageBox.Show(this, "File already exixt do you want to overwrite it?", "Alert", MessageBoxButtons.YesNo); if (f == System.Windows.Forms.DialogResult.Yes) { network.Save(saveFileDialog1.FileName); saveFileDialog1.FileName = null; } else { return; } } else { network.Save(saveFileDialog1.FileName); saveFileDialog1.FileName = null; } } }
public void UpdateNeuralNet(string csvString, string trainedNetName) { if (!File.Exists(outputDir + "dataset/" + trainedNetName + ".tmp")) { var lines = csvString.Split('\n'); var csv = from line in lines select(line.Split(',')).ToArray(); double[][] inputs = new double[150][]; double[][] outputs = new double[150][]; string[] types = new string[150]; int rowIndex = 0; foreach (var row in csv) { int colIndex = 0; inputs[rowIndex] = new double[4]; foreach (var col in row) { if (colIndex < row.Length - 1) { inputs[rowIndex][colIndex] = double.Parse(col); } else { types[rowIndex] = col; } colIndex++; } rowIndex++; } string[] distinct = types.Select(o => o.Replace("\r", "")).Distinct().ToArray(); PutDistinctLevel(trainedNetName, distinct); BackPropagation bp = new BackPropagation(); rowIndex = 0; foreach (var row in types) { outputs[rowIndex] = new double[3]; outputs[rowIndex] = bp.getIndex(row.Replace("\r", ""), distinct); rowIndex++; } // create neural network ActivationNetwork network = new ActivationNetwork(new SigmoidFunction(0.43), 4, 8, 3); BackPropagationLearning teacher = new BackPropagationLearning(network); teacher.LearningRate = 0.2; teacher.Momentum = 0; // loop double error = 1; while (error > 0.01) { // run epoch of learning procedure error = teacher.RunEpoch(inputs, outputs); Console.WriteLine("error is: " + error); // check error value to see if we need to stop // ... } network.Save(outputDir + @"dataset/" + trainedNetName + ".tmp"); } }
private void Save() { const string filename = "Network.bin"; actNet.Save(filename); MessageBox.Show($"Network saved to file '{filename}'."); }
public void Save() { NodeSavingReading reader = new NodeSavingReading(); network.Save(ANNfilename); reader.pushDataToFile(KFoldFilename, topResults); }
public object Clone() { var netw1 = new System.IO.MemoryStream(); var netw2 = new System.IO.MemoryStream(); var netw3 = new System.IO.MemoryStream(); var netw4 = new System.IO.MemoryStream(); m_network1.Save(netw1); m_network2.Save(netw2); m_network3.Save(netw3); m_network4.Save(netw4); var clone = new AForgeNetwork() { m_activationFunc = (SigmoidFunction)m_activationFunc.Clone(), m_network1 = (ActivationNetwork)Network.Load(netw1), m_network2 = (ActivationNetwork)Network.Load(netw2), m_network3 = (ActivationNetwork)Network.Load(netw3), m_network4 = (ActivationNetwork)Network.Load(netw4) }; netw1.Close(); netw2.Close(); netw3.Close(); netw4.Close(); return(clone); }
public void Save() { using (var stream = new FileStream("BinaryFile.bin", FileMode.Create, FileAccess.Write, FileShare.None)) { neuralNetwork.Save(stream); } }
private static void TrainNetwork(LearningData learningData, String networkPath) { ActivationNetwork network = new ActivationNetwork( UseBipolar ? (IActivationFunction) new BipolarSigmoidFunction(1) : (IActivationFunction) new SigmoidFunction(), 784, 784, 10); network.Randomize(); Int32 epochIndex = 0; new NguyenWidrow(network).Randomize(); //// create teacher //PerceptronLearning teacher = new PerceptronLearning(network);// new BackPropagationLearning(network); //PerceptronLearning teacher = new PerceptronLearning(network);// new BackPropagationLearning(network); ParallelResilientBackpropagationLearning teacher = new ParallelResilientBackpropagationLearning(network); //teacher.LearningRate = 0.0125; ////teacher.Momentum = 0.5f; Double error = Double.MaxValue; Double previousError = Double.MaxValue; Stopwatch sw = new Stopwatch(); Int32 counter = 100; // loop while (counter > 0) { sw.Reset(); sw.Start(); // run epoch of learning procedure error = teacher.RunEpoch(learningData.Input, learningData.Output); sw.Stop(); //if (error > previousError) //{ // teacher.LearningRate = teacher.LearningRate * 0.5f; //} Console.WriteLine(String.Format("{0} {1} {2}", epochIndex, error, sw.Elapsed.TotalSeconds)); epochIndex++; previousError = error; counter--; } network.Save(networkPath); //Double[] output = network.Compute(learningData.Input[0]); }
void BackPropagationMethod() { an = new ActivationNetwork( new SigmoidFunction(), inputCount, hidden, outputCount ); bpn = new BackPropagationLearning(an); new NguyenWidrow(an).Randomize(); Console.WriteLine("Learning"); for (var i = 0; i < maxEpoch; i++) { var error = bpn.RunEpoch(inputImgArray.ToArray(), outputImgArray.ToArray()); if (error < errorGoal) { break; } if (i % 10 == 0) { Console.WriteLine($"Report error BPN {i} : {error}"); } } an.Save(savedANNetwork); }
/// <summary> /// Generates points trained points from learning. /// </summary> private async Task <double[][]> ComputeTrainedPoints(double[][] correctPoints) { return(await Task.Run(() => { lock (_threadLocker) { try { _network = (ActivationNetwork)Network.Load(ConfigurationPath()); } catch (Exception ex) { throw ex; } Scaler scaler = new Scaler(correctPoints); var inputScaledData = correctPoints.Select(a => a.ToArray()).ToArray(); scaler.Scale(ref inputScaledData); var solution = inputScaledData.Select(a => a.ToArray()).ToArray(); var networkInput = new double[2 * _inputPoints]; for (int j = _inputPoints; j < solution.GetLength(0); j++) { for (int k = _inputPoints, l = 0; k > 0; k--, l = l + 2) { networkInput[l] = solution[j - k][0]; networkInput[l + 1] = solution[j - k][1]; } try { var result = _network.Compute(networkInput); solution[j][0] = result[0]; solution[j][1] = result[1]; } catch { solution[j][0] = double.NaN; solution[j][1] = double.NaN; } } for (int i = 0; i < solution.GetLength(0); i++) { if (double.IsNaN(solution[i][0]) || double.IsNaN(solution[i][1])) { continue; } solution[i][0] = scaler.Rescale(solution[i][0], XYEnum.X); solution[i][1] = scaler.Rescale(solution[i][1], XYEnum.Y); } _network.Save(ConfigurationPath()); _network = null; return solution; } })); }
public void Save() { PersonOccurenceDatabase.Save(_modelPath + "persons.csv"); OrganizationOccurenceDatabase.Save(_modelPath + "organizations.csv"); LocationsOccurenceDatabase.Save(_modelPath + "locations.csv"); SportSpecificWordsOccurenceDatabase.Save(_modelPath + "specificwords.csv"); _sportSpecificWords.Save(_modelPath + "specificwords.txt"); _classifier.Save(_modelPath + "classifier"); }
private static void Training() { var csv = new CsvReader(new StreamReader("C:\\Users\\jantk_000\\Documents\\SearchResultRelevance\\trainextracted.csv")); List <LabeledData> data = csv.GetRecords <LabeledData>().ToList(); List <LabeledData> train = new List <LabeledData>(); List <LabeledData> validation = new List <LabeledData>(); for (int i = 0; i < data.Count; i++) { if (i % 5 == 0) { validation.Add(data[i]); } else { train.Add(data[i]); } } double[][] trainInput = train.Select(labeledData => labeledData.GetInputVector()).ToArray(); double[][] trainOutput = train.Select(labeledData => new[] { labeledData.GetOutput() }).ToArray(); double[][] validationInput = validation.Select(labeledData => labeledData.GetInputVector()).ToArray(); double[][] validationOutput = validation.Select(labeledData => new[] { labeledData.GetOutput() }).ToArray(); ActivationNetwork network = new ActivationNetwork(new SigmoidFunction(), 3, 4, 1); BackPropagationLearning rprop = new BackPropagationLearning(network) { LearningRate = 0.01, Momentum = 0.01 }; double lastError = double.MaxValue; for (int i = 0;; i++) { rprop.RunEpoch(trainInput, trainOutput); double err = 0; for (int j = 0; j < validationInput.Length; j++) { double[] input = validationInput[j]; double[] output = network.Compute(input); err += Math.Sqrt(Math.Pow(validationOutput[j][0] - output[0], 2)); } err = err / validationInput.Length; var improvement = lastError - err; lastError = err; Console.WriteLine("Iteration {0} RMSE {1} Improvement {2}", i, err, improvement); if (improvement < 0.000001) { break; } } network.Save("Network.bin"); }
private ActivationNetwork Copy(ActivationNetwork network) { using (var memoryStream = new MemoryStream()) { network.Save(memoryStream); memoryStream.Position = 0; return((ActivationNetwork)Network.Load(memoryStream)); } }
/** * Сохранение нейронной сети по указанному пути * */ private void SaveNetToolStripMenuItem_Click(object sender, EventArgs e) { saveFileDialog1.Filter = "bin files (*.bin)|*.bin"; if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK && saveFileDialog1.FileName.Length > 0) { network.Save(saveFileDialog1.FileName); MessageBox.Show("Сеть сохранена"); } }
public void Save(string location) { using (FileStream stream = new FileStream(location, FileMode.Create)) { var formatter = new BinaryFormatter(); formatter.Serialize(stream, Ver); formatter.Serialize(stream, _allContexts); formatter.Serialize(stream, _standard); _network.Save(stream); } }
private static void TrainNetwork(LearningData learningData, String networkPath) { ActivationNetwork network = new ActivationNetwork( UseBipolar ? (IActivationFunction) new BipolarSigmoidFunction(1) : (IActivationFunction) new SigmoidFunction(), 784, //784, 10); network.Randomize(); Int32 epochIndex = 0; //// create teacher PerceptronLearning teacher = new PerceptronLearning(network); // new BackPropagationLearning(network); //PerceptronLearning teacher = new PerceptronLearning(network);// new BackPropagationLearning(network); teacher.LearningRate = 0.1f; ////teacher.Momentum = 0.5f; Double error = Double.MaxValue; Double previousError = Double.MaxValue; Int32 counter = 100; // loop while (counter > 0) { // run epoch of learning procedure error = teacher.RunEpoch(learningData.Input, learningData.Output); if (error > previousError) { teacher.LearningRate = teacher.LearningRate * 0.5f; } Console.WriteLine(String.Format("{0} {1}", epochIndex, error)); epochIndex++; previousError = error; counter--; } network.Save(networkPath); //Double[] output = network.Compute(learningData.Input[0]); }
public string Persistence() { string filePath = Directory.GetCurrentDirectory() + @"\tmp\"; string fileName = filePath + _dqnFilename; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } if (File.Exists(fileName)) { File.Delete(fileName); } _network.Save(fileName); return(fileName); }
/* * Copyright (c) 2018 Mihai Pruna * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE.*/ //Uses Aforge.NET: http://www.aforgenet.com/framework/ //Aforge.NET license: http://www.aforgenet.com/framework/license.html static void Main(string[] args) { //args: data folder, learning ,momentum,error,iterations List <string> inputRows = File.ReadAllLines(args[0] + @"\input.csv").ToList(); int inputSampleCount = inputRows.Count; char[] sep = { ',' }; int inputCount = inputRows[0].Split(sep, StringSplitOptions.None).Length; List <string> outputRows = File.ReadAllLines(args[0] + @"\output.csv").ToList(); int outputCount = outputRows[0].Split(sep, StringSplitOptions.None).Length; List <int> numberNeurons = File.ReadAllLines(args[0] + @"\layers.csv").ToList().ConvertAll(new Converter <string, Int32>(ConvMeInt)); numberNeurons.Add(outputCount); //convert data from file to format used by teacher double[][] inputs = new double[inputSampleCount][]; double[][] outputs = new double[inputSampleCount][]; PopulateFromStrings(inputs, inputRows); PopulateFromStrings(outputs, outputRows); // create multi-layer neural network ActivationNetwork network = new ActivationNetwork(new BipolarSigmoidFunction(), inputCount, numberNeurons.ToArray()); // create teacher BackPropagationLearning teacher = new BackPropagationLearning(network); teacher.LearningRate = Convert.ToDouble(args[1]); teacher.Momentum = Convert.ToDouble(args[2]); double maxerror = Convert.ToDouble(args[3]); int maxiter = Convert.ToInt32(args[4]); double error = double.MaxValue; int iter = 0; Console.WriteLine("Training..."); while (error > maxerror && iter < maxiter) { //squared error (difference between current network's output and desired output) divided by 2. error = teacher.RunEpoch(inputs, outputs); iter++; Console.WriteLine("Error " + error + " Iteration " + iter); } Console.WriteLine("Writing network to " + args[0] + @"\network.nn"); network.Save(args[0] + @"\network.nn"); //Console.ReadKey(); }
private void SaveAnnButton_Click(object sender, RoutedEventArgs e) { // Configure save file dialog box Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = "NeuralNetwork"; // Default file name dlg.DefaultExt = ".klu"; // Default file extension dlg.Filter = "KLU ANN (.klu)|*.klu"; // Filter files by extension dlg.Title = "Where to save your new Neural Network?"; // Show save file dialog box Nullable <bool> result = dlg.ShowDialog(); // Process save file dialog box results if (result == true) { _Network.Save(dlg.FileName); } }
public static ActivationNetwork GetRootsNetwork() { bool load = false; if (_rootsNetwork == null) { try { _rootsNetwork = (ActivationNetwork)Network.Load("SAVED_RootNetwork"); load = true; } catch { } if (!load) { _rootsNetwork = Analyzer.RunRoots(ROOTS_IN, ROOTS_OUT); _rootsNetwork.Save("SAVED_RootNetwork"); } } return(_rootsNetwork); }
public void bpnnTraining() { double[][] input_data = new double[Data.instance.images.Count][]; double[][] output_data = new double[Data.instance.indexClasses.Count][]; int max_output = Data.instance.classes.Count - 1, min_output = 0; for (int i = 0; i < Data.instance.images.Count; i++) { //Pilih gambar berwarna Bitmap image = new Bitmap(Data.instance.images[i]); //Preprocess jadi 10 x 10 hitam putih image = Data.instance.preProcess(image); // dari pixel 0-255 jadi 0-1 ImageToArray converter = new ImageToArray(0, 1); converter.Convert(image, out input_data[i]); output_data[i] = new double[1]; output_data[i][0] = Data.instance.indexClasses[i]; output_data[i][0] = 0 + (output_data[i][0] - min_output) * (1 - 0) / (max_output - min_output); } bpnnNetwork = new ActivationNetwork(new SigmoidFunction(), 100, 3, 1); bpnnLearning = new BackPropagationLearning(bpnnNetwork); //o Error Goals: 0.000001 //o Max Epochs: 1000000 int max_iter = 1000000; double max_error = 0.000001; for (int i = 0; i < max_iter; i++) { double error = bpnnLearning.RunEpoch(input_data, output_data); if (error < max_error) { break; } } bpnnNetwork.Save("an.bin"); }
public void Learn(ref ActivationNetwork network, double[] crossInput, double[] circleInput, double[] blankInput) { NetworkInput networkInput = new NetworkInput(crossInput, circleInput, blankInput); double[][] input = networkInput.Input; NetworkOutput networkOutput = new NetworkOutput(0); double[][] output = networkOutput.Output; BackPropagationLearning teacher = new BackPropagationLearning(network); for (int i = 0; i < 100000; i++) { double error = teacher.RunEpoch(input, output); } network.Save("Net.bin"); MessageBox.Show("Learning finished"); }
public void Train(double[][] dataset, double[][] labels) { if (dataset.Length <= 0) { return; } net.Randomize(); double error = 100; int epoch = 0; int len = dataset.Length; while (error > 0.01 && epoch < Epochs) { error = backprop.RunEpoch(dataset, labels) / len; Debug.WriteLine("iteration = " + epoch.ToString()); Debug.WriteLine("error = " + error.ToString()); ++epoch; } net.Save("net1"); }
public bool SaveNeuralNetwork(string fileName) { bool result = false; try { if (Equals(Network, null)) { throw new NullReferenceException("No Neural Network existed"); } if (File.Exists(fileName) == false) { Stream stream = new FileStream(fileName, FileMode.CreateNew); stream.Close(); } Network.Save(fileName); result = true; } catch (Exception ex) { throw ex; } return(result); }
private void testButton_Click(object sender, EventArgs e) { // number of learning samples int samples = testData.GetLength(0); var input = new double[samples][]; for (int sample = 0; sample < samples; sample++) { input[sample] = new double[numberOfInputs]; for (int i = 0; i < numberOfInputs; i++) { input[sample][i] = normalizeInput(testData[sample, i], i); } } var solution = new double[samples, numberOfInputs + 1]; // calculate solution for (int sample = 0; sample < samples; sample++) { // copy inputs for (int i = 0; i < numberOfInputs; i++) { solution[sample, i] = testData[sample, i]; } // denormalize solution[sample, numberOfInputs] = denormalize(network.Compute(input[sample])) - 1; } // create a writer and open the file TextWriter twSolution = new StreamWriter(_dir + "\\classification_output.csv"); var nfi = new NumberFormatInfo { NumberDecimalSeparator = "." }; var errors = 0; for (int sample = 0; sample < samples; sample++) { twSolution.Write(solution[sample, numberOfInputs].ToString(nfi)); twSolution.Write(" = "); twSolution.Write(testAnswers[sample]); if (radioBtnMnist.Checked && Math.Abs(testAnswers[sample] - solution[sample, numberOfInputs]) > 0.1) { twSolution.Write(" ERROR"); errors++; } twSolution.WriteLine(); } twSolution.Close(); network.Save(_dir + "\\network"); //MessageBox.Show("Tested, errors: " + errors); if (!PruningChk.Checked) { raports.Add(new Raport { connections = totalConnections, iterations = iterations, error = trainingSetError.Last(), Testerror = errors }); } raports.Last().Testerror = errors; }
public void SaveNetwork(string fname) { network.Save <ActivationNetwork>(fname); }
public void ZapiszSiecDoPliku(string plik) { siecNeuronowa.Save(plik); }
/// <summary> /// Save network to files /// </summary> public void Save() { _clusteringNetwork.Save("SOMBrain.net"); _classificationNetwork.Save("BPNNBrain.net"); }
public static void RunXOR(string[] args) { string path = Environment.CurrentDirectory + @"\XORNetwork.txt"; ActivationNetwork XORNetwork = new ActivationNetwork(new SigmoidFunction(1), 2, 2, 1); Console.WriteLine(path); int[] trainingSet = new int[8] { 0, 0, 0, 1, 1, 0, 1, 1 }; int[] trainingAnswers = new int[4] { 0, 1, 1, 0 }; Start: Console.WriteLine("What would you like to do?"); switch (Console.ReadLine().ToLower()) { case ("train"): BackPropagationLearning teacher = new BackPropagationLearning(XORNetwork); while (true) { int iter = 0; for (iter = 0; iter < 100000000; iter++) { for (int i = 0; i < 4; i++) { //Console.WriteLine(Convert.ToString(trainingSet[i * 2]) + " " + Convert.ToString(trainingSet[i * 2 + 1])); //Console.WriteLine(Convert.ToString(teacher.Run(new double[2] { trainingSet[i * 2], trainingSet[i * 2 + 1] }, new double[1] { trainingAnswers[i] }))); teacher.Run(new double[2] { trainingSet[i * 2], trainingSet[i * 2 + 1] }, new double[1] { trainingAnswers[i] }); } //Console.WriteLine(iter.ToString()); } //if (Console.ReadLine() == "stop") //{ Console.WriteLine("Done"); XORNetwork.Save(path); goto Start; //} } case ("read"): Network network; if (File.Exists(path)) { network = Network.Load(path); } else { network = XORNetwork; } for (int i = 0; i < 4; i++) { Console.WriteLine(Convert.ToString(trainingSet[i * 2]) + " " + Convert.ToString(trainingSet[i * 2 + 1])); Console.WriteLine(network.Compute((new double[2] { trainingSet[i * 2], trainingSet[i * 2 + 1] }))[0].ToString()); Console.WriteLine(Math.Round(network.Compute((new double[2] { trainingSet[i * 2], trainingSet[i * 2 + 1] }))[0]).ToString()); } /*double[] userValues = new double[2]; * userValues[0] = Convert.ToDouble(Console.ReadLine()); * userValues[1] = Convert.ToDouble(Console.Read()); * Console.WriteLine(XORNetwork.Compute(userValues)[0].ToString());*/ break; case "randomize": XORNetwork.Randomize(); XORNetwork.Save(path); Console.WriteLine("done"); break; case "status": break; } goto Start; }
//Machine Learning void IDataminingDatabase.doMachineLearning(string[] inputFields, string outcomeField, string instrument, string savePath) { string name = "ANN"; double learningRate = 0.1; double sigmoidAlphaValue = 2; int iterations = 100; bool useRegularization = false; bool useNguyenWidrow = false; bool useSameWeights = false; progress.setProgress(name, "Creating ANN..."); // create multi-layer neural network ActivationNetwork ann = new ActivationNetwork( new BipolarSigmoidFunction(sigmoidAlphaValue), inputFields.Length, 20, 2); //How many neuros ???? Standart is 1 if (useNguyenWidrow) { progress.setProgress(name, "Creating NguyenWidrow..."); if (useSameWeights) { Accord.Math.Random.Generator.Seed = 0; } NguyenWidrow initializer = new NguyenWidrow(ann); initializer.Randomize(); } progress.setProgress(name, "Creating LevenbergMarquardtLearning..."); // create teacher LevenbergMarquardtLearning teacher = new LevenbergMarquardtLearning(ann, useRegularization); //, JacobianMethod.ByBackpropagation // set learning rate and momentum teacher.LearningRate = learningRate; IMongoQuery fieldsExistQuery = Query.And(Query.Exists(outcomeField + "_buy"), Query.Exists(outcomeField + "_sell")); foreach (string inputField in inputFields) { fieldsExistQuery = Query.And(fieldsExistQuery, Query.Exists(inputField)); } progress.setProgress(name, "Importing..."); // Load Data long start = database.getFirstTimestamp(); long end = database.getLastTimestamp(); var collection = mongodb.getDB().GetCollection("prices"); var docs = collection.FindAs <BsonDocument>(Query.And(fieldsExistQuery, Query.EQ("instrument", instrument), Query.LT("timestamp", end), Query.GTE("timestamp", start))).SetSortOrder(SortBy.Ascending("timestamp")); docs.SetFlags(QueryFlags.NoCursorTimeout); long resultCount = docs.Count(); //Press into Array from progress.setProgress(name, "Casting to array..."); double[][] inputs = new double[resultCount][]; // [inputFields.Length] double[][] outputs = new double[resultCount][]; // [2] int row = 0; foreach (var doc in docs) { outputs[row] = new double[] { doc[outcomeField + "_buy"].AsInt32, doc[outcomeField + "_sell"].AsInt32 }; double[] inputRow = new double[inputFields.Length]; for (int i = 0; i < inputFields.Length; i++) { double value = doc[inputFields[i]].AsDouble; if (double.IsInfinity(value) || double.IsNegativeInfinity(value) || double.IsNaN(value)) { throw new Exception("Invalid value!"); } else { inputRow[i] = value; } } inputs[row] = inputRow; //Check these! :) ??? row++; } // Teach the ANN for (int iteration = 0; iteration < iterations; iteration++) { progress.setProgress(name, "Teaching... " + iteration + " of " + iterations); double error = teacher.RunEpoch(inputs, outputs); if (savePath != null) { ann.Save(savePath); } } //Compute Error progress.setProgress(name, "Calculating error..."); int successes = 0; int fails = 0; for (int i = 0; i < inputs.Length; i++) { var realOutput = outputs[i]; //Buys double[] calculated = ann.Compute(inputs[i]); if (calculated[0] == 0 || calculated[0] == realOutput[0]) { successes++; } if (calculated[0] == 1 && realOutput[0] == 0) { fails++; } //Sells if (calculated[1] == 0 || calculated[1] == realOutput[1]) { successes++; } if (calculated[1] == 1 && realOutput[1] == 0) { fails++; } } double successRate = (double)successes / (inputs.Length * 2); double failRate = (double)fails / (inputs.Length * 2); progress.setProgress(name, "Finished with successRate of " + successRate + " failRate of " + failRate); }