internal void RemoveConnection(Connection connection) { if(connection.FromNode == this) { OutgoingConnections.Remove(connection); } else if(connection.ToNode == this) { IncommingConnections.Remove(connection); } }
internal void AddOutgoingConnection(Connection connection) { if(connection.FromNode == this && connection.ToNode != null) { OutgoingConnections.Add(connection); } else { throw new ArgumentException("Invalid connection"); } }
public static Connection Create(double weight, Node fromNode, Node toNode) { var con = new Connection(weight, fromNode, toNode); fromNode.AddOutgoingConnection(con); toNode.AddIncommingConnection(con); return con; }
public static void Delete(Connection connection) { connection.FromNode.RemoveConnection(connection); connection.ToNode.RemoveConnection(connection); }
/// <summary> /// Calculates connection influence value IF it is not yet present in ConnectionInfluence dictionary /// Stores result in the dictionary and then returns it /// </summary> private double GetConnectionInfluence(Connection connection, int microBatchIndex) { double? cur = ConnectionInfluence[connection][microBatchIndex]; if(cur.HasValue) { return cur.Value; } else { double sumInfluenceOutput = 0; foreach(var outgoing in connection.ToNode.GetOutgoingConnections()) { double connectionInfluence = GetConnectionInfluence(outgoing, microBatchIndex); double curInfluence = connectionInfluence * outgoing.Weight; sumInfluenceOutput += curInfluence; } double fromOutput = connection.FromNode.Output; double outDeriv = Network.TransferFunction.Derivative(connection.ToNode.Output); double influence = sumInfluenceOutput * outDeriv; ConnectionInfluence[connection][microBatchIndex] = influence; return influence; } }
private double CalcOutputInfuence(Connection connection, double expectedOutput, double actualOutput) { double dif = (-(expectedOutput - actualOutput)); double outcome = dif * Network.TransferFunction.Derivative(actualOutput); return outcome; }