Exemplo n.º 1
0
        public double[] repres(double[,] x, double[] y, int variables, int watches)
        {
            double[] p = new double[watches];
            double[,] o = new double[watches, variables + 1];
            for (int i = 0; i < watches; i++)
            {
                _1st_step.y1[i] = Math.Log(y[i]);
            }
            for (int i = 0; i < watches; i++)
            {
                for (int j = 0; j <= variables; j++)
                {
                    _1st_step.x1[i, j] = Math.Log(x[i, j]);
                }
                _1st_step.x1[i, 0] = 1;
            }
            Regession sle = new Regession();

            double[] b = sle.SLE(_1st_step.x1, _1st_step.y1, variables, watches);

            for (int i = 0; i < variables + 1; i++)
            {
                _1st_step.b0[i] = b[i];
            }

            b[0] = Math.Exp(b[0]);

            for (int i = 0; i < watches; i++)
            {
                p[i] = b[0] * Math.Pow(x[i, 1], b[1]);
            }
            return(p);
        }
Exemplo n.º 2
0
        public double[] power(double[,] x, double[] y, int variables, int watches)
        {
            double[] p = new double[watches];
            for (int i = 0; i < watches; i++)
            {
                _1st_step.y1[i] = Math.Log(y[i]);
            }

            for (int i = 0; i < watches; i++)
            {
                _1st_step.x1[i, 1] = x[i, 1];
            }

            Regession sle = new Regession();

            double[] b = sle.SLE(x, _1st_step.y1, variables, watches);

            for (int i = 0; i < variables + 1; i++)
            {
                _1st_step.b0[i] = b[i];
            }

            for (int i = 0; i <= variables; i++)
            {
                b[i] = Math.Exp(b[i]);
            }

            for (int i = 0; i < watches; i++)
            {
                p[i] = b[0] * Math.Pow(b[1], x[i, 1]);
            }
            return(p);
        }
Exemplo n.º 3
0
        public double[] linear(double[,] x, double[] y, int variables, int watches)
        {
            double[] p = new double[watches];

            Regession sle = new Regession();

            double[] b = sle.SLE(x, y, variables, watches);

            for (int i = 0; i < variables + 1; i++)
            {
                _1st_step.b0[i] = b[i];
            }

            for (int i = 0; i < watches; i++)
            {
                _1st_step.y1[i] = y[i];
            }
            for (int i = 0; i < watches; i++)
            {
                _1st_step.x1[i, 1] = x[i, 1];
            }


            for (int i = 0; i < watches; i++)
            {
                p[i] = 0;
                for (int j = 0; j < b.Length; j++)
                {
                    p[i] += x[i, j] * b[j];
                }
            }
            return(p);
        }
