public override Color Compute(double x, double y) { double[] response = _neuralNetwork.Response(new double[] { x, y }); if (response.Length > _outputColors.Count) { throw new InvalidOperationException( "The number of outputs is greater than the number of colors."); } double red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0; for (int i = 0; i < response.Length; i++) { double scaledResult = response[i] * _outputScale + _outputOffset; red += _outputColors[i].R * scaledResult; green += _outputColors[i].G * scaledResult; blue += _outputColors[i].B * scaledResult; alpha += _outputColors[i].A * scaledResult; } if (_brightnessScaling) { red /= response.Length; green /= response.Length; blue /= response.Length; alpha /= response.Length; } return(Color.FromArgb( ClampColorValue(alpha), ClampColorValue(red), ClampColorValue(green), ClampColorValue(blue) )); }
internal void PerformTeaching(double teachingRatio) { /* We assume that we have non-zero amount of elements in the teaching set, * so we don't check if the 0 index is correct. This condition is * established by LoadTeachingSet(). */ if (++_currentElementIndex >= _teachingSet.Count) { _currentElementIndex = 0; } _examinedNetwork.LearnSimple(CurrentNormalizedElement, teachingRatio, ref _previousResponse, ref _previousError); _currentResponse = _examinedNetwork.Response(CurrentNormalizedElement.Inputs); _currentError = new double[_currentResponse.Length]; for (int i = 0; i < _currentResponse.Length; i++) { _currentError[i] = CurrentElement.ExpectedOutputs[i] - _currentResponse[i]; } /*double avg = 0.0; * foreach (double err in _currentError) * avg += Math.Abs(err); * avg /= _currentError.Length; * _progressHistory.Buffer.Add((float)avg);*/ double avg = 0.0; foreach (TeachingSet.Element elem in _normalizedTeachingSet) { double[] resp = _examinedNetwork.Response(elem.Inputs); for (int i = 0; i < resp.Length; i++) { avg += Math.Abs(elem.ExpectedOutputs[i] - resp[i]); } } avg /= _examinedNetwork.OutputCount * _normalizedTeachingSet.Count; _progressHistory.Buffer.Add((float)avg); _teachingStep++; }