public void hash(final ListDataSet dataSet) { new PFor(0, dataSet.size() - 1) { @Override public void step(int i) { Sample sample = dataSet.get(i); hash(sample); } }; }
public void compress(final ListDataSet dataSet) { new PFor(0, dataSet.size() - 1) { @Override public void step(int i) { Sample sample = dataSet.get(i); compress(sample); } }; }
public int getRowCount() { return iSamples.size(); }
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); }
createAlgorithm(); prob = new Problem(); prob.l = dataSet.size(); prob.n = getFeatureCount(dataSet); prob.x = new Feature[prob.l][]; if (System.currentTimeMillis() - time > 5000) { time = System.currentTimeMillis(); System.out.println("Converting samples: " + Math.round(((double) i / dataSet.size() * 100)) + "% done");
prob.l = dataSet.size();
public DataSetToInstancesWrapper(ListDataSet dataSet, boolean discrete, boolean includeTarget) { super(dataSet.getLabel(), new DataSetToAttributeInfoWrapper(dataSet, discrete), dataSet .size()); if (includeTarget) { setClassIndex(dataSet.getFeatureCount()); } for (Sample s : dataSet) { Matrix input = s.getAsMatrix(INPUT); Matrix weight = s.getAsMatrix(WEIGHT); Matrix target = s.getAsMatrix(TARGET); add(new SampleToInstanceWrapper(input, weight, target, discrete, includeTarget)); } }
@Test public void testIris() throws Exception { Result r = execute("iris"); Object o = r.getObject(); assertTrue(o instanceof ListDataSet); ListDataSet ds = (ListDataSet) o; assertEquals(150, ds.size()); }
public void trainAll(ListDataSet dataSet) { featureCount = getFeatureCount(dataSet); classCount = getClassCount(dataSet); dimensions = featureCount + classCount; Matrix x = Matrix.Factory.zeros(dataSet.size(), dimensions); int i = 0; for (Sample s : dataSet) { Matrix input = s.getAsMatrix(getInputLabel()).toColumnVector(Ret.LINK); for (int c = 0; c < featureCount; c++) { x.setAsDouble(input.getAsDouble(0, c), i, c); } Matrix target = s.getAsMatrix(getTargetLabel()).toColumnVector(Ret.LINK); for (int c = 0; c < classCount; c++) { x.setAsDouble(target.getAsDouble(0, c), i, c + featureCount); } i++; } meanMatrix = x.mean(Ret.NEW, Matrix.ROW, true); covarianceMatrix = x.cov(Ret.NEW, true, true); try { inverse = covarianceMatrix.inv(); factor = 1.0 / Math.sqrt(covarianceMatrix.det() * Math.pow(2.0 * Math.PI, dimensions)); } catch (Exception e) { inverse = covarianceMatrix.pinv(); factor = 1.0; } }
@Test public void testExampleSearch() throws Exception { ListDataSet ds = ListDataSet.Factory.IRIS(); LuceneIndex index = new LuceneIndex(); index.add(ds); ListDataSet result = index.search("setosa"); assertEquals(50, result.size()); index.close(); }
public void train(ListDataSet dataSet) { System.out.println("training started"); Matrix x = Matrix.Factory.zeros(dataSet.size(), getFeatureCount(dataSet));
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; }
public void predictAll(final ListDataSet dataSet) { new PFor(0, dataSet.size() - 1) { Matrix rmse = Matrix.Factory.linkToValue(Math.sqrt(error / dataSet.size())); rmse.setLabel("RMSE with " + getLabel()); dataSet.setMatrix(Variable.RMSE, rmse); / (double) dataSet.size()); accuracy.setLabel("Accuracy with " + getLabel()); dataSet.setMatrix(Variable.ACCURACY, accuracy);
@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); }