Search in sources :

Example 31 with MRTask

use of water.MRTask in project h2o-3 by h2oai.

the class TransformWrappedVecTest method testInversion.

@Test
public void testInversion() {
    Vec v = null;
    try {
        v = Vec.makeZero(1 << 20);
        AstFunction ast = (AstFunction) Rapids.parse("{ x . (- 1 x) }");
        Vec iv = new TransformWrappedVec(v, ast);
        new MRTask() {

            @Override
            public void map(Chunk c) {
                for (int i = 0; i < c._len; ++i) if (c.atd(i) != 1)
                    throw new RuntimeException("moo");
            }
        }.doAll(iv);
        iv.remove();
    } finally {
        if (null != v)
            v.remove();
    }
}
Also used : AstFunction(water.rapids.ast.AstFunction) MRTask(water.MRTask) Test(org.junit.Test)

Example 32 with MRTask

use of water.MRTask in project h2o-3 by h2oai.

the class VecDataInputStreamTest method makeRandomByteVec.

private static Vec makeRandomByteVec(Vec blueprint) {
    final Vec v0 = new Vec(blueprint.group().addVec(), blueprint._rowLayout, null, Vec.T_NUM);
    final int nchunks = v0.nChunks();
    new MRTask() {

        @Override
        protected void setupLocal() {
            for (int i = 0; i < nchunks; i++) {
                Key k = v0.chunkKey(i);
                if (k.home()) {
                    int len = (int) (v0.espc()[i + 1] - v0.espc()[i]);
                    byte[] bytes = new byte[len];
                    new Random(i).nextBytes(bytes);
                    DKV.put(k, new C1NChunk(bytes), _fs);
                }
            }
        }
    }.doAllNodes();
    DKV.put(v0._key, v0);
    return v0;
}
Also used : Random(java.util.Random) MRTask(water.MRTask) Key(water.Key)

Example 33 with MRTask

use of water.MRTask in project h2o-3 by h2oai.

the class DataInfoTestAdapt method checkFrame.

private void checkFrame(final Frame checkMe, final Frame gold) {
    Vec[] vecs = new Vec[checkMe.numCols() + gold.numCols()];
    new MRTask() {

        @Override
        public void map(Chunk[] cs) {
            int off = checkMe.numCols();
            for (int i = 0; i < off; ++i) {
                for (int r = 0; r < cs[0]._len; ++r) {
                    double check = cs[i].atd(r);
                    double gold = cs[i + off].atd(r);
                    if (Math.abs(check - gold) > 1e-12)
                        throw new RuntimeException("bonk");
                }
            }
        }
    }.doAll(vecs);
}
Also used : Vec(water.fvec.Vec) MRTask(water.MRTask) Chunk(water.fvec.Chunk)

Example 34 with MRTask

use of water.MRTask in project h2o-3 by h2oai.

the class ModelMetricsRegression method computeHuberDelta.

public static double computeHuberDelta(Vec actual, Vec preds, Vec weight, double huberAlpha) {
    Vec absdiff = new MRTask() {

        @Override
        public void map(Chunk[] cs, NewChunk[] nc) {
            for (int i = 0; i < cs[0].len(); ++i) nc[0].addNum(Math.abs(cs[0].atd(i) - cs[1].atd(i)));
        }
    }.doAll(1, (byte) 3, new Frame(new String[] { "preds", "actual" }, new Vec[] { preds, actual })).outputFrame().anyVec();
    // make a deep copy of the model's current distribution state (huber delta)
    //compute huber delta based on huber alpha quantile on absolute prediction error
    double hd = MathUtils.computeWeightedQuantile(weight, absdiff, huberAlpha);
    absdiff.remove();
    return hd;
}
Also used : MRTask(water.MRTask)

Example 35 with MRTask

use of water.MRTask in project h2o-3 by h2oai.

the class UnfoldingFrame method makeVecs.

protected List<Vec> makeVecs() throws IOException {
    Vec[] vecs = new Vec[width];
    for (int j = 0; j < width; j++) {
        vecs[j] = buildZeroVec();
    }
    MRTask task = new MRTask() {

        @Override
        public void map(Chunk[] cs) {
            // TODO(vlad): find a solution for empty  
            int size = cs[0].len();
            long start = cs[0].start();
            for (int r = 0; r < size; r++) {
                long i = r + start;
                List<X> values = function.apply(i);
                for (int j = 0; j < cs.length; j++) {
                    DataChunk<X> tc = factory.apply(cs[j]);
                    tc.set(r, j < values.size() ? values.get(j) : null);
                }
            }
        }
    };
    MRTask mrTask = task.doAll(vecs);
    return Arrays.asList(mrTask._fr.vecs());
}
Also used : Vec(water.fvec.Vec) MRTask(water.MRTask)

Aggregations

MRTask (water.MRTask)55 ValFrame (water.rapids.vals.ValFrame)37 Chunk (water.fvec.Chunk)33 Frame (water.fvec.Frame)33 NewChunk (water.fvec.NewChunk)23 Vec (water.fvec.Vec)17 BufferedString (water.parser.BufferedString)9 ValNum (water.rapids.vals.ValNum)6 Val (water.rapids.Val)5 AstRoot (water.rapids.ast.AstRoot)4 AstNumList (water.rapids.ast.params.AstNumList)4 Key (water.Key)3 Test (org.junit.Test)2 Futures (water.Futures)2 AstNum (water.rapids.ast.params.AstNum)2 AstStr (water.rapids.ast.params.AstStr)2 AstStrList (water.rapids.ast.params.AstStrList)2 AstGroup (water.rapids.ast.prims.mungers.AstGroup)2 ValRow (water.rapids.vals.ValRow)2 DataInfo (hex.DataInfo)1