| 13 | |
| 14 | |
| 15 | public class TestLogM extends TestCase { |
| 16 | public void testMH() { |
| 17 | final double[][] dat = { |
| 18 | /// x1 x2 y |
| 19 | { 1, 0, 1 }, |
| 20 | { 1, 1, 1 }, |
| 21 | { 0, 1, 0 } |
| 22 | }; |
| 23 | final RExample ex = new RExample(dat); |
| 24 | final VectorFn sl = new DataFn<ExampleRow>(new SigmoidLossMultinomial(ex.dim,2),ex); |
| 25 | final double[] x0 = new double[sl.dim()]; |
| 26 | for(int i=0;i<sl.dim();++i) { |
| 27 | x0[i] = i+1; |
| 28 | } |
| 29 | TestOpt.testGradAndHessian(sl,x0,1.0e-5,1.0e-2); // very sensitive to epsilon |
| 30 | } |
| 31 | |
| 32 | public void testMHR() { |
| 33 | final double[][] dat = { |
| 34 | /// x1 x2 y |
| 35 | { 1, 0, 1 }, |
| 36 | { 1, 1, 1 }, |
| 37 | { 0, 1, 0 } |
| 38 | }; |
| 39 | final RExample ex = new RExample(dat); |
| 40 | final VectorFn sl = NormPenalty.addPenalty(new DataFn<ExampleRow>(new SigmoidLossMultinomial(ex.dim,2),ex),0.1,null); |
| 41 | final double[] x0 = new double[sl.dim()]; |
| 42 | for(int i=0;i<sl.dim();++i) { |
| 43 | x0[i] = i+1; |
| 44 | } |
| 45 | TestOpt.testGradAndHessian(sl,x0,1.0e-5,1.0e-2); // very sensitive to epsilon |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * chosen to run to infinity |
| 50 | * |
| 51 | * > dat <- read.table('exB.txt',header=T,sep='\t') |
| 52 | * > model <- glm(y~x1+x2,family=binomial(link='logit'),data=dat) |
| 53 | * > predict(model,type='response') |
| 54 | * |
| 55 | * R soln: 23.56607 23.56607 -23.56607 |
| 56 | * |
| 57 | * reg(0.1) soln: x(0.1): 1 x 3 matrix -0.337079 2.215088 -0.642055 |
| 58 | * |
| 59 | * |
| 60 | */ |
| 61 | public void testB() { |
| 62 | final double[][] dat = { |
| 63 | /// x1 x2 y |
| 64 | { 1, 0, 1 }, |
| 65 | { 1, 1, 1 }, |
| 66 | { 0, 1, 0 } |
| 67 | }; |
| 68 | final RExample ex = new RExample(dat); |
| 69 | final Newton nwt = new Newton(); |
| 70 | final double reg = 0.1; |
| 71 | final SigmoidLossMultinomial sigmoidLoss = new SigmoidLossMultinomial(ex.dim,2); |
| 72 | final VectorFn sl = NormPenalty.addPenalty(new DataFn<ExampleRow>(new SigmoidLossMultinomial(ex.dim,2),ex),reg,null); |
nothing calls this directly
no outgoing calls
no test coverage detected