public void TestLogLogLogisticFeaturedLL() { DataGen dg = new DataGen(); dg.GenTrivFeaturesData(); double shapeMax = 5.0; double scaleMax = 900.0; LogLogistic modelLogLogisticFeatured = new LogLogistic(dg.organicRecoveryDurations, dg.inorganicRecoverydurations, dg.fSamples, dg.fCensored); modelLogLogisticFeatured.ShapeUpperBound = shapeMax; modelLogLogisticFeatured.ScaleUpperBound = scaleMax; double[,] warr = new double[2, 2] { { 1, 1 }, { 1, 1 } }; Matrix <double> w = Matrix <double> .Build.DenseOfArray(warr); var loglik = modelLogLogisticFeatured.LogLikelihood(w, dg.fSamples, dg.fCensored); System.Console.WriteLine("LogLikelihood is: " + loglik.ToString()); Assert.IsTrue(Math.Abs(loglik + 55.83229) < 1e-3); }
public void TestLogLogisticFeaturedGrad() { DataGen dg = new DataGen(); dg.GenTrivFeaturesData(); double shapeMax = 5.0; double scaleMax = 900.0; LogLogistic modelLogLogisticFeatured = new LogLogistic(dg.organicRecoveryDurations, dg.inorganicRecoverydurations, dg.fSamples, dg.fCensored); modelLogLogisticFeatured.ShapeUpperBound = shapeMax; modelLogLogisticFeatured.ScaleUpperBound = scaleMax; double[,] warr = new double[2, 2] { { 1, 1 }, { 1, 1 } }; Matrix <double> w = Matrix <double> .Build.DenseOfArray(warr); var grd = modelLogLogisticFeatured.GradLL2(w, dg.fSamples, dg.fCensored); var grd_numr = modelLogLogisticFeatured.NumericalGradLL(w); System.Console.WriteLine("Gradient first component:" + grd[0, 0].ToString()); Assert.IsTrue(Math.Abs(grd[0, 0] - grd_numr[0, 0]) < 1e-3); }