Example #1
0
        public void GenLogLogisticWFeatures()
        {
            LogLogistic   ll        = new LogLogistic(1.2, 300.0);
            List <double> llSamples = ll.GenerateSample(2000);

            var censorLvl = llSamples.Sum() / llSamples.Count();
            var t         = CensorList(llSamples, censorLvl);

            int n_x = llSamples.Count(ti => ti > censorLvl);

            var x = NPOnes(n_x, censorLvl);

            List <double[]> fSamplesData  = new List <double[]>();
            List <double[]> fCensoredData = new List <double[]>();

            for (int i = 0; i < t.Count(); i++)
            {
                fSamplesData.Add(new double[] { 1.0, 2.0, 3.0 });
            }

            for (int i = 0; i < x.Count(); i++)
            {
                fCensoredData.Add(new double[] { 1.0, 2.0, 3.0 });
            }

            ll        = new LogLogistic(0.7, 80.0);
            llSamples = ll.GenerateSample(2000);

            censorLvl = llSamples.Sum() / llSamples.Count();
            var t1 = CensorList(llSamples, censorLvl);

            AppendToLst(t, t1);

            n_x = llSamples.Count(ti => ti > censorLvl);
            var x1 = NPOnes(n_x, censorLvl);

            AppendToLst(x, x1);

            for (int i = 0; i < t1.Count(); i++)
            {
                fSamplesData.Add(new double[] { 1.0, 4.0, 2.0 });
            }

            for (int i = 0; i < x1.Count(); i++)
            {
                fCensoredData.Add(new double[] { 1.0, 4.0, 2.0 });
            }

            this.organicRecoveryDurations   = t;
            this.inorganicRecoverydurations = x;

            Matrix <double> fSamples = Matrix <double> .Build.DenseOfArray(CreateRectangularArray(fSamplesData));

            Matrix <double> fCensored = Matrix <double> .Build.DenseOfArray(CreateRectangularArray(fCensoredData));

            this.fSamples  = fSamples;
            this.fCensored = fCensored;
        }
Example #2
0
        public void TestMixedLogLogisticFitting()
        {
            LogLogistic   lg         = new LogLogistic(1.2, 300.0);
            List <double> llSamples  = lg.GenerateSample(5000);
            LogLogistic   lg1        = new LogLogistic(0.7, 80.0);
            List <double> llSamples1 = lg1.GenerateSample(5000);

            DataGen.AppendToLst(llSamples, llSamples1);
            var           ti = llSamples;
            List <double> xi = new List <double> {
                .1
            };
            LogLogistic llModel = new LogLogistic(ti, xi);

            double[]        arr  = new double[] { 0.8, 150.0 };
            Vector <double> init = Vector <double> .Build.DenseOfArray(arr);

            llModel.GradientDescent(init);
            Debug.WriteLine("Model completed!");
            Assert.IsTrue(Math.Abs(llModel.Kappa - 0.83) < 1e-1);
        }
Example #3
0
        public void TestLogLogisticFitting()
        {
            LogLogistic lg         = new LogLogistic(1.2, 300);
            var         lgSamples  = lg.GenerateSample(3000);
            var         lgCensored = new List <double> {
                0.1, 0.1
            };

            double[]        arr  = new double[] { 0.5, 12.0 };
            Vector <double> init = Vector <double> .Build.DenseOfArray(arr);

            LogLogistic lg2 = new LogLogistic(lgSamples, lgCensored);

            lg2.GradientDescent(init);

            Console.WriteLine(lg2.Kappa);

            //The un-biased estimator of the LogLogistic distribution
            //has a high variance. So, we have to set the bar low.
            Assert.IsTrue(Math.Abs(lg2.Kappa - 1.2) < 1e-1);
        }