| 11 | import com.winvector.opt.impl.NormPenalty; |
| 12 | |
| 13 | public class TestLog1 extends TestCase { |
| 14 | |
| 15 | |
| 16 | public void testGH() { |
| 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 | TestOpt.testGradAndHessian(sl,x0,1.0e-5,1.0e-4); // very sensitive to epsilon |
| 27 | } |
| 28 | |
| 29 | public void testGHR() { |
| 30 | final double[][] dat = { |
| 31 | /// x1 x2 y |
| 32 | { 1, 0, 1 }, |
| 33 | { 1, 1, 1 }, |
| 34 | { 0, 1, 0 } |
| 35 | }; |
| 36 | final RExample ex = new RExample(dat); |
| 37 | final VectorFn sl = NormPenalty.addPenalty(new DataFn<ExampleRow>(new SigmoidLossMultinomial(ex.dim,2),ex),0.1,null); |
| 38 | final double[] x0 = new double[sl.dim()]; |
| 39 | TestOpt.testGradAndHessian(sl,x0,1.0e-5,1.0e-4); // very sensitive to epsilon |
| 40 | } |
| 41 | |
| 42 | public void testGH2() { |
| 43 | final double[][] dat = { |
| 44 | /// x1 x2 y |
| 45 | { 1, 0, 1 }, |
| 46 | { 1, 1, 1 }, |
| 47 | { 0, 1, 0 } |
| 48 | }; |
| 49 | final RExample ex = new RExample(dat); |
| 50 | final VectorFn sl = new DataFn<ExampleRow>(new SigmoidLossMultinomial(ex.dim,2),ex); |
| 51 | final double[] x0 = new double[sl.dim()]; |
| 52 | x0[1] = 1.0; |
| 53 | TestOpt.testGradAndHessian(sl,x0,1.0e-5,1.0e-4); // very sensitive to epsilon |
| 54 | } |
| 55 | |
| 56 | public void testGHR2() { |
| 57 | final double[][] dat = { |
| 58 | /// x1 x2 y |
| 59 | { 1, 0, 1 }, |
| 60 | { 1, 1, 1 }, |
| 61 | { 0, 1, 0 } |
| 62 | }; |
| 63 | final RExample ex = new RExample(dat); |
| 64 | final VectorFn sl = NormPenalty.addPenalty(new DataFn<ExampleRow>(new SigmoidLossMultinomial(ex.dim,2),ex),0.1,null); |
| 65 | final double[] x0 = new double[sl.dim()]; |
| 66 | x0[1] = 1.0; |
| 67 | TestOpt.testGradAndHessian(sl,x0,1.0e-5,1.0e-4); // very sensitive to epsilon |
| 68 | } |
| 69 | |
| 70 | /** |
nothing calls this directly
no outgoing calls
no test coverage detected