public NeuralLayer(int numNeurons, int inputs, NeuralNetwork net) { Neurons = new Neuron[numNeurons]; NumInputs = inputs; for(int i = 0; i < numNeurons; i++) { Neurons[i] = new Neuron(inputs, net); } //Neurons[0].Debug = true; }
public void SetNetwork(NeuralNetwork net) { Network = net; }
public OutputNeuralLayer(int outputs, int inputs, NeuralNetwork net) : base(outputs, inputs, net) { Neurons[0].Debug = false; }
public Neuron(int inputs, NeuralNetwork net) { Network = net; Weights = new double[inputs]; deltas = new double[inputs]; for (int i = 0; i < inputs; i++) { Weights[i] = NeuralNetwork.Rand.NextDouble()*4-2; } Bias = NeuralNetwork.Rand.NextDouble()*4-2; }
public override void SetNetwork(NeuralNetwork net) { return; }
public virtual void SetNetwork(NeuralNetwork net) { Neurons.ForEach(n => n.SetNetwork(net)); }
public InputNeuralLayer(int inputs, NeuralNetwork net) : base(0, inputs, net) { }
private void runner(object state) { int id = (int)state; do { NeuralNetwork.NetworkParameters param; lock (ParametersEnumerator) { if (!ParametersEnumerator.MoveNext()) { // Done return; } param = ParametersEnumerator.Current; Console.WriteLine(string.Format("Id {4} Starting an optimization run : L={0} N={1} D={2} R={3}", param.Layers, param.NeuronsPerLayers, param.MaxDepth, param.TrainingRate, id)); } NeuralNetwork network = new NeuralNetwork(param); var results = network.TrainBatch(TrainingSet.Item1.ToList(), TrainingSet.Item2.ToList(), s => Console.WriteLine("Id "+ id + " " + s)); // Check against bests lock (bestRuns) { Console.WriteLine(string.Format("Optimisation for {0} is done in {1}s. Results => MSE={2:.00}% // Success={5:.00} ({3}/{4})", id, results.duration.TotalSeconds, results.mse*100, results.success, results.count, ((double)results.success/results.count)*100)); if (bestRuns.Count < bestRuns.Capacity) { bestRuns.Add(Tuple.Create(network, results, param)); } else { for(int i = 0; i < bestRuns.Count; i++) { if (bestRuns[i].Item2.success < results.success) { bestRuns[i] = Tuple.Create(network, results, param); } } } break; } } while (true); }
static void Main(string[] args) { if (args.Length < 2) { Environment.Exit(1); return; } var test = extractPlayers(args[1]); //Console.Out.WriteLine(allPlayers.Count); var serializer = new XmlSerializer(typeof(SerializeNetwork)); if (args[0].EndsWith(".xml")) { // Training is a xml backup var load = File.OpenRead(args[0]); var deserialized = (SerializeNetwork)serializer.Deserialize(load); load.Close(); network = deserialized.network; mean = deserialized.means; stdev = deserialized.stdev; network.Checker = checker; network.SetNetwork(); } else { var training = extractPlayers(args[0]); network = Train(training); } Test(test); var save = File.Create("network.xml"); serializer.Serialize(save, new SerializeNetwork { network = network, means = mean, stdev = stdev }); save.Close(); while(Console.ReadLine() != "stop"); }
public void SetActualNetworkFromNetworkDetails() { this.actualNetwork = ucNetworkDetails.GetNetwork(); }