/// <summary>
        /// Mengestimasi parameter
        /// </summary>
        private void EstimateParameters()
        {
            if (this.sesRdb.Checked == true)
            {
                if (this.variable.SeriesValuesNoNaN.Count < 7)
                {
                    MessageBox.Show("Unsufficent number of observations", "Exponential Smoothing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.DialogResult = DialogResult.None;
                    return;
                }

                //get alpha
                try { this.esProperties.alpha = double.Parse(this.alpha.Text); }
                catch { this.esProperties.alpha = 0.2; }

                this.esProperties.initialModel = 1;
                ses = new SingleExponentialSmoothing(this.variable, this.esProperties.alpha, this.singleInitialSmoothed);

                this.esTable.smoothed  = ses.Smoothed;
                this.esTable.predicted = ses.Predicted;
                this.esTable.residual  = ses.Residual;

                this.esProperties.includedObservations = ses.IncludedObservations;
                this.esProperties.sseES  = ses.SSE;
                this.esProperties.mseES  = ses.MSE;
                this.esProperties.maeES  = ses.MAE;
                this.esProperties.mpeES  = ses.MPE;
                this.esProperties.mapeES = ses.MAPE;
            }

            else if (this.brownRdb.Checked == true)
            {
                //get alpha
                try { this.esProperties.alpha = double.Parse(this.alpha.Text); }
                catch { this.esProperties.alpha = 0.2; }

                this.esProperties.initialModel = 2;
                brown = new DoubleExponentialSmoothingBrown(this.variable, this.esProperties.alpha);

                this.esTable.smoothed  = brown.Smoothed;
                this.esTable.predicted = brown.Predicted;
                this.esTable.residual  = brown.Residual;

                this.esProperties.includedObservations = brown.IncludedObservations;
                this.esProperties.sseES  = brown.SSE;
                this.esProperties.mseES  = brown.MSE;
                this.esProperties.maeES  = brown.MAE;
                this.esProperties.mpeES  = brown.MPE;
                this.esProperties.mapeES = brown.MAPE;
            }

            else if (this.holtRdb.Checked == true)
            {
                //get alpha
                try { this.esProperties.alpha = double.Parse(this.alpha.Text); }
                catch { this.esProperties.alpha = 0.2; }
                //get gamma
                try { this.esProperties.gamma = double.Parse(this.gamma.Text); }
                catch { this.esProperties.gamma = 0.2; }

                this.esProperties.initialModel = 3;

                holt = new DoubleExponentialSmoothingHolt(this.variable, this.esProperties.alpha, this.esProperties.gamma);

                this.esTable.smoothed  = holt.Smoothed;
                this.esTable.trend     = holt.Trend;
                this.esTable.predicted = holt.Predicted;
                this.esTable.residual  = holt.Residual;

                this.esProperties.includedObservations = holt.IncludedObservations;
                this.esProperties.sseES  = holt.SSE;
                this.esProperties.mseES  = holt.MSE;
                this.esProperties.maeES  = holt.MAE;
                this.esProperties.mpeES  = holt.MPE;
                this.esProperties.mapeES = holt.MAPE;
            }

            else if (this.winterRdb.Checked == true)
            {
                if (this.variable.SeriesValuesNoNaN.Count < 4)
                {
                    MessageBox.Show("Unsufficent number of observations", "Exponential Smoothing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.DialogResult = DialogResult.None;
                    return;
                }

                //get alpha
                try { this.esProperties.alpha = double.Parse(this.alpha.Text); }
                catch { this.esProperties.alpha = 0.2; }
                //get gamma
                try { this.esProperties.gamma = double.Parse(this.gamma.Text); }
                catch { this.esProperties.gamma = 0.2; }
                //get beta
                try { this.esProperties.beta = double.Parse(this.beta.Text); }
                catch { this.esProperties.beta = 0.2; }

                //get seasonal length
                try { this.esProperties.seasonalLength = int.Parse(this.seasonalBox.Text); }
                catch { this.esProperties.seasonalLength = 2; }

                this.esProperties.initialModel = 4;
                winter = new TripleExponentialSmoothingWinter(this.variable, this.esProperties.alpha, this.esProperties.gamma, this.esProperties.beta, this.esProperties.seasonalLength, this.esProperties.isMultiplicative);

                this.esTable.smoothed  = winter.Smoothed;
                this.esTable.trend     = winter.Trend;
                this.esTable.seasonal  = winter.Seasonal;
                this.esTable.predicted = winter.Predicted;
                this.esTable.residual  = winter.Residual;

                this.esProperties.includedObservations = winter.IncludedObservations;
                this.esProperties.sseES  = winter.SSE;
                this.esProperties.mseES  = winter.MSE;
                this.esProperties.maeES  = winter.MAE;
                this.esProperties.mpeES  = winter.MPE;
                this.esProperties.mapeES = winter.MAPE;
            }
        }
        private void GridSearch()
        {
            double alphaStart = (double)this.alphaStartUpDown.Value;
            double alphaStop = (double)this.alphaStopUpDown.Value;
            double alphaIncrement = (double)this.alphaIncrementUpDown.Value;
            double currentAlpha = alphaStart;
            double solutionCount = double.Parse(solutionBox.Text);

            double maxSolutionsCriterion = 0;
            int maxSolutionIndex = -1;

            int increment = 0;

            while (currentAlpha <= alphaStop)
            {
                DoubleExponentialSmoothingBrown des = new DoubleExponentialSmoothingBrown(variable, currentAlpha);

                double mse = des.MSE;

                // Masukkan sejumlah solutionCount solusi pertama ke list
                if (solutions.Count < solutionCount)
                {
                    solutions.Add(des);
                    if (des.MSE > maxSolutionsCriterion)
                    {
                        maxSolutionsCriterion = des.MSE;
                        maxSolutionIndex = solutions.Count - 1;
                    }
                }
                // list solusi sudah penuh
                else
                {
                    // jika lebih kecil dari MSE terbesar pada list, ganti solusi terbesar itu
                    // dengan solusi ini
                    if (des.MSE < maxSolutionsCriterion)
                    {
                        solutions[maxSolutionIndex] = des;
                        maxSolutionIndex = this.FindMaximumCriterionIndex(solutions);
                        maxSolutionsCriterion = solutions[maxSolutionIndex].MSE;
                    }
                }

                currentAlpha += alphaIncrement;
                ++increment;
            }

            //this.textBox2.Visible = true;
            //this.textBox2.Text = increment.ToString();

            // urutkan berdasarkan mse
            solutions.Sort(delegate(DoubleExponentialSmoothingBrown des1, DoubleExponentialSmoothingBrown des2) { return des1.MSE.CompareTo(des2.MSE); });

            this.resultGrid.RowCount = solutions.Count;
            // tampilklan ke grid
            for (int i = 0; i < solutions.Count; i++)
            {
                int row = i + 1;
                this.resultGrid.Rows[i].HeaderCell.Value = row.ToString();
                this.resultGrid[0, i].Value = solutions[i].Alpha.ToString("F3");
                this.resultGrid[1, i].Value = solutions[i].MAE.ToString("F5");
                this.resultGrid[2, i].Value = solutions[i].MSE.ToString("F5");
                this.resultGrid[3, i].Value = solutions[i].MPE.ToString("F5");
                this.resultGrid[4, i].Value = solutions[i].MAPE.ToString("F5");
            }
        }
        /// <summary>
        /// Mengestimasi parameter
        /// </summary>
        private void EstimateParameters()
        {
            if (this.sesRdb.Checked == true)
            {
                if (this.variable.SeriesValuesNoNaN.Count < 7)
                {
                    MessageBox.Show("Unsufficent number of observations", "Exponential Smoothing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.DialogResult = DialogResult.None;
                    return;
                }

                //get alpha
                try { this.esProperties.alpha = double.Parse(this.alpha.Text); }
                catch { this.esProperties.alpha = 0.2; }

                this.esProperties.initialModel = 1;
                ses = new SingleExponentialSmoothing(this.variable, this.esProperties.alpha,this.singleInitialSmoothed);

                this.esTable.smoothed = ses.Smoothed;
                this.esTable.predicted = ses.Predicted;
                this.esTable.residual = ses.Residual;

                this.esProperties.includedObservations = ses.IncludedObservations;
                this.esProperties.sseES = ses.SSE;
                this.esProperties.mseES = ses.MSE;
                this.esProperties.maeES = ses.MAE;
                this.esProperties.mpeES = ses.MPE;
                this.esProperties.mapeES = ses.MAPE;
            }

            else if (this.brownRdb.Checked == true)
            {
                //get alpha
                try { this.esProperties.alpha = double.Parse(this.alpha.Text); }
                catch { this.esProperties.alpha = 0.2; }

                this.esProperties.initialModel = 2;
                brown = new DoubleExponentialSmoothingBrown(this.variable, this.esProperties.alpha);

                this.esTable.smoothed = brown.Smoothed;
                this.esTable.predicted = brown.Predicted;
                this.esTable.residual = brown.Residual;

                this.esProperties.includedObservations = brown.IncludedObservations;
                this.esProperties.sseES = brown.SSE;
                this.esProperties.mseES = brown.MSE;
                this.esProperties.maeES = brown.MAE;
                this.esProperties.mpeES = brown.MPE;
                this.esProperties.mapeES = brown.MAPE;
            }

            else if (this.holtRdb.Checked == true)
            {
                //get alpha
                try { this.esProperties.alpha = double.Parse(this.alpha.Text); }
                catch { this.esProperties.alpha = 0.2; }
                //get gamma
                try { this.esProperties.gamma = double.Parse(this.gamma.Text); }
                catch { this.esProperties.gamma = 0.2; }

                this.esProperties.initialModel = 3;

                holt = new DoubleExponentialSmoothingHolt(this.variable, this.esProperties.alpha, this.esProperties.gamma);

                this.esTable.smoothed = holt.Smoothed;
                this.esTable.trend = holt.Trend;
                this.esTable.predicted = holt.Predicted;
                this.esTable.residual = holt.Residual;

                this.esProperties.includedObservations = holt.IncludedObservations;
                this.esProperties.sseES = holt.SSE;
                this.esProperties.mseES = holt.MSE;
                this.esProperties.maeES = holt.MAE;
                this.esProperties.mpeES = holt.MPE;
                this.esProperties.mapeES = holt.MAPE;
            }

            else if (this.winterRdb.Checked == true)
            {
                if (this.variable.SeriesValuesNoNaN.Count < 4)
                {
                    MessageBox.Show("Unsufficent number of observations", "Exponential Smoothing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.DialogResult = DialogResult.None;
                    return;
                }

                //get alpha
                try { this.esProperties.alpha = double.Parse(this.alpha.Text); }
                catch { this.esProperties.alpha = 0.2; }
                //get gamma
                try { this.esProperties.gamma = double.Parse(this.gamma.Text); }
                catch { this.esProperties.gamma = 0.2; }
                //get beta
                try { this.esProperties.beta = double.Parse(this.beta.Text); }
                catch { this.esProperties.beta = 0.2; }

                //get seasonal length
                try { this.esProperties.seasonalLength = int.Parse(this.seasonalBox.Text); }
                catch { this.esProperties.seasonalLength = 2; }

                this.esProperties.initialModel = 4;
                winter = new TripleExponentialSmoothingWinter(this.variable, this.esProperties.alpha, this.esProperties.gamma, this.esProperties.beta, this.esProperties.seasonalLength, this.esProperties.isMultiplicative);

                this.esTable.smoothed = winter.Smoothed;
                this.esTable.trend = winter.Trend;
                this.esTable.seasonal = winter.Seasonal;
                this.esTable.predicted = winter.Predicted;
                this.esTable.residual = winter.Residual;

                this.esProperties.includedObservations = winter.IncludedObservations;
                this.esProperties.sseES = winter.SSE;
                this.esProperties.mseES = winter.MSE;
                this.esProperties.maeES = winter.MAE;
                this.esProperties.mpeES = winter.MPE;
                this.esProperties.mapeES = winter.MAPE;
            }
        }
        private void GridSearch()
        {
            double alphaStart     = (double)this.alphaStartUpDown.Value;
            double alphaStop      = (double)this.alphaStopUpDown.Value;
            double alphaIncrement = (double)this.alphaIncrementUpDown.Value;
            double currentAlpha   = alphaStart;
            double solutionCount  = double.Parse(solutionBox.Text);

            double maxSolutionsCriterion = 0;
            int    maxSolutionIndex      = -1;

            int increment = 0;

            while (currentAlpha <= alphaStop)
            {
                DoubleExponentialSmoothingBrown des = new DoubleExponentialSmoothingBrown(variable, currentAlpha);

                double mse = des.MSE;

                // Masukkan sejumlah solutionCount solusi pertama ke list
                if (solutions.Count < solutionCount)
                {
                    solutions.Add(des);
                    if (des.MSE > maxSolutionsCriterion)
                    {
                        maxSolutionsCriterion = des.MSE;
                        maxSolutionIndex      = solutions.Count - 1;
                    }
                }
                // list solusi sudah penuh
                else
                {
                    // jika lebih kecil dari MSE terbesar pada list, ganti solusi terbesar itu
                    // dengan solusi ini
                    if (des.MSE < maxSolutionsCriterion)
                    {
                        solutions[maxSolutionIndex] = des;
                        maxSolutionIndex            = this.FindMaximumCriterionIndex(solutions);
                        maxSolutionsCriterion       = solutions[maxSolutionIndex].MSE;
                    }
                }

                currentAlpha += alphaIncrement;
                ++increment;
            }

            //this.textBox2.Visible = true;
            //this.textBox2.Text = increment.ToString();

            // urutkan berdasarkan mse
            solutions.Sort(delegate(DoubleExponentialSmoothingBrown des1, DoubleExponentialSmoothingBrown des2) { return(des1.MSE.CompareTo(des2.MSE)); });

            this.resultGrid.RowCount = solutions.Count;
            // tampilklan ke grid
            for (int i = 0; i < solutions.Count; i++)
            {
                int row = i + 1;
                this.resultGrid.Rows[i].HeaderCell.Value = row.ToString();
                this.resultGrid[0, i].Value = solutions[i].Alpha.ToString("F3");
                this.resultGrid[1, i].Value = solutions[i].MAE.ToString("F5");
                this.resultGrid[2, i].Value = solutions[i].MSE.ToString("F5");
                this.resultGrid[3, i].Value = solutions[i].MPE.ToString("F5");
                this.resultGrid[4, i].Value = solutions[i].MAPE.ToString("F5");
            }
        }