public List <NeuralPathway> GetPathways(Dynamic o) { var pathways = new List <NeuralPathway>(); var path = new NeuralPathway(); path.Path.Add(o); path.Weightings.Add(1); var paths = o.ExtendPathway(path); pathways.AddRange(paths); return(pathways); }
public NeuralPathway Copy() { var copy = new NeuralPathway(); foreach (var p in Path) { copy.Path.Add(p); } foreach (var w in Weightings) { copy.Weightings.Add(w); } return(copy); }
public override double GetOutput(NeuralPathway path = null) { if (path != null) { if (path.Path.Count(Equivelant) > 2) { return(0); } path.Path.Add(this); } var sum = Dendrites.Aggregate <Dendrite, double>(0, (current, d) => current + (d.GetSignal(path))); return(Function(sum)); }
/** * backpropagate * sends weighted error back through the network * re-weights input based on error. * @param error (double) */ public override void Backpropagate(double error, NeuralPathway path = null) { if (path != null) { if (path.Path.Count(Equivelant) > 2) { return; } path.Path.Add(this); } //http://home.agh.edu.pl/~vlsi/AI/backp_t_en/backprop.html foreach (var d in Dendrites) { d.Neuron.Backpropagate(error * d.Weight, path); Reweight(d, error, path); } }
public IEnumerable <NeuralPathway> ExtendPathway(NeuralPathway pathway) { var pathways = new List <NeuralPathway>(); if (Dendrites.Count <= 0) { return new List <NeuralPathway>() { pathway } } ; foreach (var d in Dendrites) { var path = pathway.Copy(); path.Path.Add(d.Neuron); path.Weightings.Add(d.Weight); var paths = d.Neuron.ExtendPathway(path); pathways.AddRange(paths); } return(pathways); } }
/** * reweight * Sets the weight of the given dendrite based on its error. * @param dendrite (Dendrite) to be reweighted * @param error (double) */ private void Reweight(Dendrite dendrite, double error, NeuralPathway path = null) { var weight = dendrite.Weight + LearningRate * error * Derivative(GetOutput(path)) * dendrite.Neuron.GetOutput(path); dendrite.Weight = weight; }
/** * backpropagate * all nodes must backpropagate errors * @param error (double) */ public abstract void Backpropagate(double error, NeuralPathway path = null);
/** * getOutput * Abstract, all nodes must return an output * @return double value */ public abstract double GetOutput(NeuralPathway path = null);
/** * backpropagate * Static neurons do not need to backpropagate */ public override void Backpropagate(double error, NeuralPathway path = null) { }
/** * getOutput * Static INeurons return their value * @return double value */ public override double GetOutput(NeuralPathway path = null) { return(Value); }
public double GetWeightedOutput(NeuralPathway path = null) { return(Weight * Neuron.GetOutput(path)); }
public double GetSignal(NeuralPathway path = null) { return(GetWeightedOutput(path)); }