コード例 #1
0
 public void Add(double x, double y)
 {
     // no need to check validity of values explicitly here as it is checked in all three evaluators
     covCalculator.Add(x, y);
     sxCalculator.Add(x);
     syCalculator.Add(y);
 }
 /// <summary>
 /// Calculates linear scaling parameters in one pass.
 /// The formulas to calculate the scaling parameters were taken from Scaled Symblic Regression by Maarten Keijzer.
 /// http://www.springerlink.com/content/x035121165125175/
 /// </summary>
 public void Add(double original, double target)
 {
     // validity of values is checked in mean calculator and covariance calculator
     targetMeanCalculator.Add(target);
     originalMeanAndVarianceCalculator.Add(original);
     originalTargetCovarianceCalculator.Add(original, target);
 }
        public void Add(double original, double estimated)
        {
            // no need to check for validity of values explicitly as it is checked in the meanAndVariance calculator anyway
            double error = estimated - original;

            meanSquaredErrorCalculator.Add(error * error);
            originalVarianceCalculator.Add(original);
        }
コード例 #4
0
        public static void Calculate(IEnumerable <double> x, out double mean, out double variance, out OnlineCalculatorError meanErrorState, out OnlineCalculatorError varianceErrorState)
        {
            OnlineMeanAndVarianceCalculator meanAndVarianceCalculator = new OnlineMeanAndVarianceCalculator();

            foreach (double xi in x)
            {
                meanAndVarianceCalculator.Add(xi);
            }
            mean               = meanAndVarianceCalculator.Mean;
            variance           = meanAndVarianceCalculator.Variance;
            meanErrorState     = meanAndVarianceCalculator.MeanErrorState;
            varianceErrorState = meanAndVarianceCalculator.VarianceErrorState;
        }
コード例 #5
0
        public void Add(double startValue, IEnumerable <double> actualContinuation, IEnumerable <double> referenceContinuation, IEnumerable <double> predictedContinuation)
        {
            if (double.IsNaN(startValue) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0)
            {
                errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
            }
            else
            {
                var actualEnumerator    = actualContinuation.GetEnumerator();
                var predictedEnumerator = predictedContinuation.GetEnumerator();
                var referenceEnumerator = referenceContinuation.GetEnumerator();
                while (actualEnumerator.MoveNext() & predictedEnumerator.MoveNext() & referenceEnumerator.MoveNext()
                       & ErrorState != OnlineCalculatorError.InvalidValueAdded)
                {
                    double actual    = actualEnumerator.Current;
                    double predicted = predictedEnumerator.Current;
                    double reference = referenceEnumerator.Current;
                    if (double.IsNaN(actual) || double.IsNaN(predicted) || double.IsNaN(reference))
                    {
                        errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
                    }
                    else
                    {
                        // error of predicted change
                        double errorPredictedChange = (predicted - startValue) - (actual - startValue);
                        squaredErrorMeanCalculator.Add(errorPredictedChange * errorPredictedChange);

                        double errorReference = (reference - startValue) - (actual - startValue);
                        unbiasedEstimatorMeanCalculator.Add(errorReference * errorReference);
                    }
                }
                // check if both enumerators are at the end to make sure both enumerations have the same length
                if (actualEnumerator.MoveNext() || predictedEnumerator.MoveNext() || referenceEnumerator.MoveNext())
                {
                    errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
                }
                else
                {
                    errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1
                }
            }
        }
コード例 #6
0
 public static void Calculate(IEnumerable<double> x, out double mean, out double variance, out OnlineCalculatorError meanErrorState, out OnlineCalculatorError varianceErrorState) {
   OnlineMeanAndVarianceCalculator meanAndVarianceCalculator = new OnlineMeanAndVarianceCalculator();
   foreach (double xi in x) {
     meanAndVarianceCalculator.Add(xi);
   }
   mean = meanAndVarianceCalculator.Mean;
   variance = meanAndVarianceCalculator.Variance;
   meanErrorState = meanAndVarianceCalculator.MeanErrorState;
   varianceErrorState = meanAndVarianceCalculator.VarianceErrorState;
 }
コード例 #7
0
 public void Add(double original, double estimated)
 {
     meanAndVarianceCalculator.Add(estimated - original);
 }