/// <summary> /// Processes a training sample. /// </summary> /// <param name="connections">The inter-layer connections.</param> /// <param name="activatedLeft">The activated units in the left partition.</param> /// <param name="activatedRight">The activated units in the right partition.</param> public override void ProcessSample(IInterLayerConnections connections, List <int> activatedLeft, List <int> activatedRight) { var random = ThreadSafeRandom.GetThreadRandom(); foreach (var outputUnit in activatedRight) { // // Find out how many strong (excitatory) edges are connected to this unit // int degree = connections.GetNeighbours(outputUnit, Partition.Right, true).Count(); // // If it's equal to the target degree, move on to the next output unit // if (degree == this.targetDegree) { ////Debug.WriteLine("Skipping output unit " + outputUnit + " because it has reached its target degree"); continue; } // // Calculate the probability of an edge strengthening/weakening // double p = (double)(this.targetDegree - degree) / (2.0 * this.MaxInputActivations); // // Stochastically modify edges which connect concurrently active units // foreach (var inputUnit in activatedLeft) { var edge = connections.GetEdge(inputUnit, outputUnit); if (edge.Weight == 0 && p > 0.0 && random.NextDouble() < p) { connections.SetEdge(inputUnit, outputUnit, 1); #if DEBUG Debug.WriteLine("Adding edge between " + inputUnit + " and " + outputUnit); #endif } else if (edge.Weight == 1 && p < 0.0 && random.NextDouble() < -p) { connections.SetEdge(inputUnit, outputUnit, 0); #if DEBUG Debug.WriteLine("Removing edge between " + inputUnit + " and " + outputUnit); #endif } } } // // TODO: Prune from the left as well? // }
/// <summary> /// Processes a training sample. /// </summary> /// <param name="connections">The inter-layer connections.</param> /// <param name="activatedLeft">The activated units in the left partition.</param> /// <param name="activatedRight">The activated units in the right partition.</param> public override void ProcessSample(IInterLayerConnections connections, List <int> activatedLeft, List <int> activatedRight) { var random = ThreadSafeRandom.GetThreadRandom(); foreach (var leftUnit in activatedLeft) { foreach (var rightUnit in activatedRight) { if (connections.GetEdge(leftUnit, rightUnit).Weight == 0) { if (random.NextDouble() < this.strengtheningProbability) { connections.SetEdge(leftUnit, rightUnit, 1); } } } } }