Search in sources :

Example 6 with Chunk

use of water.fvec.Chunk in project h2o-3 by h2oai.

the class KMeansModel method predictScoreImpl.

@Override
protected Frame predictScoreImpl(Frame orig, Frame adaptedFr, String destination_key, final Job j, boolean computeMetrics) {
    if (!_parms._pred_indicator) {
        return super.predictScoreImpl(orig, adaptedFr, destination_key, j, computeMetrics);
    } else {
        final int len = _output._k[_output._k.length - 1];
        String prefix = "cluster_";
        Frame adaptFrm = new Frame(adaptedFr);
        for (int c = 0; c < len; c++) adaptFrm.add(prefix + Double.toString(c + 1), adaptFrm.anyVec().makeZero());
        new MRTask() {

            @Override
            public void map(Chunk[] chks) {
                if (isCancelled() || j != null && j.stop_requested())
                    return;
                double[] tmp = new double[_output._names.length];
                double[] preds = new double[len];
                for (int row = 0; row < chks[0]._len; row++) {
                    Arrays.fill(preds, 0);
                    double[] p = score_indicator(chks, row, tmp, preds);
                    for (int c = 0; c < preds.length; c++) chks[_output._names.length + c].set(row, p[c]);
                }
                if (j != null)
                    j.update(1);
            }
        }.doAll(adaptFrm);
        // Return the predicted columns
        int x = _output._names.length, y = adaptFrm.numCols();
        // this will call vec_impl() and we cannot call the delete() below just yet
        Frame f = adaptFrm.extractFrame(x, y);
        f = new Frame(Key.<Frame>make(destination_key), f.names(), f.vecs());
        DKV.put(f);
        makeMetricBuilder(null).makeModelMetrics(this, orig, null, null);
        return f;
    }
}
Also used : Frame(water.fvec.Frame) MRTask(water.MRTask) Chunk(water.fvec.Chunk)

Example 7 with Chunk

use of water.fvec.Chunk in project h2o-3 by h2oai.

the class PCAModel method predictScoreImpl.

@Override
protected Frame predictScoreImpl(Frame orig, Frame adaptedFr, String destination_key, final Job j, boolean computeMetrics) {
    Frame adaptFrm = new Frame(adaptedFr);
    for (int i = 0; i < _parms._k; i++) adaptFrm.add("PC" + String.valueOf(i + 1), adaptFrm.anyVec().makeZero());
    new MRTask() {

        @Override
        public void map(Chunk[] chks) {
            if (isCancelled() || j != null && j.stop_requested())
                return;
            double[] tmp = new double[_output._names.length];
            double[] preds = new double[_parms._k];
            for (int row = 0; row < chks[0]._len; row++) {
                double[] p = score0(chks, row, tmp, preds);
                for (int c = 0; c < preds.length; c++) chks[_output._names.length + c].set(row, p[c]);
            }
            if (j != null)
                j.update(1);
        }
    }.doAll(adaptFrm);
    // Return the projection into principal component space
    int x = _output._names.length, y = adaptFrm.numCols();
    // this will call vec_impl() and we cannot call the delete() below just yet
    Frame f = adaptFrm.extractFrame(x, y);
    f = new Frame(Key.<Frame>make(destination_key), f.names(), f.vecs());
    DKV.put(f);
    makeMetricBuilder(null).makeModelMetrics(this, orig, null, null);
    return f;
}
Also used : Frame(water.fvec.Frame) MRTask(water.MRTask) Chunk(water.fvec.Chunk)

Example 8 with Chunk

use of water.fvec.Chunk in project h2o-3 by h2oai.

the class AggregatorModel method scoreExemplarMembers.

@Override
public Frame scoreExemplarMembers(Key<Frame> destination_key, final int exemplarIdx) {
    Vec booleanCol = new MRTask() {

        @Override
        public void map(Chunk c, NewChunk nc) {
            for (int i = 0; i < c._len; ++i) nc.addNum(c.at8(i) == _exemplars[exemplarIdx].gid ? 1 : 0, 0);
        }
    }.doAll(Vec.T_NUM, new Frame(new Vec[] { _exemplar_assignment_vec_key.get() })).outputFrame().anyVec();
    Frame orig = _parms.train();
    Vec[] vecs = Arrays.copyOf(orig.vecs(), orig.vecs().length + 1);
    vecs[vecs.length - 1] = booleanCol;
    Frame ff = new Frame(orig.names(), orig.vecs());
    ff.add("predicate", booleanCol);
    Frame res = new Frame.DeepSelect().doAll(orig.types(), ff).outputFrame(destination_key, orig.names(), orig.domains());
    FrameUtils.shrinkDomainsToObservedSubset(res);
    DKV.put(res);
    assert (res.numRows() == _counts[exemplarIdx]);
    booleanCol.remove();
    return res;
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec) Chunk(water.fvec.Chunk) NewChunk(water.fvec.NewChunk) NewChunk(water.fvec.NewChunk)

