public void GetArrayTest1() { double[] vector = new double[] { 1, 2, 3, 4 }; double[][] matrix = new double[][] { new double[] { 1, 0 }, new double[] { 2, 0 }, new double[] { 3, 0 }, new double[] { 4, 0 } }; Assert.Equal(vector, EANN.GetArray(matrix)); }
public void Convert2JaggedTest() { double[] vectorIn = new double[] { 1, 2, 3, 4 }; double[][] matrixOut = new double[][] { new double[] { 1 }, new double[] { 2 }, new double[] { 3 }, new double[] { 4 } }; Assert.Equal(matrixOut, EANN.ConvertToJagged(vectorIn)); }
static void SaveResults(EANN eo_ann, string filePath) { if (Equals(eo_ann, null)) { return; } if (Equals(eo_ann.BestChart, null)) { return; } if (Equals(eo_ann, null)) { return; } using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate)) { using (StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8)) { System.Text.StringBuilder strb = new System.Text.StringBuilder(); strb.AppendLine("Best_Chart;"); for (int i = 0; i < eo_ann.BestChart.Count; i++) { strb.Append(eo_ann.BestChart[i]).AppendLine(";"); } strb.AppendLine("Best Learning score;"); strb.Append(eo_ann.BestLearningScore).AppendLine(";"); strb.AppendLine("Best Testing Score;"); strb.Append(eo_ann.BestTestingScore).AppendLine(";"); strb.AppendLine("Best solution;"); for (int i = 0; i < eo_ann.BestSolution.Length; i++) { strb.Append(eo_ann.BestSolution[i]).AppendLine(";"); } sw.Write(strb.ToString()); sw.Flush(); sw.Close(); fs.Close(); } } bool save = eo_ann.BestNeuralNetwork.SaveNeuralNetwork(string.Format("C:\\SSL\\The_Best_ANN_{0}.ann", fileName.Trim())); Console.WriteLine("Save the best ANN : {0}", save); }
public void GetArrayTest2() { double[] vector = new double[] { 0, 0, 0, 0, 0 }; double[][] matrix = new double[][] { new double[] { 0 }, new double[] { 0 }, new double[] { 0 }, new double[] { 0 }, new double[] { 0 } }; Assert.Equal(vector, EANN.GetArray(matrix)); }
static void LaunchANNEO(DataFormater dfr, int n, int kmax, int learnAlgo) { int minHLNeurones = 1; int maxHLNeurones = 15; int kminL = 40; int kmaxL = 200; if (learnAlgo == 0) { kminL = 10000; kmaxL = 21000; } var ranges = new List <MonoObjectiveEOALib.Range> { new MonoObjectiveEOALib.Range("Activation Function", 0.9, 2.1), new MonoObjectiveEOALib.Range("Alpha of Activation Function", 0.1, 10), new MonoObjectiveEOALib.Range("Learning rate", 0.05, 0.1), new MonoObjectiveEOALib.Range("Momentum/Ajustement", 10, 12), new MonoObjectiveEOALib.Range("Learning Err", 0.001, 0.01), new MonoObjectiveEOALib.Range("Max Iteration (Kmax)", kminL, kmaxL), new MonoObjectiveEOALib.Range("Hiden Layer Number", 1, 5), new MonoObjectiveEOALib.Range("Layer 1 Nodes count", minHLNeurones, maxHLNeurones), new MonoObjectiveEOALib.Range("Layer 2 Nodes count", minHLNeurones, maxHLNeurones), new MonoObjectiveEOALib.Range("Layer 3 Nodes count", minHLNeurones, maxHLNeurones), new MonoObjectiveEOALib.Range("Layer 4 Nodes count", minHLNeurones, maxHLNeurones), new MonoObjectiveEOALib.Range("Layer 5 Nodes count", minHLNeurones, maxHLNeurones), new MonoObjectiveEOALib.Range("Layer 6 Nodes count", minHLNeurones, maxHLNeurones) }; EANN annEo = new EANN(dfr.TrainingInput, dfr.TrainingOutput, dfr.TestingInput, dfr.TestingOutput); annEo.Learning_Algorithm = (LearningAlgorithmEnum)learnAlgo;// LearningAlgorithmEnum.LevenbergMarquardtLearning; annEo.SearchRanges = ranges; annEo.MaxOptimizationIterations = kmax; annEo.PopulationSize = n; annEo.LearnEO(); Console.WriteLine("EO-ANN :-> Best learning scroe = {0} ; EO-ANN :-> Best testing score = {1}", annEo.BestLearningScore, annEo.BestTestingScore); foreach (var itm in annEo.BestChart) { Console.WriteLine(itm); } SaveResults(annEo, string.Format("C:\\SSL\\Results_ANN_{0}.txt", fileName.Trim())); //double[][] xy = new double[][] // { // new double []{ 0.8}, // new double []{0.16}, // new double []{0.24}, // new double []{0.35}, // new double []{0.25} // }; //double[][] xy = new double[][] //{ // new double []{0.8, 0.12}, // new double []{0.16, 0.10}, // new double []{0.24, 0.26}, // new double []{0.35, 0.10}, // new double []{0.25, 0.12} //}; //var z = annEo.Compute(xy); //if (Equals(z, null)) { return; } //foreach (double value in z) //{ // Console.WriteLine("z = {0}", Math.Round(value, 3)); //} }
public EANNTests() { _tst = new EANN(); }