示例#1
0
        private void createRegChart()
        {
            if (glm == null)
            {
                Accord.Statistics.Links.ILinkFunction lFunc = new Accord.Statistics.Links.IdentityLinkFunction();
                switch (Link)
                {
                case LinkFunction.Absolute:
                    lFunc = new Accord.Statistics.Links.AbsoluteLinkFunction();
                    break;

                case LinkFunction.Cauchit:
                    lFunc = new Accord.Statistics.Links.CauchitLinkFunction();
                    break;

                case LinkFunction.Inverse:
                    lFunc = new Accord.Statistics.Links.InverseLinkFunction();
                    break;

                case LinkFunction.InverseSquared:
                    lFunc = new Accord.Statistics.Links.InverseSquaredLinkFunction();
                    break;

                case LinkFunction.Logit:
                    lFunc = new Accord.Statistics.Links.LogitLinkFunction();
                    break;

                case LinkFunction.Log:
                    lFunc = new Accord.Statistics.Links.LogLinkFunction();
                    break;

                case LinkFunction.LogLog:
                    lFunc = new Accord.Statistics.Links.LogLogLinkFunction();
                    break;

                case LinkFunction.Probit:
                    lFunc = new Accord.Statistics.Links.ProbitLinkFunction();
                    break;

                case LinkFunction.Sin:
                    lFunc = new Accord.Statistics.Links.SinLinkFunction();
                    break;

                case LinkFunction.Threshold:
                    lFunc = new Accord.Statistics.Links.ThresholdLinkFunction();
                    break;

                default:
                    break;
                }
                glm = new Accord.Statistics.Models.Regression.GeneralizedLinearRegression(lFunc, coefficients, stdError);
            }
            Forms.Stats.frmChart          hist       = (Forms.Stats.frmChart)ModelHelper.generateRegressionGraphic(IndependentFieldNames);
            System.Windows.Forms.ComboBox cmbPrimary = (System.Windows.Forms.ComboBox)hist.Controls["cmbPrimary"];
            cmbPrimary.SelectedValueChanged += new EventHandler(cmbPrimary_SelectedValueChanged);
            System.Windows.Forms.TrackBar tb = (System.Windows.Forms.TrackBar)hist.Controls["tbQ"];
            tb.Scroll += new EventHandler(tb_RegionChanged);
            hist.chrHistogram.Show();
            cmbPrimary.SelectedItem = IndependentFieldNames[0];
            hist.Show();
        }
