Search in sources :

Example 11 with Futures

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

the class CBSChunkTest method testImpl.

void testImpl(long[] ls, int[] xs, int expBpv, int expGap, int expClen, int expNA) {
    AppendableVec av = new AppendableVec(Vec.newKey(), Vec.T_NUM);
    // Create a new chunk
    NewChunk nc = new NewChunk(av, 0, ls, xs, null, null);
    for (int i = 0; i < ls.length; ++i) if (ls[i] == Long.MIN_VALUE)
        nc.setNA_impl(i);
    // Compute rollups, including NA
    nc.type();
    assertEquals(expNA, nc.naCnt());
    // Compress chunk
    Chunk cc = nc.compress();
    assert cc instanceof CBSChunk;
    Futures fs = new Futures();
    cc._vec = av.layout_and_close(fs);
    fs.blockForPending();
    Assert.assertTrue("Found chunk class " + cc.getClass() + " but expected " + CBSChunk.class, CBSChunk.class.isInstance(cc));
    assertEquals(nc._len, cc._len);
    assertEquals(expBpv, ((CBSChunk) cc).bpv());
    assertEquals(expGap, ((CBSChunk) cc).gap());
    assertEquals(expClen, cc._mem.length - CBSChunk._OFF);
    // Also, we can decompress correctly
    for (int i = 0; i < ls.length; i++) if (ls[i] != Long.MIN_VALUE)
        assertEquals(ls[i], cc.at8(i));
    else
        assertTrue(cc.isNA(i));
    // materialize the vector (prerequisite to free the memory)
    Vec vv = av.layout_and_close(fs);
    fs.blockForPending();
    vv.remove();
}
Also used : Futures(water.Futures)

Example 12 with Futures

use of water.Futures in project h2o-2 by h2oai.

the class CoxPH method execImpl.

@Override
protected void execImpl() {
    final DataInfo dinfo = model.data_info;
    final int n_offsets = (model.parameters.offset_columns == null) ? 0 : model.parameters.offset_columns.length;
    final int n_coef = dinfo.fullN() - n_offsets;
    final double[] step = MemoryManager.malloc8d(n_coef);
    final double[] oldCoef = MemoryManager.malloc8d(n_coef);
    final double[] newCoef = MemoryManager.malloc8d(n_coef);
    Arrays.fill(step, Double.NaN);
    Arrays.fill(oldCoef, Double.NaN);
    for (int j = 0; j < n_coef; ++j) newCoef[j] = init;
    double oldLoglik = -Double.MAX_VALUE;
    final int n_time = (int) (model.max_time - model.min_time + 1);
    final boolean has_start_column = (model.parameters.start_column != null);
    final boolean has_weights_column = (model.parameters.weights_column != null);
    for (int i = 0; i <= iter_max; ++i) {
        model.iter = i;
        final CoxPHTask coxMR = new CoxPHTask(self(), dinfo, newCoef, model.min_time, n_time, n_offsets, has_start_column, has_weights_column).doAll(dinfo._adaptedFrame);
        final double newLoglik = model.calcLoglik(coxMR);
        if (newLoglik > oldLoglik) {
            if (i == 0)
                model.calcCounts(coxMR);
            model.calcModelStats(newCoef, newLoglik);
            model.calcCumhaz_0(coxMR);
            if (newLoglik == 0)
                model.lre = -Math.log10(Math.abs(oldLoglik - newLoglik));
            else
                model.lre = -Math.log10(Math.abs((oldLoglik - newLoglik) / newLoglik));
            if (model.lre >= lre_min)
                break;
            Arrays.fill(step, 0);
            for (int j = 0; j < n_coef; ++j) for (int k = 0; k < n_coef; ++k) step[j] -= model.var_coef[j][k] * model.gradient[k];
            for (int j = 0; j < n_coef; ++j) if (Double.isNaN(step[j]) || Double.isInfinite(step[j]))
                break;
            oldLoglik = newLoglik;
            System.arraycopy(newCoef, 0, oldCoef, 0, oldCoef.length);
        } else {
            for (int j = 0; j < n_coef; ++j) step[j] /= 2;
        }
        for (int j = 0; j < n_coef; ++j) newCoef[j] = oldCoef[j] - step[j];
    }
    final Futures fs = new Futures();
    DKV.put(dest(), model, fs);
    fs.blockForPending();
}
Also used : DataInfo(hex.FrameTask.DataInfo) Futures(water.Futures)

Example 13 with Futures

use of water.Futures in project h2o-2 by h2oai.

the class SparseTest method makeChunk.

protected Chunk makeChunk(double[] vals) {
    int nzs = 0;
    int[] nonzeros = new int[vals.length];
    int j = 0;
    for (double d : vals) if (d != 0)
        nonzeros[nzs++] = j++;
    Key key = Vec.newKey();
    AppendableVec av = new AppendableVec(key);
    NewChunk nv = new NewChunk(av, 0);
    for (double d : vals) {
        if (Double.isNaN(d))
            nv.addNA();
        else if ((long) d == d)
            nv.addNum((long) d, 0);
        else
            nv.addNum(d);
    }
    nv.close(0, null);
    Futures fs = new Futures();
    Vec vec = av.close(fs);
    fs.blockForPending();
    return vec.chunkForChunkIdx(0);
}
Also used : Futures(water.Futures) Key(water.Key)

Example 14 with Futures

use of water.Futures in project h2o-2 by h2oai.

the class SparseTest method setAndClose.

protected Chunk setAndClose(double[] vals, int[] ids, Chunk c) {
    final int cidx = c.cidx();
    final Vec vec = c._vec;
    for (int i = 0; i < vals.length; ++i) c.set0(ids[i], vals[i]);
    Futures fs = new Futures();
    c.close(cidx, fs);
    return vec.chunkForChunkIdx(cidx);
}
Also used : Futures(water.Futures)

Example 15 with Futures

use of water.Futures in project h2o-2 by h2oai.

the class MatrixMultiply method serve.

@Override
protected Response serve() {
    Key jk = Key.make(after + "_job");
    Futures fs = new Futures();
    if (skip_first_col && x.numCols() == (y.numRows() + 1)) {
        // hack to remove columns added during smvlight conversion
        x.remove(0).remove(fs);
        y.remove(0).remove(fs);
    }
    new DMatrix.MatrixMulJob(jk, after, x, y).fork();
    return Response.redirect(this, "/2/Inspector", "src_key", after);
}
Also used : Futures(water.Futures) Key(water.Key) DMatrix(hex.la.DMatrix)

Aggregations

Futures (water.Futures)34 Vec (water.fvec.Vec)11 Key (water.Key)10 Frame (water.fvec.Frame)7 AppendableVec (water.fvec.AppendableVec)4 NewChunk (water.fvec.NewChunk)4 ValFrame (water.rapids.vals.ValFrame)4 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 Test (org.junit.Test)2 MRTask (water.MRTask)2 DataInfo (hex.FrameTask.DataInfo)1 DMatrix (hex.la.DMatrix)1 File (java.io.File)1 IOException (java.io.IOException)1 Job (water.Job)1 FrameKeyV3 (water.api.schemas3.KeyV3.FrameKeyV3)1 ByteVec (water.fvec.ByteVec)1 NFSFileVec (water.fvec.NFSFileVec)1 BufferedString (water.parser.BufferedString)1