Exemplo n.º 1
0
Arquivo: Rgz.cs Projeto: Swipes13/smad
        private void computeAllKrits(int n, int m, double fullR2, double sigma2, TettaRSS tettaRss)
        {
            ForOptMdl.TettaRss.Add(tettaRss);
            ForOptMdl.Mellous.Add(tettaRss.Rss / sigma2 + 2.0 * m - n);

            double newR2 = calcR2(tettaRss.Y, n);

            ForOptMdl.ManyKrit.Add(newR2 / fullR2);

            var msep = tettaRss.Rss / (n * (n - m)) * (1 + n + m * (n + 1) / (n - m - 2));

            ForOptMdl.MSEP.Add(msep);
            var aev = tettaRss.Rss * m / (n * (n - m));

            ForOptMdl.AEV.Add(aev);

            var fullSum = 0.0;

            for (int d = 0; d < n; d++)
            {
                var dif = Math.Abs(_Y[d][0, 0] - tettaRss.Y[d][0, 0]);
                fullSum += dif;
            }
            ForOptMdl.E.Add(fullSum);
        }
Exemplo n.º 2
0
Arquivo: Rgz.cs Projeto: Swipes13/smad
        private void exceptionAlgorithm(int n, int fullM, double fullR2, double sigma2)
        {
            bool[] needFunc = new bool[TrueFunc.Count];
            for (int i = 0; i < TrueFunc.Count; i++)
            {
                needFunc[i] = TrueFunc[i];
            }
            var m = fullM; var nu2 = 1;

            for (int i = 0; i < fullM - 1; i++)
            {
                Dictionary <int, double> FCrit = new Dictionary <int, double>();
                var nu1 = n - m + 1; double nu2_nu1 = ((double)nu2 / (double)nu1);

                TettaRSS tettaRssBefore = TettaRSS.Compute(generateX(n, m, needFunc), _Y);
                computeAllKrits(n, m, fullR2, sigma2, tettaRssBefore);
                ForOptMdl.Functions.Add(needFunc.ToArray());

                for (int q = fullM - m, index = 0, newM = m - 1; q < fullM; q++, index++)
                {
                    var newNeedToAdd = new bool[TrueFunc.Count];
                    for (int w = 0; w < TrueFunc.Count; w++)
                    {
                        newNeedToAdd[w] = needFunc[w];
                    }
                    while (!newNeedToAdd[index] || !TrueFunc[index])
                    {
                        index++;
                    }
                    newNeedToAdd[index] = false;

                    TettaRSS newTettaRss = TettaRSS.Compute(generateX(n, newM, newNeedToAdd), _Y);
                    var      fCrit       = nu2_nu1 * (newTettaRss.Rss - tettaRssBefore.Rss) / newTettaRss.Rss;
                    FCrit.Add(index, fCrit);
                }
                ForOptMdl.AllFCrits.Add(FCrit.ToList());
                var sorted = FCrit.OrderBy(x => x.Value).ToList();
                m--; needFunc[sorted[0].Key] = false;
            }
            computeAllKrits(n, m, fullR2, sigma2, TettaRSS.Compute(generateX(n, m, needFunc), _Y));
            ForOptMdl.Functions.Add(needFunc.ToArray());
        }
Exemplo n.º 3
0
Arquivo: Rgz.cs Projeto: Swipes13/smad
        public void GenerateOptimalModel(OptimalModelAlgorithm alg)
        {
            if (!_initialized)
            {
                return;
            }
            ForOptMdl.Clear();

            var n     = Data.Count;
            int fullM = 0;

            foreach (bool b in TrueFunc)
            {
                if (b)
                {
                    fullM++;
                }
            }

            double fullR2 = calcR2(_Y, n);

            TettaRSS fullXTettaRss = TettaRSS.Compute(generateX(Data.Count, fullM, TrueFunc.ToArray()), _Y);
            var      sigma2        = fullXTettaRss.Rss / (n - fullM);

            if (alg == OptimalModelAlgorithm.Exception)
            {
                exceptionAlgorithm(n, fullM, fullR2, sigma2);
            }
            else
            {
                insertionAlgorithm(n, fullM, fullR2, sigma2);
            }
            selectBestF(ForOptMdl.Mellous, ref ForOptMdl.BestFMell);
            selectBestF(ForOptMdl.MSEP, ref ForOptMdl.BestFMSEP);
            selectBestF(ForOptMdl.AEV, ref ForOptMdl.BestFAEV);
            selectBestF(ForOptMdl.E, ref ForOptMdl.BestFE);
            selectBestFR(ForOptMdl.ManyKrit, ref ForOptMdl.BestFR);
        }
