Beispiel #1
0
        public void TestLogLogisticWFeatures()
        {
            DataGen dg = new DataGen();

            dg.GenLogLogisticWFeatures();

            double shapeMax = 5.0;
            double scaleMax = 500.0;

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

            LogLogistic modelLogLogistic = new LogLogistic(dg.organicRecoveryDurations,
                                                           dg.inorganicRecoverydurations);

            modelLogLogistic.GradientDescent(init);

            Console.WriteLine("LL without features is " +
                              modelLogLogistic.LogLikelihood(modelLogLogistic.Kappa, modelLogLogistic.Lambda) +
                              " with Kappa " + modelLogLogistic.Kappa + " and Lambda " + modelLogLogistic.Lambda);

            double[,] warr = new double[2, dg.fCensored.ColumnCount];
            warr[0, 0]     = Sigmoid.InverseSigmoid(modelLogLogistic.Kappa, shapeMax);
            warr[1, 0]     = Sigmoid.InverseSigmoid(modelLogLogistic.Lambda, scaleMax);
            Matrix <double> w = Matrix <double> .Build.DenseOfArray(warr);

            LogLogistic modelLogLogisticFeatured = new LogLogistic(dg.organicRecoveryDurations,
                                                                   dg.inorganicRecoverydurations,
                                                                   dg.fSamples, dg.fCensored);

            modelLogLogisticFeatured.ShapeUpperBound = shapeMax;
            modelLogLogisticFeatured.ScaleUpperBound = scaleMax;
            Matrix <double> logLogisticParameters = modelLogLogisticFeatured.GradientDescent(w, 2001);
            Vector <double> frstSample            = Vector <double> .Build.DenseOfArray(
                new double[] { 1.0, 2.0, 3.0 });

            Vector <double> scndSample = Vector <double> .Build.DenseOfArray(
                new double[] { 1.0, 4.0, 2.0 });

            Vector <double> res         = logLogisticParameters.Multiply(frstSample);
            var             alpha_shape = res[0];
            var             shape       = Sigmoid.Transform(alpha_shape, shapeMax);
            var             alpha_scale = res[1];
            var             scale       = Sigmoid.Transform(alpha_scale, scaleMax);

            res         = logLogisticParameters.Multiply(scndSample);
            alpha_shape = res[0];
            shape       = Sigmoid.Transform(alpha_shape, shapeMax);
            alpha_scale = res[1];
            scale       = Sigmoid.Transform(alpha_scale, scaleMax);
            Assert.IsTrue(Math.Abs(scale - 80.0) < 2.0);
        }