public NetCacheEntry(string name, string tag, double fitness, NeuralNet.Net net) { this.name = name; this.tag = tag; this.fitness = fitness; this.net = net; }
public void exportNeuralNet(Net n, string filePath) { var lines = new List<string>(); lines.Add(n.numInput.ToString() + ' ' + n.numHidden.ToString() + ' ' + n.numOutput.ToString()); foreach (var lw in n.inpToHiddenWeight) { string line = ""; foreach (var weight in lw) { line = line + String.Format("{0:#,0.000}", weight) + ' '; } lines.Add(line.TrimEnd(' ')); } foreach (var lw in n.hidToOutputWeight) { string line = ""; foreach (var weight in lw) { line = line + String.Format("{0:#,0.000}", weight) + ' '; } lines.Add(line.TrimEnd(' ')); } System.IO.File.WriteAllLines(filePath, lines); }
public Net loadNeuralNet(string filePath) { try { using (StreamReader sr = new StreamReader(filePath)) { String line = sr.ReadToEnd(); var words = line.Split('\n'); var nums = words.First().Split(' ').Select(Int32.Parse).ToList(); var neuralNet = new Net(nums[0], nums[1], nums[2]); for (int i = 1; i < 1 + nums[1]; i++) { var weights = words[i].Split(' ').Select(Double.Parse).ToList(); neuralNet.inpToHiddenWeight.Add(weights); } for (int i = nums[1] + 1; i < 1 + nums[1] + nums[2]; i++) { var weights = words[i].Split(' ').Select(Double.Parse).ToList(); neuralNet.hidToOutputWeight.Add(weights); } return neuralNet; } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); return null; } }
public void TransplantNet(NeuralNet.Net net) { this.Net = (FeedForward)net; // Net fitness is based on amount consumed. Net.FitnessEvaluator = n => (double)stats.Consumed; }