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

Class BigExample

src/com/winvector/logistic/demo/BigExample.java:10–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import java.util.Random;
9
10public class BigExample {
11 public static void main(String[] args) throws IOException {
12 final File outFile = new File(args[0]);
13 final Random rand = new Random(52325);
14 final int kVars = 10;
15 final int nLevels = 10;
16 final int nRows = 1000000;
17
18 System.out.println("writing:\t" + outFile.getAbsolutePath() + "\t" + new Date());
19
20 final double dcTerm = rand.nextDouble();
21 final double[][] levelValues = new double[kVars][nLevels];
22 for(int vi=0;vi<kVars;++vi) {
23 for(int li=0;li<nLevels;++li) {
24 levelValues[vi][li] = rand.nextGaussian();
25 }
26 }
27 final PrintStream p = new PrintStream(new FileOutputStream(outFile));
28 p.print("Result");
29 for(int vi=0;vi<kVars;++vi) {
30 p.print("\tV" + vi);
31 }
32 p.println();
33 int nCorrect = 0;
34 for(int row=0;row<nRows;++row) {
35 int[] choices = new int[kVars];
36 double tot = dcTerm;
37 for(int vi=0;vi<kVars;++vi) {
38 choices[vi] = rand.nextInt(nLevels);
39 tot += levelValues[vi][choices[vi]];
40 }
41 final boolean calc = tot>0.0;
42 tot += rand.nextDouble(); // noise term
43 final boolean pos = tot>0.0;
44 if(calc==pos) {
45 ++nCorrect;
46 }
47 p.print(pos?"1":"0");
48 for(int vi=0;vi<kVars;++vi) {
49 p.print("\tV" + vi + "L" + choices[vi]);
50 }
51 p.println();
52 }
53 p.close();
54 System.out.println("\ttarget accuracy: " + nCorrect + "/" + nRows + " = " + (nCorrect/(double)nRows));
55 }
56}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected