Search in sources :

Example 56 with ValFrame

use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.

the class AstQtile method apply.

@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
    QuantileModel.QuantileParameters parms = new QuantileModel.QuantileParameters();
    Frame fr = stk.track(asts[1].exec(env)).getFrame();
    // Force a bogus Key for Quantiles ModelBuilder
    Frame fr_wkey = new Frame(fr);
    DKV.put(fr_wkey);
    parms._train = fr_wkey._key;
    parms._probs = ((AstNumList) asts[2]).expand();
    for (double d : parms._probs) if (d < 0 || d > 1)
        throw new IllegalArgumentException("Probability must be between 0 and 1: " + d);
    String inter = asts[3].exec(env).getStr();
    parms._combine_method = QuantileModel.CombineMethod.valueOf(inter.toUpperCase());
    parms._weights_column = asts[4].str().equals("_") ? null : asts[4].str();
    // Compute Quantiles
    Job j = new Quantile(parms).trainModel();
    QuantileModel q = (QuantileModel) j.get();
    DKV.remove(j._key);
    // Remove bogus Key
    DKV.remove(fr_wkey._key);
    // Reshape all outputs as a Frame, with probs in col 0 and the
    // quantiles in cols 1 thru fr.numCols() - except the optional weights vec
    int ncols = fr.numCols();
    if (parms._weights_column != null)
        ncols--;
    Vec[] vecs = new Vec[1 + /*1 more for the probs themselves*/
    ncols];
    String[] names = new String[vecs.length];
    vecs[0] = Vec.makeCon(null, parms._probs);
    names[0] = "Probs";
    int w = 0;
    for (int i = 0; i < vecs.length - 1; ++i) {
        if (fr._names[i].equals(parms._weights_column))
            w = 1;
        vecs[i + 1] = Vec.makeCon(null, q._output._quantiles[i]);
        names[i + 1] = fr._names[w + i] + "Quantiles";
    }
    q.delete();
    return new ValFrame(new Frame(names, vecs));
}
Also used : ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) QuantileModel(hex.quantile.QuantileModel) ValFrame(water.rapids.vals.ValFrame) Vec(water.fvec.Vec) Job(water.Job) Quantile(hex.quantile.Quantile)

Example 57 with ValFrame

use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.

the class AstRunif method apply.

@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
    Frame fr = stk.track(asts[1].exec(env)).getFrame();
    long seed = (long) asts[2].exec(env).getNum();
    if (seed == -1)
        seed = new Random().nextLong();
    return new ValFrame(new Frame(new String[] { "rnd" }, new Vec[] { fr.anyVec().makeRand(seed) }));
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Random(java.util.Random) Vec(water.fvec.Vec)

Example 58 with ValFrame

use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.

the class AstTable method apply.

@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
    Frame fr1 = stk.track(asts[1].exec(env)).getFrame();
    final boolean dense = asts[asts.length - 1].exec(env).getNum() == 1;
    Frame fr2 = asts.length == 4 ? stk.track(asts[2].exec(env)).getFrame() : null;
    int ncols = fr1.numCols() + (fr2 == null ? 0 : fr2.numCols());
    Vec vec1 = fr1.vec(0);
    ValFrame res = fast_table(vec1, ncols, fr1._names[0]);
    if (res != null)
        return res;
    if (!(asts.length == 3 || asts.length == 4) || ncols > 2)
        throw new IllegalArgumentException("table expects one or two columns");
    Vec vec2 = fr1.numCols() == 2 ? fr1.vec(1) : fr2 != null ? fr2.vec(0) : null;
    int sz = fr1._names.length + (fr2 != null ? fr2._names.length : 0);
    String[] colnames = new String[sz];
    int i = 0;
    for (String name : fr1._names) colnames[i++] = name;
    if (fr2 != null)
        for (String name : fr2._names) colnames[i++] = name;
    return slow_table(vec1, vec2, colnames, dense);
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Vec(water.fvec.Vec)

Example 59 with ValFrame

use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.

the class AstUnique method apply.

@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
    Frame fr = stk.track(asts[1].exec(env)).getFrame();
    Vec vec0 = fr.vec(0);
    Vec v;
    if (fr.numCols() != 1)
        throw new IllegalArgumentException("Unique applies to a single column only.");
    if (vec0.isCategorical()) {
        v = Vec.makeSeq(0, (long) vec0.domain().length, true);
        v.setDomain(vec0.domain());
        DKV.put(v);
    } else {
        UniqTask t = new UniqTask().doAll(fr);
        int nUniq = t._uniq.size();
        final AstGroup.G[] uniq = t._uniq.keySet().toArray(new AstGroup.G[nUniq]);
        v = Vec.makeZero(nUniq, vec0.get_type());
        new MRTask() {

            @Override
            public void map(Chunk c) {
                int start = (int) c.start();
                for (int i = 0; i < c._len; ++i) c.set(i, uniq[i + start]._gs[0]);
            }
        }.doAll(v);
    }
    return new ValFrame(new Frame(v));
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) AstGroup(water.rapids.ast.prims.mungers.AstGroup) Vec(water.fvec.Vec) MRTask(water.MRTask) Chunk(water.fvec.Chunk)

Example 60 with ValFrame

use of water.rapids.vals.ValFrame in project h2o-3 by h2oai.

the class AstLs method apply.

@Override
public ValFrame apply(Env env, Env.StackHelp stk, AstRoot[] asts) {
    ArrayList<String> domain = new ArrayList<>();
    Futures fs = new Futures();
    AppendableVec av = new AppendableVec(Vec.VectorGroup.VG_LEN1.addVec(), Vec.T_CAT);
    NewChunk keys = new NewChunk(av, 0);
    int r = 0;
    for (Key key : KeySnapshot.globalSnapshot().keys()) {
        keys.addCategorical(r++);
        domain.add(key.toString());
    }
    String[] key_domain = domain.toArray(new String[domain.size()]);
    av.setDomain(key_domain);
    keys.close(fs);
    // c0 is the row index vec
    Vec c0 = av.layout_and_close(fs);
    fs.blockForPending();
    return new ValFrame(new Frame(Key.<Frame>make("h2o_ls"), new String[] { "key" }, new Vec[] { c0 }));
}
Also used : ValFrame(water.rapids.vals.ValFrame) ValFrame(water.rapids.vals.ValFrame) Frame(water.fvec.Frame) Futures(water.Futures) Vec(water.fvec.Vec) AppendableVec(water.fvec.AppendableVec) ArrayList(java.util.ArrayList) AppendableVec(water.fvec.AppendableVec) Key(water.Key) NewChunk(water.fvec.NewChunk)

Aggregations

ValFrame (water.rapids.vals.ValFrame)132 Frame (water.fvec.Frame)98 Val (water.rapids.Val)48 Vec (water.fvec.Vec)43 Test (org.junit.Test)38 MRTask (water.MRTask)32 Chunk (water.fvec.Chunk)24 NewChunk (water.fvec.NewChunk)23 BufferedString (water.parser.BufferedString)16 AstNumList (water.rapids.ast.params.AstNumList)11 AstNum (water.rapids.ast.params.AstNum)7 ValNum (water.rapids.vals.ValNum)7 AstRoot (water.rapids.ast.AstRoot)6 ValRow (water.rapids.vals.ValRow)6 ArrayList (java.util.ArrayList)5 Key (water.Key)5 AstStrList (water.rapids.ast.params.AstStrList)5 Futures (water.Futures)4 AstParameter (water.rapids.ast.AstParameter)4 Random (java.util.Random)3