@Override public void step(int i) { Sample sample = dataSet.get(i); compress(sample); } };
@Override public void step(int i) { Sample sample = dataSet.get(i); hash(sample); } };
@Override public void step(int i) { Sample sample = dataSet.get(i); predictOne(sample); } };
public Object getValueAt(int rowIndex, int columnIndex) { Sample s = iSamples.get(rowIndex); if (s == null) { return null; } for (String key : s.keySet()) { if (keys.add(key)) { columnMap.put(columnMap.size(), key); fireTableStructureChanged(); } } return s; }
public int getClassCount(ListDataSet dataSet) { return (int) dataSet.get(0).getAsMatrix(getTargetLabel()).toRowVector(Ret.NEW) .getRowCount(); }
public ListDataSet calculate(ListDataSet dataSet) throws Exception { product1ToIds.setLabel("Product 1 Ids"); product2ToIds.setLabel("Product 2 Ids"); Matrix product1Count = new CountMatrix(product1ToIds); product1Count.setLabel("Product 1 Count"); Matrix product2Count = new CountMatrix(product2ToIds); product2Count.setLabel("Product 2 Count"); for (int r = 0; r < dataSet.size(); r++) { if (r % 1000 == 0) { System.out.println(r + " of " + dataSet.size()); } RelationalSample s = (RelationalSample) dataSet.get(r); Collection<?> products = s.getObjects(); if (products.size() != 0) { addProduct1Count(products, r); addProduct2Count(products, r); } } return calculateP(minSupport); }
public void trainAll(ListDataSet dataSet) { System.out.println("training started"); int featureCount = (int) dataSet.get(0).getAsMatrix(getInputLabel()).getValueCount(); boolean discrete = isDiscrete(dataSet); classCount = getClassCount(dataSet);
Sample s = dataSet.get(randomIndex); inputs.add(s.getAsMatrix(Sample.INPUT).toColumnVector(Ret.NEW)); targets.add(s.getAsMatrix(Sample.TARGET).toColumnVector(Ret.NEW));
private Matrix createCompleteMatrix(ListDataSet dataSet) { final int sampleCount = dataSet.size(); final int featureCount = getFeatureCount(dataSet); final int targetCount = getClassCount(dataSet); Matrix m = Matrix.Factory.zeros(sampleCount, featureCount + targetCount); for (int r = 0; r < sampleCount; r++) { Sample s = dataSet.get(r); Matrix input = s.getAsMatrix(getInputLabel()).toColumnVector(Ret.NEW); Matrix target = s.getAsMatrix(getTargetLabel()).toColumnVector(Ret.NEW); for (int c = 0; c < featureCount; c++) { m.setAsDouble(input.getAsDouble(0, c), r, c); } for (int c = 0; c < targetCount; c++) { m.setAsDouble(target.getAsDouble(0, c), r, c + featureCount); } } return m; }
@Test public void testHenon() throws Exception { Result r = execute("henon(100,10,5)"); Object o = r.getObject(); assertTrue(o instanceof ListDataSet); ListDataSet ds = (ListDataSet) o; assertEquals(100, ds.size()); Sample s = ds.get(0); long input = s.getAsMatrix(Sample.INPUT).getColumnCount(); long target = s.getAsMatrix(Sample.TARGET).getColumnCount(); assertEquals(10, input); assertEquals(5, target); }
if (dataSet.get(0).getAsMatrix(getTargetLabel()) != null) { final Matrix confusion; double error = 0.0;
@Test public void testTagger() throws Exception { if (tagger == null) { return; } ListDataSet ds = new DefaultListDataSet(); Sample sa1 = new DefaultSample(); sa1.put(Sample.INPUT, s1); Sample sa2 = new DefaultSample(); sa2.put(Sample.INPUT, s2); ds.add(sa1); ds.add(sa2); tokenizer.tokenize(Sample.INPUT, ds); tagger.tag(ds); sa1 = ds.get(0); sa2 = ds.get(1); Matrix m1 = sa1.getAsMatrix(Tagger.TAGGED); Matrix m2 = sa2.getAsMatrix(Tagger.TAGGED); assertEquals(2, m1.getColumnCount()); assertEquals(11, m1.getRowCount()); assertEquals(2, m2.getColumnCount()); assertEquals(5, m2.getRowCount()); } }
@Test public void testTokenizer() throws Exception { ListDataSet ds = new DefaultListDataSet(); Sample sa1 = new DefaultSample(); sa1.put(Sample.INPUT, s1); sa1.setId("sample1"); Sample sa2 = new DefaultSample(); sa2.put(Sample.INPUT, s2); sa2.setId("sample2"); ds.add(sa1); ds.add(sa2); Tokenizer t = new StanfordTokenizer(); t.tokenize(Sample.INPUT, ds); sa1 = ds.get(0); sa2 = ds.get(1); Matrix m1 = sa1.getAsMatrix(Tokenizer.TOKENIZED); Matrix m2 = sa2.getAsMatrix(Tokenizer.TOKENIZED); assertEquals(1, m1.getColumnCount()); assertEquals(11, m1.getRowCount()); assertEquals(1, m2.getColumnCount()); assertEquals(5, m2.getRowCount()); } }