Exemplo n.º 4
0
Arquivo: Rgz.cs Projeto: Swipes13/smad
        private void computeAllKrits(int n, int m, double fullR2, double sigma2, TettaRSS tettaRss)
        {
            ForOptMdl.TettaRss.Add(tettaRss);
              ForOptMdl.Mellous.Add(tettaRss.Rss / sigma2 + 2.0 * m - n);

              double newR2 = calcR2(tettaRss.Y, n);
              ForOptMdl.ManyKrit.Add(newR2 / fullR2);

              var msep = tettaRss.Rss / (n * (n - m)) * (1 + n + m * (n + 1) / (n - m - 2));
              ForOptMdl.MSEP.Add(msep);
              var aev = tettaRss.Rss * m / (n * (n - m));
              ForOptMdl.AEV.Add(aev);

              var fullSum = 0.0;
              for (int d = 0; d < n; d++) {
            var dif = Math.Abs(_Y[d][0, 0] - tettaRss.Y[d][0, 0]);
            fullSum += dif;
              }
              ForOptMdl.E.Add(fullSum);
        }
Exemplo n.º 5
0
Arquivo: Rgz.cs Projeto: Swipes13/smad
        public void CheckMultiColliniar()
        {
            if (!_initialized) return;
              int n = Data.Count;
              int m = 0; foreach (bool b in TrueFunc) if (b) m++;
              _X = generateX(n, m, TrueFunc.ToArray());
              _TettaEst = TettaRSS.Compute(_X,_Y);
              var XTX = _X.Transpose() * _X;

              var XTXTrace = XTX * 1/XTX.Trace();
              ForMultCol.DetXTXTrace = XTXTrace.Determinant();
              ForMultCol.MinLambda = XTXTrace.MinEiganValue();
              ForMultCol.NeimanGoldstein = XTXTrace.MaxEiganValue() / ForMultCol.MinLambda;

              Matrix R = new Matrix(m, m);

              double r_max = 0.0;
              for (int j = 0; j < m; j++) {
            for (int i = 0; i < m; i++) {
              double sum_up = 0.0, sum_d1 = 0.0, sum_d2 = 0.0;
              for (int k = 0; k < n; k++) {
            sum_up += _X[k, i] * _X[k, j];
            sum_d1 += _X[k, i] * _X[k, i];
            sum_d2 += _X[k, j] * _X[k, j];
              }
              double rij = sum_up / (Math.Sqrt(sum_d1) * Math.Sqrt(sum_d2));
              if (i != j && Math.Abs(rij) > r_max)
            r_max = Math.Abs(rij);
              R[i, j] = rij;
            }
            R[j, j] = 1.0;
              }
              ForMultCol.MaxPairConjugation = r_max;

              R = R.Inverse();
              r_max = 0.0;
              for (int i = 0; i < m; i++) {
            double ri = Math.Sqrt(1.0 - 1.0 / R[i, i]);
            if (ri > r_max)
              r_max = ri;
              }
              ForMultCol.MaxConjugation = r_max;
        }
Exemplo n.º 6
0
Arquivo: Rgz.cs Projeto: Swipes13/smad
        public void CheckMultiColliniar()
        {
            if (!_initialized)
            {
                return;
            }
            int n = Data.Count;
            int m = 0; foreach (bool b in TrueFunc)

            {
                if (b)
                {
                    m++;
                }
            }

            _X        = generateX(n, m, TrueFunc.ToArray());
            _TettaEst = TettaRSS.Compute(_X, _Y);
            var XTX = _X.Transpose() * _X;

            var XTXTrace = XTX * 1 / XTX.Trace();

            ForMultCol.DetXTXTrace     = XTXTrace.Determinant();
            ForMultCol.MinLambda       = XTXTrace.MinEiganValue();
            ForMultCol.NeimanGoldstein = XTXTrace.MaxEiganValue() / ForMultCol.MinLambda;

            Matrix R = new Matrix(m, m);

            double r_max = 0.0;

            for (int j = 0; j < m; j++)
            {
                for (int i = 0; i < m; i++)
                {
                    double sum_up = 0.0, sum_d1 = 0.0, sum_d2 = 0.0;
                    for (int k = 0; k < n; k++)
                    {
                        sum_up += _X[k, i] * _X[k, j];
                        sum_d1 += _X[k, i] * _X[k, i];
                        sum_d2 += _X[k, j] * _X[k, j];
                    }
                    double rij = sum_up / (Math.Sqrt(sum_d1) * Math.Sqrt(sum_d2));
                    if (i != j && Math.Abs(rij) > r_max)
                    {
                        r_max = Math.Abs(rij);
                    }
                    R[i, j] = rij;
                }
                R[j, j] = 1.0;
            }
            ForMultCol.MaxPairConjugation = r_max;

            R     = R.Inverse();
            r_max = 0.0;
            for (int i = 0; i < m; i++)
            {
                double ri = Math.Sqrt(1.0 - 1.0 / R[i, i]);
                if (ri > r_max)
                {
                    r_max = ri;
                }
            }
            ForMultCol.MaxConjugation = r_max;
        }