public double CalculateError(IMLDataSet data) { BestMatchingUnit unit = new BestMatchingUnit(this); unit.Reset(); foreach (IMLDataPair pair in data) { IMLData input = pair.Input; unit.CalculateBMU(input); } return (unit.WorstDistance / 100.0); }
/// <summary> /// Perform one training iteration. /// </summary> public override void Iteration() { EncogLogging.Log(EncogLogging.LevelInfo, "Performing SOM Training iteration."); PreIteration(); // Reset the BMU and begin this iteration. _bmuUtil.Reset(); var won = new int[_outputNeuronCount]; double leastRepresentedActivation = Double.PositiveInfinity; IMLData leastRepresented = null; // Reset the correction matrix for this synapse and iteration. _correctionMatrix.Clear(); // Determine the BMU for each training element. foreach (IMLDataPair pair in Training) { IMLData input = pair.Input; int bmu = _bmuUtil.CalculateBMU(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. IMLData output = Compute(_network, pair.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 = pair.Input; } } Train(bmu, _network.Weights, 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; PostIteration(); }
/// <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; }