示例#2
0
        public void getGlmModel(string modelPath, bool BuildModel = false)
        {
            using (System.IO.StreamReader sr = new System.IO.StreamReader(modelPath))
            {
                string     mType = sr.ReadLine();
                modelTypes m     = (modelTypes)Enum.Parse(typeof(modelTypes), mType);
                if (m != modelTypes.GLM)
                {
                    System.Windows.Forms.MessageBox.Show("Model file specified is not a GLM!!", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    return;
                }
                InTablePath           = sr.ReadLine();
                IndependentFieldNames = sr.ReadLine().Split(new char[] { ',' });
                DependentFieldNames   = sr.ReadLine().Split(new char[] { ',' });
                ClassFieldNames       = sr.ReadLine().Split(new char[] { ',' });
                n                  = System.Convert.ToInt32(sr.ReadLine());
                nvars              = System.Convert.ToInt32(sr.ReadLine());
                iterations         = System.Convert.ToInt32(sr.ReadLine());
                delta              = System.Convert.ToDouble(sr.ReadLine());
                loglikelihood      = System.Convert.ToDouble(sr.ReadLine());
                loglikelihoodratio = System.Convert.ToDouble(sr.ReadLine());
                pv                 = System.Convert.ToDouble(sr.ReadLine());
                deviance           = System.Convert.ToDouble(sr.ReadLine());
                chisqr             = System.Convert.ToDouble(sr.ReadLine());
                linkfunction       = (LinkFunction)Enum.Parse(typeof(LinkFunction), sr.ReadLine());
                coefficients       = (from string s in (sr.ReadLine().Split(new char[] { ' ' })) select System.Convert.ToDouble(s)).ToArray();
                stdError           = (from string s in (sr.ReadLine().Split(new char[] { ' ' })) select System.Convert.ToDouble(s)).ToArray();
                waldTestValues     = (from string s in (sr.ReadLine().Split(new char[] { ' ' })) select System.Convert.ToDouble(s)).ToArray();
                waldTestPValues    = (from string s in (sr.ReadLine().Split(new char[] { ' ' })) select System.Convert.ToDouble(s)).ToArray();
                minValues          = (from string s in (sr.ReadLine().Split(new char[] { ' ' })) select System.Convert.ToDouble(s)).ToArray();
                maxValues          = (from string s in (sr.ReadLine().Split(new char[] { ' ' })) select System.Convert.ToDouble(s)).ToArray();
                sumValues          = (from string s in (sr.ReadLine().Split(new char[] { ' ' })) select System.Convert.ToDouble(s)).ToArray();
                sr.Close();
            }
            if (BuildModel)
            {
                Accord.Statistics.Links.ILinkFunction lFunc = new Accord.Statistics.Links.IdentityLinkFunction();
                switch (Link)
                {
                case LinkFunction.Absolute:
                    lFunc = new Accord.Statistics.Links.AbsoluteLinkFunction();
                    break;

                case LinkFunction.Cauchit:
                    lFunc = new Accord.Statistics.Links.CauchitLinkFunction();
                    break;

                case LinkFunction.Inverse:
                    lFunc = new Accord.Statistics.Links.InverseLinkFunction();
                    break;

                case LinkFunction.InverseSquared:
                    lFunc = new Accord.Statistics.Links.InverseSquaredLinkFunction();
                    break;

                case LinkFunction.Logit:
                    lFunc = new Accord.Statistics.Links.LogitLinkFunction();
                    break;

                case LinkFunction.Log:
                    lFunc = new Accord.Statistics.Links.LogLinkFunction();
                    break;

                case LinkFunction.LogLog:
                    lFunc = new Accord.Statistics.Links.LogLogLinkFunction();
                    break;

                case LinkFunction.Probit:
                    lFunc = new Accord.Statistics.Links.ProbitLinkFunction();
                    break;

                case LinkFunction.Sin:
                    lFunc = new Accord.Statistics.Links.SinLinkFunction();
                    break;

                case LinkFunction.Threshold:
                    lFunc = new Accord.Statistics.Links.ThresholdLinkFunction();
                    break;

                default:
                    break;
                }
                glm = new Accord.Statistics.Models.Regression.GeneralizedLinearRegression(lFunc, coefficients, stdError);
            }
        }
示例#3
0
        private void buildModel()
        {
            if (independentVls == null)
            {
                getMatrix();
            }
            Accord.Statistics.Links.ILinkFunction lFunc = new Accord.Statistics.Links.IdentityLinkFunction();
            switch (Link)
            {
            case LinkFunction.Absolute:
                lFunc = new Accord.Statistics.Links.AbsoluteLinkFunction();
                break;

            case LinkFunction.Cauchit:
                lFunc = new Accord.Statistics.Links.CauchitLinkFunction();
                break;

            case LinkFunction.Inverse:
                lFunc = new Accord.Statistics.Links.InverseLinkFunction();
                break;

            case LinkFunction.InverseSquared:
                lFunc = new Accord.Statistics.Links.InverseSquaredLinkFunction();
                break;

            case LinkFunction.Logit:
                lFunc = new Accord.Statistics.Links.LogitLinkFunction();
                break;

            case LinkFunction.Log:
                lFunc = new Accord.Statistics.Links.LogLinkFunction();
                break;

            case LinkFunction.LogLog:
                lFunc = new Accord.Statistics.Links.LogLogLinkFunction();
                break;

            case LinkFunction.Probit:
                lFunc = new Accord.Statistics.Links.ProbitLinkFunction();
                break;

            case LinkFunction.Sin:
                lFunc = new Accord.Statistics.Links.SinLinkFunction();
                break;

            case LinkFunction.Threshold:
                lFunc = new Accord.Statistics.Links.ThresholdLinkFunction();
                break;

            default:
                break;
            }
            glm = new Accord.Statistics.Models.Regression.GeneralizedLinearRegression(lFunc, NumberOfVariables);
            Accord.Statistics.Models.Regression.Fitting.IterativeReweightedLeastSquares isl = new Accord.Statistics.Models.Regression.Fitting.IterativeReweightedLeastSquares(glm);
            delta = 0;
            do
            {
                delta       = isl.Run(independentVls, dependentVls);
                iterations += 1;
            }while (delta > converge && iterations < totiterations);
            coefficients  = glm.Coefficients;
            stdError      = glm.StandardErrors;
            loglikelihood = glm.GetLogLikelihood(independentVls, dependentVls);
            if (Double.IsNaN(loglikelihood))
            {
                loglikelihood = 0;
            }
            loglikelihoodratio = glm.GetLogLikelihoodRatio(independentVls, dependentVls, glm);
            if (Double.IsNaN(loglikelihoodratio))
            {
                loglikelihoodratio = 0;
            }
            deviance = glm.GetDeviance(independentVls, dependentVls);
            if (Double.IsNaN(deviance))
            {
                deviance = 0;
            }
            Accord.Statistics.Testing.ChiSquareTest chiTest = glm.ChiSquare(independentVls, dependentVls);
            pv = chiTest.PValue;
            if (Double.IsNaN(pv))
            {
                pv = 0;
            }
            chisqr = chiTest.Statistic;
            if (double.IsNaN(chisqr))
            {
                chisqr = 0;
            }
            waldTestValues  = new double[IndependentFieldNames.Length];
            waldTestPValues = new double[waldTestValues.Length];
            for (int i = 0; i < waldTestValues.Length; i++)
            {
                Accord.Statistics.Testing.WaldTest wTest = glm.GetWaldTest(i);
                double wS = wTest.Statistic;
                double wP = wTest.PValue;
                //if (Double.IsNaN(wS)) wS = 0;
                //if (Double.IsNaN(wP)) wP = 0;
                waldTestValues[i]  = wS;
                waldTestPValues[i] = wP;
            }
            //if (stdError.Length != coefficients.Length) stdError = new double[coefficients.Length];
            //for (int i = 0; i < stdError.Length; i++)
            //{
            //    double vl = stdError[i];
            //    if (Double.IsNaN(vl)) stdError[i] = 0;
            //}
        }
 private void createRegChart()
 {
     if (glm == null)
     {
         Accord.Statistics.Links.ILinkFunction lFunc = new Accord.Statistics.Links.IdentityLinkFunction();
         switch (Link)
         {
             case LinkFunction.Absolute:
                 lFunc = new Accord.Statistics.Links.AbsoluteLinkFunction();
                 break;
             case LinkFunction.Cauchit:
                 lFunc = new Accord.Statistics.Links.CauchitLinkFunction();
                 break;
             case LinkFunction.Inverse:
                 lFunc = new Accord.Statistics.Links.InverseLinkFunction();
                 break;
             case LinkFunction.InverseSquared:
                 lFunc = new Accord.Statistics.Links.InverseSquaredLinkFunction();
                 break;
             case LinkFunction.Logit:
                 lFunc = new Accord.Statistics.Links.LogitLinkFunction();
                 break;
             case LinkFunction.Log:
                 lFunc = new Accord.Statistics.Links.LogLinkFunction();
                 break;
             case LinkFunction.LogLog:
                 lFunc = new Accord.Statistics.Links.LogLogLinkFunction();
                 break;
             case LinkFunction.Probit:
                 lFunc = new Accord.Statistics.Links.ProbitLinkFunction();
                 break;
             case LinkFunction.Sin:
                 lFunc = new Accord.Statistics.Links.SinLinkFunction();
                 break;
             case LinkFunction.Threshold:
                 lFunc = new Accord.Statistics.Links.ThresholdLinkFunction();
                 break;
             default:
                 break;
         }
         glm = new Accord.Statistics.Models.Regression.GeneralizedLinearRegression(lFunc, coefficients, stdError);
     }
     Forms.Stats.frmChart hist = (Forms.Stats.frmChart)ModelHelper.generateRegressionGraphic(IndependentFieldNames);
     System.Windows.Forms.ComboBox cmbPrimary = (System.Windows.Forms.ComboBox)hist.Controls["cmbPrimary"];
     cmbPrimary.SelectedValueChanged += new EventHandler(cmbPrimary_SelectedValueChanged);
     System.Windows.Forms.TrackBar tb = (System.Windows.Forms.TrackBar)hist.Controls["tbQ"];
     tb.Scroll += new EventHandler(tb_RegionChanged);
     hist.chrHistogram.Show();
     cmbPrimary.SelectedItem = IndependentFieldNames[0];
     hist.Show();
 }
 private void buildModel()
 {
     if (independentVls == null) getMatrix();
     Accord.Statistics.Links.ILinkFunction lFunc = new Accord.Statistics.Links.IdentityLinkFunction();
     switch (Link)
     {
         case LinkFunction.Absolute:
             lFunc = new Accord.Statistics.Links.AbsoluteLinkFunction();
             break;
         case LinkFunction.Cauchit:
             lFunc = new Accord.Statistics.Links.CauchitLinkFunction();
             break;
         case LinkFunction.Inverse:
             lFunc = new Accord.Statistics.Links.InverseLinkFunction();
             break;
         case LinkFunction.InverseSquared:
             lFunc = new Accord.Statistics.Links.InverseSquaredLinkFunction();
             break;
         case LinkFunction.Logit:
             lFunc = new Accord.Statistics.Links.LogitLinkFunction();
             break;
         case LinkFunction.Log:
             lFunc = new Accord.Statistics.Links.LogLinkFunction();
             break;
         case LinkFunction.LogLog:
             lFunc = new Accord.Statistics.Links.LogLogLinkFunction();
             break;
         case LinkFunction.Probit:
             lFunc = new Accord.Statistics.Links.ProbitLinkFunction();
             break;
         case LinkFunction.Sin:
             lFunc = new Accord.Statistics.Links.SinLinkFunction();
             break;
         case LinkFunction.Threshold:
             lFunc = new Accord.Statistics.Links.ThresholdLinkFunction();
             break;
         default:
             break;
     }
     glm = new Accord.Statistics.Models.Regression.GeneralizedLinearRegression(lFunc,NumberOfVariables);
     Accord.Statistics.Models.Regression.Fitting.IterativeReweightedLeastSquares isl = new Accord.Statistics.Models.Regression.Fitting.IterativeReweightedLeastSquares(glm);
     delta = 0;
     do
     {
         delta = isl.Run(independentVls,dependentVls);
         iterations += 1;
     }while (delta>converge&&iterations<totiterations);
     coefficients = glm.Coefficients;
     stdError = glm.StandardErrors;
     loglikelihood = glm.GetLogLikelihood(independentVls,dependentVls);
     if (Double.IsNaN(loglikelihood)) loglikelihood = 0;
     loglikelihoodratio = glm.GetLogLikelihoodRatio(independentVls, dependentVls, glm);
     if (Double.IsNaN(loglikelihoodratio)) loglikelihoodratio = 0;
     deviance = glm.GetDeviance(independentVls,dependentVls);
     if (Double.IsNaN(deviance)) deviance = 0;
     Accord.Statistics.Testing.ChiSquareTest chiTest = glm.ChiSquare(independentVls, dependentVls);
     pv = chiTest.PValue;
     if (Double.IsNaN(pv)) pv = 0;
     chisqr = chiTest.Statistic;
     if (double.IsNaN(chisqr)) chisqr = 0;
     waldTestValues = new double[IndependentFieldNames.Length];
     waldTestPValues = new double[waldTestValues.Length];
     for (int i = 0; i < waldTestValues.Length; i++)
     {
         Accord.Statistics.Testing.WaldTest wTest = glm.GetWaldTest(i);
         double wS = wTest.Statistic;
         double wP = wTest.PValue;
         //if (Double.IsNaN(wS)) wS = 0;
         //if (Double.IsNaN(wP)) wP = 0;
         waldTestValues[i] = wS;
         waldTestPValues[i] = wP;
     }
     //if (stdError.Length != coefficients.Length) stdError = new double[coefficients.Length];
     //for (int i = 0; i < stdError.Length; i++)
     //{
     //    double vl = stdError[i];
     //    if (Double.IsNaN(vl)) stdError[i] = 0;
     //}
 }
        public void getGlmModel(string modelPath, bool BuildModel=false)
        {
            using (System.IO.StreamReader sr = new System.IO.StreamReader(modelPath))
            {
                string mType = sr.ReadLine();
                modelTypes m = (modelTypes)Enum.Parse(typeof(modelTypes), mType);
                if (m != modelTypes.GLM)
                {
                    System.Windows.Forms.MessageBox.Show("Model file specified is not a GLM!!", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    return;
                }
                InTablePath = sr.ReadLine();
                IndependentFieldNames = sr.ReadLine().Split(new char[] { ',' });
                DependentFieldNames = sr.ReadLine().Split(new char[] { ',' });
                ClassFieldNames = sr.ReadLine().Split(new char[] { ',' });
                n = System.Convert.ToInt32(sr.ReadLine());
                nvars = System.Convert.ToInt32(sr.ReadLine());
                iterations = System.Convert.ToInt32(sr.ReadLine());
                delta = System.Convert.ToDouble(sr.ReadLine());
                loglikelihood=System.Convert.ToDouble(sr.ReadLine());
                loglikelihoodratio = System.Convert.ToDouble(sr.ReadLine());
                pv = System.Convert.ToDouble(sr.ReadLine());
                deviance = System.Convert.ToDouble(sr.ReadLine());
                chisqr = System.Convert.ToDouble(sr.ReadLine());
                linkfunction = (LinkFunction)Enum.Parse(typeof(LinkFunction), sr.ReadLine());
                coefficients = (from string s in (sr.ReadLine().Split(new char[]{' '})) select System.Convert.ToDouble(s)).ToArray();
                stdError = (from string s in (sr.ReadLine().Split(new char[] { ' ' })) select System.Convert.ToDouble(s)).ToArray();
                waldTestValues = (from string s in (sr.ReadLine().Split(new char[] { ' ' })) select System.Convert.ToDouble(s)).ToArray();
                waldTestPValues = (from string s in (sr.ReadLine().Split(new char[] { ' ' })) select System.Convert.ToDouble(s)).ToArray();
                minValues = (from string s in (sr.ReadLine().Split(new char[] { ' ' })) select System.Convert.ToDouble(s)).ToArray();
                maxValues = (from string s in (sr.ReadLine().Split(new char[] { ' ' })) select System.Convert.ToDouble(s)).ToArray();
                sumValues = (from string s in (sr.ReadLine().Split(new char[] { ' ' })) select System.Convert.ToDouble(s)).ToArray();
                sr.Close();

            }
            if (BuildModel)
            {
                Accord.Statistics.Links.ILinkFunction lFunc = new Accord.Statistics.Links.IdentityLinkFunction();
                switch (Link)
                {
                    case LinkFunction.Absolute:
                        lFunc = new Accord.Statistics.Links.AbsoluteLinkFunction();
                        break;
                    case LinkFunction.Cauchit:
                        lFunc = new Accord.Statistics.Links.CauchitLinkFunction();
                        break;
                    case LinkFunction.Inverse:
                        lFunc = new Accord.Statistics.Links.InverseLinkFunction();
                        break;
                    case LinkFunction.InverseSquared:
                        lFunc = new Accord.Statistics.Links.InverseSquaredLinkFunction();
                        break;
                    case LinkFunction.Logit:
                        lFunc = new Accord.Statistics.Links.LogitLinkFunction();
                        break;
                    case LinkFunction.Log:
                        lFunc = new Accord.Statistics.Links.LogLinkFunction();
                        break;
                    case LinkFunction.LogLog:
                        lFunc = new Accord.Statistics.Links.LogLogLinkFunction();
                        break;
                    case LinkFunction.Probit:
                        lFunc = new Accord.Statistics.Links.ProbitLinkFunction();
                        break;
                    case LinkFunction.Sin:
                        lFunc = new Accord.Statistics.Links.SinLinkFunction();
                        break;
                    case LinkFunction.Threshold:
                        lFunc = new Accord.Statistics.Links.ThresholdLinkFunction();
                        break;
                    default:
                        break;
                }
                glm = new Accord.Statistics.Models.Regression.GeneralizedLinearRegression(lFunc, coefficients, stdError);
            }
        }