Search in sources :

Example 1 with Chunk

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

the class ChunkDemo method Chunk.

@Test
public void Chunk() {
    String fileName = "./cookbookData/iris_withNA.csv";
    File file = new File(fileName);
    Key fkey = NFSFileVec.make(file);
    Key okey = Key.make("iris.hex");
    Frame fr;
    fr = ParseDataset2.parse(okey, new Key[] { fkey });
    //accessing the first vector from the frame
    Vec vv = fr.vec(0);
    int chunk_num = vv.nChunks();
    System.out.println("Number of chunks in column 1:  " + chunk_num);
    //Reading in the first chunk. This loads the data locally.
    Chunk cc = vv.chunkForChunkIdx(0);
    for (int i = 0; i < cc._len; i++) {
        //READING A DOUBLE ELEMENT FROM A CHUNK
        // at0 gives the local chunk index
        double d_at = cc.at0(i);
        System.out.println("double Value at chunk index " + i + ":  " + d_at);
        //READING A LONG ELEMENT FROM A CHUNK
        if (!Double.isNaN(d_at)) {
            long l_at = cc.at80(i);
            System.out.println("long Value at chunk index " + i + ":  " + l_at);
        }
        //UPDATING A DOUBLE ELEMENT TO A CHUNK
        double d = 1.23;
        double set_dval = cc.set0(i, d);
        System.out.println("Setting a double value at index " + i + " : " + set_dval);
        //UPDATING A LONG ELEMENT TO A CHUNK
        long l = 123L;
        long set_lval = cc.set0(i, l);
        System.out.println("Setting a double value at index " + i + " : " + set_lval);
    }
    //logThisH2OInstanceWebBrowserAddress();
    //sleepForever();	
    //CLEANING THE KV STORE OF ALL DATA
    Frame.delete(okey);
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec) NFSFileVec(water.fvec.NFSFileVec) Chunk(water.fvec.Chunk) File(java.io.File) Key(water.Key) Test(org.junit.Test)

Example 2 with Chunk

use of water.fvec.Chunk 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 3 with Chunk

use of water.fvec.Chunk 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 4 with Chunk

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

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

the class ScoreBuildHistogram method map.

@Override
public void map(Chunk[] chks) {
    final Chunk wrks = chks[_workIdx];
    final Chunk nids = chks[_nidIdx];
    final Chunk weight = _weightIdx >= 0 ? chks[_weightIdx] : new C0DChunk(1, chks[0].len());
    // Pass 1: Score a prior partially-built tree model, and make new Node
    // assignments to every row.  This involves pulling out the current
    // assigned DecidedNode, "scoring" the row against that Node's decision
    // criteria, and assigning the row to a new child UndecidedNode (and
    // giving it an improved prediction).
    int[] nnids = new int[nids._len];
    if (// Prior pass exists?
    _leaf > 0)
        score_decide(chks, nids, nnids);
    else
        // Just flag all the NA rows
        for (int row = 0; row < nids._len; row++) {
            if (weight.atd(row) == 0)
                continue;
            if (isDecidedRow((int) nids.atd(row)))
                nnids[row] = DECIDED_ROW;
        }
    // Pass 2: accumulate all rows, cols into histograms
    //    if (_subset)
    //      accum_subset(chks,wrks,weight,nnids); //for debugging - simple code
    //    else
    //generally faster
    accum_all(chks, wrks, weight, nnids);
}
Also used : C0DChunk(water.fvec.C0DChunk) Chunk(water.fvec.Chunk) C0DChunk(water.fvec.C0DChunk)

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