コード例 #1
0
 public static (double[], double[]) Calculate(double[] inputValue, int amountOfPeriodsToCalculate)
 {
     Name = "Promedio simple";
     //Call function to calculate the 'n' next periods
     double[] full = SimpleAverageHelper.Calculate(
         inputValue.ToList(), inputValue.Sum(), amountOfPeriodsToCalculate).ToArray <double>();
     //Check if a value is less than 0
     if (full.Where(f => f < 0).Count() > 0)
     {
         Name = "!!!" + Name;
     }
     return(ArrayBased.Split(full, amountOfPeriodsToCalculate));
 }
コード例 #2
0
 public static (double[], double[]) Calculate(double[] inputValue, double smoothingConstant)
 {
     if (0 == inputValue.Length)
     {
         throw new EmptyParameterArray();
     }
     Name = string.Format("Suavización exponencial simple | cte. de suavización: {0}", smoothingConstant);
     double[] full = SimpleExponentialSmoothingHelper.Calculate(
         inputValue.ToList(), inputValue.Take(1).ToList <double>(), smoothingConstant).ToArray();
     //Check if a value is less than 0
     if (full.Where(f => f < 0).Count() > 0)
     {
         Name = "!!!" + Name;
     }
     return(ArrayBased.Split(full, 1));
 }
コード例 #3
0
        public static (double[], double[]) Calculate(double[] inputValue, int amountOfPeriodsToCalculate)
        {
            Name = "Simple Linear Regression";
            int inputLength = inputValue.Length;

            double[] xData = Enumerable.Range(0, inputLength).Select(i => (double)i).ToArray();
            Tuple <double, double> parameters = Fit.Line(xData, inputValue);

            double[] full = Enumerable.Range(0, inputLength + amountOfPeriodsToCalculate)
                            .Select(i => parameters.Item1 + parameters.Item2 * i).ToArray();
            //Check if a value is less than 0
            if (full.Where(f => f < 0).Count() > 0)
            {
                Name = "!!!" + Name;
            }
            return(ArrayBased.Split(full, amountOfPeriodsToCalculate));
        }
コード例 #4
0
 public static (double[], double[]) Calculate(double[] inputValue, int movingAverageTerms)
 {
     if (0 > movingAverageTerms)
     {
         throw new NegativeMovingAverageTerms();
     }
     if (inputValue.Length < movingAverageTerms)
     {
         return(new double[0], new double[0]);                                   // throw new MovingAverageTermsBiggerThanInputSize();
     }
     Name = string.Format("Promedio móvil ({0})", movingAverageTerms);
     //Call function to calculate the 'n' next periods
     double[] full = MovingAverageHelper.Calculate(
         inputValue.ToList(), movingAverageTerms, new List <double>()).ToArray <double>();
     //Check if a value is less than 0
     if (full.Where(f => f < 0).Count() > 0)
     {
         Name = "!!!" + Name;
     }
     return(ArrayBased.Split(full, 1));
 }
コード例 #5
0
        //116
        public static (double[], double[]) Calculate(double[] inputValue, int amountOfPeriodsToCalculate, int movingAverageTerms)
        {
            if (0 > movingAverageTerms)
            {
                throw new NegativeMovingAverageTerms();
            }
            if (inputValue.Length < movingAverageTerms)
            {
                return(new List <double>()
                {
                    -1
                }.ToArray(), new List <double>()
                {
                    -1
                }.ToArray());                                                                                                  // throw new MovingAverageTermsBiggerThanInputSize();
            }
            if (0 > amountOfPeriodsToCalculate)
            {
                throw new NegativePeriodsToCalculate();
            }
            Name = string.Format("Promedio móvil doble ({0})", movingAverageTerms);
            //Calculate first moving average
            double[] firstAverage = ArrayBased.Join(MovingAverage.Calculate(inputValue, movingAverageTerms));
            //Calculate second moving average
            double[] secondAverage = ArrayBased.Join(MovingAverage.Calculate(firstAverage, movingAverageTerms));
            //Remove first movingAverageTerms - 1 values since they are not use
            List <double> fixFirstAverage = firstAverage.ToList().Skip(movingAverageTerms - 1).ToList();

            //Call function to calculate the 'n' next periods
            double[] full = DoubleMovingAverageHelper.Calculate(
                fixFirstAverage, secondAverage.ToList(), new List <double>(),
                movingAverageTerms, 1, amountOfPeriodsToCalculate).ToArray <double>();
            //Check if a value is less than 0
            if (full.Where(f => f < 0).Count() > 0)
            {
                Name = "!!!" + Name;
            }
            return(ArrayBased.Split(full, amountOfPeriodsToCalculate));
        }
コード例 #6
0
        public static (double[], double[]) Calculate(
            double[] inputValue, int amountOfPeriodsToCalculate, decimal dataSmoothingFactor, decimal trendSmoothingFactor)
        {
            SmallestError = double.MaxValue;
            double initalSmoothedValue = inputValue[0];

            (List <double>, List <double>)auxValues = HoltHelper.CalculteSmoothedAndTrendValues(
                inputValue.Select(d => (decimal)d).ToList(), dataSmoothingFactor, trendSmoothingFactor, new List <decimal>(), new List <decimal>());
            //Calculate forecast for periods which already have real values
            double[] full =
                HoltHelper.Calculate(auxValues.Item1, auxValues.Item2, inputValue.Take(1).ToList()).ToArray <double>();
            (double[], double[])calculated = ArrayBased.Split(full, amountOfPeriodsToCalculate);
            double mad = MeanAbsoluteDeviation.Calculation(inputValue, calculated.Item1);

            if (!double.IsNaN(mad) && mad < SmallestError)
            {
                SmallestError      = mad;
                BestDataSmoothing  = (double)dataSmoothingFactor;
                BestTrendSmoothing = (double)trendSmoothingFactor;
                BestResult         = calculated;
            }
            return(calculated);
        }