MCPcopy Create free account
hub / github.com/WinVector/Logistic / TestLRPathPlus

Class TestLRPathPlus

test/com/winvector/logistic/TestLRPathPlus.java:51–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50
51public class TestLRPathPlus {
52
53 public static void copyResourceToFile(final String resourceName, final File dest) throws IOException {
54 final InputStream is = TestRoundTrip.class.getClassLoader().getResourceAsStream(resourceName);
55 final FileOutputStream os = new FileOutputStream(dest);
56 int c = -1;
57 while((c=is.read())>=0) {
58 os.write(c);
59 }
60 os.close();
61 is.close();
62 }
63
64 public static ArrayList<BurstMap> readBurstFromResource(final String resourceName) throws IOException {
65 final ArrayList<BurstMap> r = new ArrayList<BurstMap>();
66 final InputStream is = TestRoundTrip.class.getClassLoader().getResourceAsStream(resourceName);
67 final Iterator<BurstMap> it = new TrivialIterator(new LineNumberReader(new InputStreamReader(is)),Pattern.compile("\t"),false,true,"res:"+resourceName);
68 while(it.hasNext()) {
69 final BurstMap row = it.next();
70 r.add(row);
71 }
72 return r;
73 }
74
75 private double relDiff(double a, double b) {
76 final double diff = Math.abs(a-b);
77 if(diff<=0.0) {
78 return 0.0;
79 } else {
80 return 2.0*diff/(Math.abs(a)+Math.abs(b));
81 }
82 }
83
84 /**
85 * essentially the same loop structure as VariableEncodings.formatSoln. So double calculating here confirms
86 * the results are coming out correctly.
87 * @param trainSource
88 * @param adapter
89 * @param sigmoidLoss
90 * @param x
91 */
92 private void confirmEffectCalc(final Iterable<BurstMap> trainSource, final VariableEncodings adapter,
93 final DModel<ExampleRow> sigmoidLoss, final double[] x) {
94 // confirm effects work like we think
95 for(final BurstMap row: trainSource) {
96 // score the standard way
97 final SparseSemiVec vec = adapter.vector(row);
98 if(null!=vec) {
99 //final String resStr = row.getAsString(adapter.def().resultColumn);
100 //final int category = adapter.category(resStr);
101 final Datum ei = new SparseExampleRow(vec,1.0,-1);
102 final double[] pred = sigmoidLoss.predict(x,ei);
103 // score via effects
104 final double[] predE = new double[adapter.outcomeCategories.entrySet().size()];
105 for(final Map.Entry<String,Integer> mc: adapter.outcomeCategories.entrySet()) {
106 //final String outcome = mc.getKey();
107 final int cati = mc.getValue();
108 final int base = cati*adapter.vdim;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected