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

Class RExample

test/com/winvector/logistic/RExample.java:10–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import com.winvector.opt.impl.SparseSemiVec;
9
10public class RExample implements Iterable<ExampleRow> {
11 private final double[][] rawdat;
12 public final int dim;
13
14 public RExample(final double[][] rawdat) {
15 this.rawdat = rawdat;
16 dim = rawdat[0].length;
17 }
18
19 private class SI implements Iterator<ExampleRow> {
20 private int i = 0;
21 private ExampleRow next = null;
22
23 public SI() {
24 advance();
25 }
26
27 private void advance() {
28 next = null;
29 while((next==null)&&(i<rawdat.length)) {
30 final int category = rawdat[i][dim-1]>0.5?1:0;
31 final double[] vec = new double[dim];
32 vec[0] = 1.0;
33 for(int j=0;j<dim-1;++j) {
34 if(rawdat[i][j]!=0.0) {
35 vec[j+1] = rawdat[i][j];
36 }
37 }
38 next = new SparseExampleRow(new SparseSemiVec(vec),1.0,category);
39 ++i;
40 }
41 }
42
43 @Override
44 public boolean hasNext() {
45 return next!=null;
46 }
47
48 @Override
49 public ExampleRow next() {
50 if(!hasNext()) {
51 throw new NoSuchElementException();
52 }
53 final ExampleRow ret = next;
54 advance();
55 return ret;
56 }
57
58 @Override
59 public void remove() {
60 throw new UnsupportedOperationException();
61 }
62 }
63
64
65 @Override
66 public Iterator<ExampleRow> iterator() {
67 return new SI();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected