コード例 #1
0
ファイル: RecordClass.cs プロジェクト: rj128x/EDSProject2019
        public static void calcSTATIZMRegr(List <Record> dataS, ref double STATIZM, ref double MP, ref double PSgl, BlockData bd)
        {
            SortedList <double, List <double[]> > FullData = new SortedList <double, List <double[]> >();

            List <double> Data     = new List <double>();
            List <double> DataAbs  = new List <double>();
            List <double> DataSign = new List <double>();
            List <double> X        = new List <double>();
            List <double> Y        = new List <double>();

            foreach (Record rec in dataS)
            {
                double d = rec.F_gc - 50;
                double y = (rec.P_fakt - rec.P_plan - rec.P_zvn) / bd.PNom * 100;
                X.Add(d);
                Y.Add(y);
            }

            /*X = calcAVGKoleb(X,20);
            *  Y = calcAVGKoleb(Y,20);*/

            for (int ii = 0; ii < X.Count; ii++)
            {
                double d = X[ii];
                double y = Y[ii];
                if (Math.Abs(d) > 1)
                {
                    continue;
                }

                double absD = Math.Abs(d);

                if (!FullData.ContainsKey(absD))
                {
                    FullData.Add(absD, new List <double[]>());
                }

                FullData[absD].Add(new double[] { y, Math.Sign(d) });
            }
            List <double> absXKeys = new List <double>();

            List <double> keys = FullData.Keys.ToList();
            int           i    = 0;

            foreach (double x in keys)
            {
                foreach (double[] subArr in FullData[x])
                {
                    double y    = subArr[0];
                    double sign = subArr[1];
                    Data.Add(y);
                    DataAbs.Add(y * y);
                    DataSign.Add(sign);


                    if (i > 0)
                    {
                        DataAbs[i] += DataAbs[i - 1];
                    }
                    absXKeys.Add(x);
                    i++;
                }
            }

            double minDV  = double.MaxValue;
            double minDV2 = double.MaxValue;


            double v0 = 0;

            double o2;
            double o1;

            double absX = 0;
            double sgnX = 0;
            double regr = 0;
            double xi;
            double yi = 0;

            List <double> DataStat = new List <double>();
            List <double> KeysStat = new List <double>();

            for (double s = 3; s < 12; s += 0.01)
            {
                DataStat.Add(0);
                KeysStat.Add(s);
            }

            OutputData.InitOutput("test");
            for (o1 = 0.005; o1 <= 0.03; o1 += 0.0001)
            {
                int o1I  = 0;
                int cnt0 = 0;
                int si   = 0;
                while (o1I < absXKeys.Count)
                {
                    if (absXKeys[o1I] > (o1))
                    {
                        break;
                    }
                    o1I++;
                }
                double sum1 = DataAbs[o1I - 1];
                for (si = 0; si < KeysStat.Count; si++)
                {
                    DataStat[si] = sum1;
                }
                cnt0 = o1I;
                while (o1I < absXKeys.Count)
                {
                    absX = absXKeys[o1I];
                    sgnX = DataSign[o1I];
                    xi   = absX * sgnX;
                    yi   = Data[o1I];

                    regr = -(xi - sgnX * o1);


                    for (si = 0; si < KeysStat.Count; si++)
                    {
                        o2            = 200 / KeysStat[si];
                        DataStat[si] += (yi - o2 * regr) * (yi - o2 * regr);
                    }
                    o1I++;
                }

                /*for (si = 0; si < KeysStat.Count; si++)
                 * {
                 *
                 *  double mv = sum1 / cnt0 + (DataStat[si] / (absXKeys.Count - cnt0));
                 *  DataStat[si] = mv;
                 *
                 * }*/


                for (si = 1; si < KeysStat.Count - 1; si++)
                {
                    if (DataStat[si - 1] > DataStat[si] && DataStat[si + 1] > DataStat[si])
                    {
                        double val = DataStat[si];
                        if (val < minDV)
                        {
                            minDV   = val;
                            minDV2  = sum1;
                            STATIZM = KeysStat[si];
                            MP      = o1;
                        }
                    }
                }
                OutputData.writeToOutput("test", string.Join(";", DataStat));
            }
        }
コード例 #2
0
ファイル: RecordClass.cs プロジェクト: rj128x/EDSProject2019
        public static void calcSTATIZM(List <Record> dataS, ref double STATIZM, ref double MP, ref double PSgl, ref int step)
        {
            List <double> X = new List <double>();
            List <double> Y = new List <double>();
            SortedList <double, double> Data    = new SortedList <double, double>();
            SortedList <double, double> DataAbs = new SortedList <double, double>();

            foreach (Record rec in dataS)
            {
                double d = rec.F_gc - 50;
                double y = rec.P_fakt - rec.P_plan - rec.P_zvn;
                X.Add(d);
                Y.Add(y);
            }



            int n = X.Count;


            double minDV = double.MaxValue;

            double vs0  = 0;
            double vmp0 = 0;
            double v0   = 0;
            double v1   = 0;
            double o2   = 40;
            double o1   = 0.02;
            double p    = 0.001;
            double sO1  = 0.001;
            double sO2  = 1;
            double sP   = 0.001;
            bool   ok   = false;

            OutputData.InitOutput("test");

            double prevGrad = 1;
            double prevVal  = funcRegr(X, Y, o1, o2, p);

            step = 5000;


            while (!ok)
            {
                step--;
                double[] arr  = getProizv(X, Y, o1, o2, p);
                double   dO1  = arr[0] / X.Count;
                double   dO2  = arr[1];
                double   dP   = arr[2] / X.Count;
                double   grad = Math.Sqrt(dO1 * dO1 + dO2 * dO2 + dP * dP);
                double   cO1  = Math.Abs(dO1 / grad);
                double   cO2  = Math.Abs(dO2 / grad);
                double   cP   = Math.Abs(dP / grad);
                OutputData.writeToOutput("test", String.Join(";", new double[] { o1, o2, p, dO1, dO2, dP, grad }));

                /*o1 = dO1 < 0 ? o1 + sO1 : o1 - sO1 / 2;
                 * o2 = dO2 < 0 ? o2 + sO2 : o2 - sO2 / 2;
                 * p = dP < 0 ? p + sP  : p - sP / 2;*/

                /*cO1 = cO1 < 0.01 ? 0.01 : cO1 > 1 ? 1 : cO1;
                 * cO2 = cO2 < 0.01 ? 0.01 : cO2 > 1 ? 1 : cO2;
                 * cP = cP < 0.01 ? 0.01 : cP > 1 ? 1 : cP;*/

                o1 = o1 - sO1 * cO1 * Math.Sign(dO1);
                o2 = o2 - sO2 * cO2 * Math.Sign(dO2);
                p  = p - sP * cP * Math.Sign(dP);

                double val = funcRegr(X, Y, o1, o2, p);
                prevGrad = grad;

                ok      = Math.Abs(val - prevVal) < 0.0001 || step < 1;
                prevVal = val;
            }
            STATIZM = 200 / o2;
            MP      = o1;
            PSgl    = p;
        }