/// Compute suitable limits and bin width. /// @param from approximate lower limit of first histogram bin. /// @param to approximate upper limit of last histogram bin. /// @param bins desired number of bins. /// @exception ArgumentOutOfRangeException /// if the number of bins is non-positive, /// if the limits are inversed. private void DefineParameters(double from, double to, int bins) { if (from >= to) { throw new ArgumentOutOfRangeException( "Inverted range: minimum = " + from + ", maximum = " + to); } if (bins < 1) { throw new ArgumentOutOfRangeException( "Non-positive number of bins: " + bins); } _binWidth = DhbMath.RoundToScale((to - from) / bins, _integerBinWidth); _minimum = _binWidth * Math.Floor(from / _binWidth); int numberOfBins = (int)Math.Ceiling((to - _minimum) / _binWidth); if (_minimum + numberOfBins * _binWidth <= to) { numberOfBins++; } _contents = new int[numberOfBins]; _cached = false; _cache = null; Reset(); }
/// Initializes internal parameters to start the iterative process. /// Assigns default derivative if necessary. public override void InitializeIterations() { if (_df == null) { _df = new FunctionDerivative(_f); } if (double.IsNaN(_result)) { _result = 0; } int n = 0; Random random = new Random(); while (DhbMath.Equal(_df.Value(_result), 0)) { if (++n > MaximumIterations) { break; } _result += random.NextDouble(); } }