Example 9 with Chunk

use of water.fvec.Chunk in project h2o-3 by h2oai.

the class AggregatorModel method createFrameOfExemplars.

public Frame createFrameOfExemplars(Frame orig, Key destination_key) {
    final long[] keep = new long[_exemplars.length];
    for (int i = 0; i < keep.length; ++i) keep[i] = _exemplars[i].gid;
    Vec exAssignment = _exemplar_assignment_vec_key.get();
    // preserve the original row order
    Vec booleanCol = new MRTask() {

        @Override
        public void map(Chunk c, Chunk c2) {
            for (int i = 0; i < keep.length; ++i) {
                if (keep[i] < c.start())
                    continue;
                if (keep[i] >= c.start() + c._len)
                    continue;
                c2.set((int) (keep[i] - c.start()), 1);
            }
        }
    }.doAll(new Frame(new Vec[] { exAssignment, exAssignment.makeZero() }))._fr.vec(1);
    Vec[] vecs = Arrays.copyOf(orig.vecs(), orig.vecs().length + 1);
    vecs[vecs.length - 1] = booleanCol;
    Frame ff = new Frame(orig.names(), orig.vecs());
    ff.add("predicate", booleanCol);
    Frame res = new Frame.DeepSelect().doAll(orig.types(), ff).outputFrame(destination_key, orig.names(), orig.domains());
    FrameUtils.shrinkDomainsToObservedSubset(res);
    booleanCol.remove();
    assert (res.numRows() == _exemplars.length);
    Vec cnts = res.anyVec().makeZero();
    Vec.Writer vw = cnts.open();
    for (int i = 0; i < _counts.length; ++i) vw.set(i, _counts[i]);
    vw.close();
    res.add("counts", cnts);
    DKV.put(destination_key, res);
    return res;
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec) Chunk(water.fvec.Chunk) NewChunk(water.fvec.NewChunk)

Example 10 with Chunk

use of water.fvec.Chunk in project h2o-3 by h2oai.

the class GBMTest method testNfoldsColumnNumbersFrom0.

@Test
public void testNfoldsColumnNumbersFrom0() {
    Frame tfr = null;
    Vec old = null;
    GBMModel gbm1 = null;
    try {
        tfr = parse_test_file("smalldata/junit/cars_20mpg.csv");
        // Remove unique id
        tfr.remove("name").remove();
        new MRTask() {

            @Override
            public void map(Chunk c) {
                for (int i = 0; i < c.len(); ++i) {
                    if (c.at8(i) == 3)
                        c.set(i, 0);
                    if (c.at8(i) == 4)
                        c.set(i, 1);
                    if (c.at8(i) == 5)
                        c.set(i, 2);
                    if (c.at8(i) == 6)
                        c.set(i, 3);
                    if (c.at8(i) == 8)
                        c.set(i, 4);
                }
            }
        }.doAll(tfr.vec("cylinders"));
        DKV.put(tfr);
        GBMModel.GBMParameters parms = new GBMModel.GBMParameters();
        parms._train = tfr._key;
        parms._response_column = "economy_20mpg";
        parms._fold_column = "cylinders";
        parms._ntrees = 10;
        GBM job1 = new GBM(parms);
        gbm1 = job1.trainModel().get();
        Assert.assertTrue(gbm1._output._cross_validation_models.length == 5);
    } finally {
        if (tfr != null)
            tfr.remove();
        if (old != null)
            old.remove();
        if (gbm1 != null) {
            gbm1.deleteCrossValidationModels();
            gbm1.delete();
        }
    }
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec) FVecTest.makeByteVec(water.fvec.FVecTest.makeByteVec) Chunk(water.fvec.Chunk) Test(org.junit.Test)

Aggregations

Chunk (water.fvec.Chunk)74 Frame (water.fvec.Frame)50 NewChunk (water.fvec.NewChunk)36 MRTask (water.MRTask)33 Vec (water.fvec.Vec)30 ValFrame (water.rapids.vals.ValFrame)26 C0DChunk (water.fvec.C0DChunk)7 BufferedString (water.parser.BufferedString)7 Random (java.util.Random)6 Test (org.junit.Test)5 MRTask2 (water.MRTask2)4 Val (water.rapids.Val)4 Key (water.Key)3 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)3 AstRoot (water.rapids.ast.AstRoot)3 AstNumList (water.rapids.ast.params.AstNumList)3 File (java.io.File)2 IOException (java.io.IOException)2 ValNum (water.rapids.vals.ValNum)2 PrettyPrint (water.util.PrettyPrint)2