/// <summary> /// Perform one training iteration. /// </summary> public void Iteration() { // Reset the BMU and begin this iteration. _bmuUtil.Reset(); var won = new int[_outputNeuronCount]; var leastRepresentedActivation = double.PositiveInfinity; double[] leastRepresented = null; // Reset the correction matrix for this synapse and iteration. //*this.correctionMatrix.clear(); // Determine the BMU for each training element. foreach (var input in _training) { var bmu = _bmuUtil.CalculateBMU(input.Input); won[bmu]++; // If we are to force a winner each time, then track how many // times each output neuron becomes the BMU (winner). if (ForceWinner) { // Get the "output" from the network for this pattern. This // gets the activation level of the BMU. var output = Compute(_network, input.Input); // Track which training entry produces the least BMU. This // pattern is the least represented by the network. if (output[bmu] < leastRepresentedActivation) { leastRepresentedActivation = output[bmu]; leastRepresented = input.Input; } } Train(bmu, _network.Weights, input.Input); if (ForceWinner) { // force any non-winning neurons to share the burden somewhat\ if (!ForceWinners(_network.Weights, won, leastRepresented)) { ApplyCorrection(); } } else { ApplyCorrection(); } } // update the error _error = _bmuUtil.WorstDistance / 100.0; }
/// <summary> /// Calculate the error for the specified data set. The error is the largest distance. /// </summary> /// <param name="data">The data set to check.</param> /// <returns>The error.</returns> public double CalculateError(IMLDataSet data) { var bmu = new BestMatchingUnit(this); bmu.Reset(); // Determine the BMU for each training element. foreach (IMLDataPair pair in data) { IMLData input = pair.Input; bmu.CalculateBMU(input); } // update the error return(bmu.WorstDistance / 100.0); }