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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations