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

Class TestLRPath

test/com/winvector/logistic/TestLRPath.java:46–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected