Search in sources :

Example 1 with NewChunk

use of water.fvec.NewChunk in project h2o-2 by h2oai.

the class MRUtils method add.

public static Frame add(Frame fr, final double d) {
    Frame r = new MRTask2() {

        @Override
        public void map(Chunk[] cs, NewChunk[] ncs) {
            for (int i = 0; i < ncs.length; i++) {
                NewChunk nc = ncs[i];
                Chunk c = cs[i];
                for (int r = 0; r < c._len; r++) nc.addNum(c.at0(r) + d);
            }
        }
    }.doAll(fr.numCols(), fr).outputFrame(fr.names(), fr.domains());
    return r;
}
Also used : Frame(water.fvec.Frame) MRTask2(water.MRTask2) Chunk(water.fvec.Chunk) NewChunk(water.fvec.NewChunk) NewChunk(water.fvec.NewChunk)

Example 2 with NewChunk

use of water.fvec.NewChunk in project h2o-2 by h2oai.

the class MRUtils method pow.

public static Frame pow(Frame fr, final double d) {
    Frame r = new MRTask2() {

        @Override
        public void map(Chunk[] cs, NewChunk[] ncs) {
            for (int i = 0; i < ncs.length; i++) {
                NewChunk nc = ncs[i];
                Chunk c = cs[i];
                for (int r = 0; r < c._len; r++) nc.addNum(Math.pow(c.at0(r), d));
            }
        }
    }.doAll(fr.numCols(), fr).outputFrame(fr.names(), fr.domains());
    return r;
}
Also used : Frame(water.fvec.Frame) MRTask2(water.MRTask2) Chunk(water.fvec.Chunk) NewChunk(water.fvec.NewChunk) NewChunk(water.fvec.NewChunk)

Example 3 with NewChunk

use of water.fvec.NewChunk in project h2o-2 by h2oai.

the class MRUtils method mul.

public static Frame mul(Frame fr, final double d) {
    Frame r = new MRTask2() {

        @Override
        public void map(Chunk[] cs, NewChunk[] ncs) {
            for (int i = 0; i < ncs.length; i++) {
                NewChunk nc = ncs[i];
                Chunk c = cs[i];
                for (int r = 0; r < c._len; r++) nc.addNum(c.at0(r) * d);
            }
        }
    }.doAll(fr.numCols(), fr).outputFrame(fr.names(), fr.domains());
    ;
    return r;
}
Also used : Frame(water.fvec.Frame) MRTask2(water.MRTask2) Chunk(water.fvec.Chunk) NewChunk(water.fvec.NewChunk) NewChunk(water.fvec.NewChunk)

Example 4 with NewChunk

use of water.fvec.NewChunk 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 5 with NewChunk

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

the class AstCut method apply.

@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
    Frame fr = stk.track(asts[1].exec(env)).getFrame();
    double[] cuts = check(asts[2]);
    Arrays.sort(cuts);
    String[] labels = check2(asts[3]);
    final boolean lowest = asts[4].exec(env).getNum() == 1;
    final boolean rite = asts[5].exec(env).getNum() == 1;
    // cap at 12
    final int digits = Math.min((int) asts[6].exec(env).getNum(), 12);
    if (fr.vecs().length != 1 || fr.vecs()[0].isCategorical())
        throw new IllegalArgumentException("First argument must be a numeric column vector");
    double fmin = fr.anyVec().min();
    double fmax = fr.anyVec().max();
    // c(0,10,100) -> 2 bins (0,10] U (10, 100]
    int nbins = cuts.length - 1;
    double width;
    if (nbins == 0) {
        if (cuts[0] < 2)
            throw new IllegalArgumentException("The number of cuts must be >= 2. Got: " + cuts[0]);
        // in this case, cut the vec into _cuts[0] many pieces of equal length
        nbins = (int) Math.floor(cuts[0]);
        width = (fmax - fmin) / nbins;
        cuts = new double[nbins];
        cuts[0] = fmin - 0.001 * (fmax - fmin);
        for (int i = 1; i < cuts.length; ++i) cuts[i] = (i == cuts.length - 1) ? (fmax + 0.001 * (fmax - fmin)) : (fmin + i * width);
    }
    // if(width == 0) throw new IllegalArgumentException("Data vector is constant!");
    if (labels != null && labels.length != nbins)
        throw new IllegalArgumentException("`labels` vector does not match the number of cuts.");
    // Construct domain names from _labels or bin intervals if _labels is null
    final double[] cutz = cuts;
    // first round _cuts to dig.lab decimals: example floor(2.676*100 + 0.5) / 100
    for (int i = 0; i < cuts.length; ++i) cuts[i] = Math.floor(cuts[i] * Math.pow(10, digits) + 0.5) / Math.pow(10, digits);
    String[][] domains = new String[1][nbins];
    if (labels == null) {
        domains[0][0] = (lowest ? "[" : left(rite)) + cuts[0] + "," + cuts[1] + rite(rite);
        for (int i = 1; i < (cuts.length - 1); ++i) domains[0][i] = left(rite) + cuts[i] + "," + cuts[i + 1] + rite(rite);
    } else
        domains[0] = labels;
    Frame fr2 = new MRTask() {

        @Override
        public void map(Chunk c, NewChunk nc) {
            int rows = c._len;
            for (int r = 0; r < rows; ++r) {
                double x = c.atd(r);
                if (Double.isNaN(x) || (lowest && x < cutz[0]) || (!lowest && (x < cutz[0] || MathUtils.equalsWithinOneSmallUlp(x, cutz[0]))) || (rite && x > cutz[cutz.length - 1]) || (!rite && (x > cutz[cutz.length - 1] || MathUtils.equalsWithinOneSmallUlp(x, cutz[cutz.length - 1]))))
                    nc.addNum(Double.NaN);
                else {
                    for (int i = 1; i < cutz.length; ++i) {
                        if (rite) {
                            if (x <= cutz[i]) {
                                nc.addNum(i - 1);
                                break;
                            }
                        } else if (x < cutz[i]) {
                            nc.addNum(i - 1);
                            break;
                        }
                    }
                }
            }
        }
    }.doAll(1, Vec.T_NUM, fr).outputFrame(fr.names(), domains);
    return new ValFrame(fr2);
}
Also used : ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Chunk(water.fvec.Chunk) NewChunk(water.fvec.NewChunk) NewChunk(water.fvec.NewChunk) ValFrame(water.rapids.vals.ValFrame) MRTask(water.MRTask)

Aggregations

NewChunk (water.fvec.NewChunk)42 Frame (water.fvec.Frame)34 Chunk (water.fvec.Chunk)32 ValFrame (water.rapids.vals.ValFrame)23 MRTask (water.MRTask)22 Vec (water.fvec.Vec)19 AppendableVec (water.fvec.AppendableVec)8 BufferedString (water.parser.BufferedString)6 Key (water.Key)5 Futures (water.Futures)4 MRTask2 (water.MRTask2)4 ValNum (water.rapids.vals.ValNum)4 C0DChunk (water.fvec.C0DChunk)3 Val (water.rapids.Val)2 ValRow (water.rapids.vals.ValRow)2 ConfusionMatrix (hex.ConfusionMatrix)1 MersenneTwisterRNG (hex.rng.MersenneTwisterRNG)1 DataInputStream (java.io.DataInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1