random data > dat <- read.table('exdat.txt',header=T,sep='\t') > model <- glm(y~x1+x2+x3,family=binomial(link='logit'),data=dat) > predict(model,type='response')
()
| 75 | * > predict(model,type='response') |
| 76 | */ |
| 77 | public void test1() { |
| 78 | final double[][] dat = { |
| 79 | /// x1 x2 x3 y |
| 80 | { -0.44976435, -0.78296280, -0.48688853, 0 }, |
| 81 | { -1.03426815, 0.04612169, 1.47089045, 0 }, |
| 82 | { -0.43384390, 0.42899808, -0.26193149, 0 }, |
| 83 | { -0.95033489, -0.27426514, 0.68173371, 1 }, |
| 84 | { 0.27908890, -0.32059753, -0.70644535, 0 }, |
| 85 | { 1.00157159, 0.79282132, -0.37996207, 0 }, |
| 86 | { 0.95845408, -2.53278930, 1.17061997, 1 }, |
| 87 | { -0.49769246, -1.40173370, 0.85298792, 1 }, |
| 88 | { 0.49837975, 0.09472328, 0.55434520, 1 }, |
| 89 | { -0.95468277, 1.20501514, -0.36059224, 0 }, |
| 90 | { -0.54413233, 1.22795085, 0.40355037, 0 }, |
| 91 | { 0.06684785, -0.90056936, 0.26543402, 1 }, |
| 92 | { 0.85603550, 0.21198687, -2.61638078, 0 }, |
| 93 | { 1.26778309, 1.46421442, -0.41545011, 0 }, |
| 94 | { -0.08671788, -0.71608390, -1.35539576, 0 }, |
| 95 | { -0.89845231, 0.53988648, -1.44072650, 0 }, |
| 96 | { -0.04908144, -2.34300762, -0.04386654, 1 }, |
| 97 | { 0.61978004, 0.38270863, -0.08020138, 1 }, |
| 98 | { 0.55258524, 2.06820588, 0.54660427, 0 }, |
| 99 | { -0.16982628, -0.51338245, 1.28251022, 1 }, |
| 100 | }; |
| 101 | final RExample ex = new RExample(dat); |
| 102 | final Newton nwt = new Newton(); |
| 103 | final double[] rsoln = {-0.8438, 5.1539, -5.0729, 4.6308 }; // glm(y~x1+x2+x3,family=binomial(link='logit'),data=dat) |
| 104 | for(final double reg: new double[] { 0.0, 1.0e-3, 1.0e-2, 0.1, 1.0 }) { |
| 105 | final SigmoidLossMultinomial sigmoidLoss = new SigmoidLossMultinomial(ex.dim,2); |
| 106 | final VectorFn sl = NormPenalty.addPenalty(new DataFn<ExampleRow>(new SigmoidLossMultinomial(ex.dim,2),ex),reg,null); |
| 107 | final double[] x0 = new double[sl.dim()]; |
| 108 | //System.out.println("start: " + x0); |
| 109 | final VEval opt = nwt.maximize(sl,x0,10); |
| 110 | //System.out.println(opt); |
| 111 | //for(final ExampleRow ei: ex) { |
| 112 | // double pred = SigmoidLoss.px(opt.x,ei.x); |
| 113 | // System.out.println(ei + " -> " + pred); |
| 114 | //} |
| 115 | final double accuracy = HelperFns.accuracy(sigmoidLoss,ex,opt.x); |
| 116 | //System.out.println("accuracy(" + pass + "): " + accuracy); |
| 117 | if(reg<=0.0) { |
| 118 | for(int i=0;i<rsoln.length;++i) { |
| 119 | final double javaSoln = -opt.x[i] + opt.x[i+rsoln.length]; |
| 120 | assertTrue(Math.abs(rsoln[i]-javaSoln)<1.0e-1); |
| 121 | } |
| 122 | } |
| 123 | //System.out.println("done: " + opt.x); |
| 124 | //System.out.println("x(" + reg + "," + accuracy + "): " + opt.x); |
| 125 | assertTrue(accuracy>=0.85); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * chosen to run to infinity |
nothing calls this directly
no test coverage detected