Exemplo n.º 4
0
        private void Enter_v_w_Click(object sender, EventArgs e)
        {
            //label1.Text = "sdjfhskdjhvsdf;lbvnszfkl;bha;lb";



            if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            string filename = openFileDialog1.FileName;

            lines = System.IO.File.ReadAllLines(filename);

            Linear.Series.Clear();
            Linear.Series.Add("y fact");
            Linear.Series.Add("y esmitated");
            Linear.Series["y fact"].ChartType      = SeriesChartType.Line;
            Linear.Series["y esmitated"].ChartType = SeriesChartType.Line;

            Exp.Series.Clear();
            Exp.Series.Add("y fact");
            Exp.Series.Add("y esmitated");
            Exp.Series["y fact"].ChartType      = SeriesChartType.Line;
            Exp.Series["y esmitated"].ChartType = SeriesChartType.Line;

            Power.Series.Clear();
            Power.Series.Add("y fact");
            Power.Series.Add("y esmitated");
            Power.Series["y fact"].ChartType      = SeriesChartType.Line;
            Power.Series["y esmitated"].ChartType = SeriesChartType.Line;

            Repres.Series.Clear();
            Repres.Series.Add("y fact");
            Repres.Series.Add("y esmitated");
            Repres.Series["y fact"].ChartType      = SeriesChartType.Line;
            Repres.Series["y esmitated"].ChartType = SeriesChartType.Line;



            variables = Convert.ToInt32(VarField.Text);
            watches   = Convert.ToInt32(WatchField.Text);

            double fs  = 0;
            double af  = 0;
            double afm = 0;
            int    mod = 0;

            y1 = new double[watches];
            x1 = new double[watches, variables + 1];

            double[] y = new double[watches];
            double[,] x = new double[watches, variables + 1];

            _1st_step.b0      = new double[variables + 1];
            _1st_step.average = new double[variables + 1];

            for (int h = 0; h < watches; h++)
            {
                x[h, 0] = 1;
            }

            for (int i = 0; i < watches; i++)
            {
                string[] line = lines[i].Split(' ', '	');
                y[i] = Convert.ToDouble(line[0]);
                for (int j = 0; j < variables; j++)
                {
                    x[i, j + 1] = Convert.ToDouble(line[1 + j]);
                }
            }

            Regession sle = new Regession();

            double[] y_es  = new double[watches];
            double[] y_es1 = new double[watches];
            double[] y_es2 = new double[watches];
            double[] y_es3 = new double[watches];

            y_es = sle.linear(x, y, variables, watches);
            double rr = sle.rr(y, y_es, average);

            fs  = sle.Fstat(rr, variables, watches);
            af  = sle.Afalse(y, y_es, watches);
            afm = af;
            if (afm >= af)
            {
                afm = af;
                mod = 1;
            }

            //if (variables == 1)
            //{

            /*double aaa = sle.sb(watches,variables);
             * double sss = sle.sa(watches, variables);*/
            AnLinar.Text = "коеф. детерминации: " + rr + Environment.NewLine + "F статистика: " + fs + Environment.NewLine + "Ошибка аппроксимации: " + af;
            //}

            for (int j = 0; j < watches; j++)
            {
                Linear.Series["y esmitated"].Points.Add(y_es[j], x[j, 1]);
                Linear.Series["y fact"].Points.Add(y[j], x[j, 1]);
            }

            if (variables == 1)
            {
                y_es1 = sle.exp(x, y, variables, watches);

                rr = sle.rr(y, y_es1, average);
                fs = sle.Fstat(rr, variables, watches);
                af = sle.Afalse(y, y_es1, watches);
                if (afm >= af)
                {
                    afm = af;
                    mod = 2;
                }
                AnExp.Text = "коеф. детерминации: " + rr + Environment.NewLine + "F статистика: " + fs + Environment.NewLine + "Ошибка аппроксимации: " + af;

                for (int j = 0; j < watches; j++)
                {
                    Exp.Series["y esmitated"].Points.Add(y_es1[j], x[j, 1]);
                    Exp.Series["y fact"].Points.Add(y[j], x[j, 1]);
                }

                y_es2 = sle.power(x, y, variables, watches);

                rr = sle.rr(y, y_es2, average);
                fs = sle.Fstat(rr, variables, watches);
                af = sle.Afalse(y, y_es2, watches);
                if (afm >= af)
                {
                    afm = af;
                    mod = 3;
                }
                AnPower.Text = "коеф. детерминации: " + rr + Environment.NewLine + "F статистика: " + fs + Environment.NewLine + "Ошибка аппроксимации: " + af;

                for (int j = 0; j < watches; j++)
                {
                    Power.Series["y esmitated"].Points.Add(y_es2[j], x[j, 1]);
                    Power.Series["y fact"].Points.Add(y[j], x[j, 1]);
                }

                y_es3 = sle.repres(x, y, variables, watches);

                rr = sle.rr(y, y_es3, average);
                fs = sle.Fstat(rr, variables, watches);
                af = sle.Afalse(y, y_es3, watches);
                if (afm >= af)
                {
                    afm = af;
                    mod = 4;
                }
                AnRepres.Text = "коеф. детерминации: " + rr + Environment.NewLine + "F статистика: " + fs + Environment.NewLine + "Ошибка аппроксимации: " + af;

                for (int j = 0; j < watches; j++)
                {
                    Repres.Series["y esmitated"].Points.Add(y_es3[j], x[j, 1]);
                    Repres.Series["y fact"].Points.Add(y[j], x[j, 1]);
                }

                if (mod == 1)
                {
                    Linear.BackColor = Color.FromArgb(125, 235, 110);
                }
                else
                if (mod == 2)
                {
                    Exp.BackColor = Color.FromArgb(125, 235, 110);
                }
                else
                if (mod == 3)
                {
                    Power.BackColor = Color.FromArgb(125, 235, 110);
                }
                else
                {
                    Repres.BackColor = Color.FromArgb(125, 235, 110);
                }
            }
        }