Search in sources :

Example 91 with Vec

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

the class VecTest method testToEnumDomainMatch.

private void testToEnumDomainMatch(Vec f, String[] expectedDomain) {
    Vec ef = null;
    try {
        ef = f.toEnum();
        String[] actualDomain = ef.domain();
        assertArrayEquals("toEnum call returns wrong domain!", expectedDomain, actualDomain);
    } finally {
        if (f != null)
            UKV.remove(f._key);
        if (ef != null)
            UKV.remove(ef._key);
    }
}
Also used : Vec(water.fvec.Vec)

Example 92 with Vec

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

the class VecTest method testMakeConSeq.

// Test HEX-1819
@Test
public void testMakeConSeq() {
    Vec v;
    v = makeConSeq(0xCAFE, CHUNK_SZ);
    assertTrue(v.at(234) == 0xCAFE);
    assertTrue(v._espc.length == 2);
    assertTrue(v._espc[0] == 0 && v._espc[1] == CHUNK_SZ);
    v.remove(new Futures()).blockForPending();
    v = makeConSeq(0xCAFE, 2 * CHUNK_SZ);
    assertTrue(v.at(234) == 0xCAFE);
    assertTrue(v.at(2 * CHUNK_SZ - 1) == 0xCAFE);
    assertTrue(v._espc.length == 3);
    assertTrue(v._espc[0] == 0 && v._espc[1] == CHUNK_SZ && v._espc[2] == CHUNK_SZ * 2);
    v.remove(new Futures()).blockForPending();
    v = makeConSeq(0xCAFE, 2 * CHUNK_SZ + 1);
    assertTrue(v.at(234) == 0xCAFE);
    assertTrue(v.at(2 * CHUNK_SZ) == 0xCAFE);
    assertTrue(v._espc.length == 4);
    assertTrue(v._espc[0] == 0 && v._espc[1] == CHUNK_SZ && v._espc[2] == CHUNK_SZ * 2 && v._espc[3] == CHUNK_SZ * 2 + 1);
    v.remove(new Futures()).blockForPending();
    v = makeConSeq(0xCAFE, 3 * CHUNK_SZ);
    assertTrue(v.at(234) == 0xCAFE);
    assertTrue(v.at(3 * CHUNK_SZ - 1) == 0xCAFE);
    assertTrue(v._espc.length == 4);
    assertTrue(v._espc[0] == 0 && v._espc[1] == CHUNK_SZ && v._espc[2] == CHUNK_SZ * 2 && v._espc[3] == CHUNK_SZ * 3);
    v.remove(new Futures()).blockForPending();
}
Also used : Vec(water.fvec.Vec) Test(org.junit.Test)

Example 93 with Vec

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

the class VecTest method testChangeDomainImpl.

// want this to be test but avoid serialization of outer class (due to use of anonymous mr2s)
private static final void testChangeDomainImpl() {
    ArrayList<Key> madeKeys = new ArrayList<Key>();
    try {
        final String[] oldDomain = { "a", "b", "c" };
        Vec v = Vec.makeNewCons(1000, 1, 0, new String[][] { oldDomain })[0];
        madeKeys.add(v._key);
        Vec.Writer vw = v.open();
        for (long i = 0; i < v.length(); ++i) vw.set(i, i % 3);
        vw.close();
        // now rebalance to ensure multiple chunks (and distribution to multiple nodes)
        Key reblancedKey = Key.make("reblanced");
        madeKeys.add(reblancedKey);
        RebalanceDataSet rbd = new RebalanceDataSet(new Frame(v), reblancedKey, 100);
        H2O.submitTask(rbd);
        rbd.join();
        Frame rebalancedFrame = DKV.get(reblancedKey).get();
        new MRTask2() {

            @Override
            public void map(Chunk c) {
                assertTrue(Arrays.deepEquals(c._vec.domain(), oldDomain));
            }
        }.doAll(rebalancedFrame);
        madeKeys.add(rebalancedFrame.lastVec()._key);
        final String[] newDomain = new String[] { "x", "y", "z" };
        rebalancedFrame.lastVec().changeDomain(newDomain);
        new MRTask2() {

            @Override
            public void map(Chunk c) {
                assertTrue(Arrays.deepEquals(c._vec.domain(), newDomain));
            }
        }.doAll(rebalancedFrame);
    } finally {
        for (Key k : madeKeys) UKV.remove(k);
    }
}
Also used : ArrayList(java.util.ArrayList) Vec(water.fvec.Vec)

Example 94 with Vec

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

the class ModelSerializationTest method prepareDRFModel.

private DRFModel prepareDRFModel(String dataset, int[] ignores, int response, boolean classification, int ntrees) {
    Frame f = parseFrame(dataset);
    try {
        DRF drf = new DRF();
        Vec respVec = f.vec(response);
        drf.source = f;
        drf.response = respVec;
        drf.classification = classification;
        drf.ntrees = ntrees;
        drf.score_each_iteration = true;
        drf.invoke();
        return UKV.get(drf.dest());
    } finally {
        if (f != null)
            f.delete();
    }
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec) DRF(hex.drf.DRF)

Example 95 with Vec

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

the class MRUtilsTest method run.

@Test
public void run() {
    Frame frame = null;
    Frame f0 = null;
    Frame f1 = null;
    Frame f2 = null;
    Frame f3 = null;
    Frame f4 = null;
    Frame f5 = null;
    Frame f6 = null;
    Vec orig_response = null;
    Key file = null;
    try {
        file = NFSFileVec.make(find_test_file("smalldata/./logreg/prostate.csv"));
        frame = ParseDataset2.parse(Key.make(), new Key[] { file });
        orig_response = frame.remove(1);
        frame.add("response", orig_response.toEnum());
        frame.add("MOV", frame.remove(2));
        frame.add("ASP", frame.remove("PSA"));
        f0 = MRUtils.sampleFrameStratified(frame, frame.vecs()[frame.find("response")], new float[] { 1.3f, 2.3f }, 0x1c3db4b3, true);
        f1 = MRUtils.shuffleAndBalance(frame, H2O.NUMCPUS * H2O.CLOUD.size(), /*nchunks*/
        0x600ddad, true, /*shuffle*/
        false);
        f2 = MRUtils.sampleFrameStratified(frame, frame.vecs()[frame.find("response")], new float[] { 1.3f, 2.3f }, 0x1c3db4b3, true);
        f3 = MRUtils.sampleFrame(frame, 7, 0xdecaf);
        f4 = MRUtils.sampleFrame(f2, 15, 0xdecaf);
        f5 = MRUtils.sampleFrame(f1, 13, 0xdecaf);
        f6 = MRUtils.sampleFrameStratified(f2, f2.vecs()[f2.find("response")], new float[] { 1.0f, 1.3f }, 0x1c3db4b3, true);
        f3.add("SWP", f3.vecs()[f3.find("ASP")]);
        Log.info(f3.toStringAll());
        assert (f3.names().length == f3.vecs().length);
        assert (f3.names().length == 10);
        assert (f3.names()[0].equals("ID"));
        assert (f3.names()[1].equals("AGE"));
        assert (f3.names()[2].equals("DPROS"));
        assert (f3.names()[3].equals("DCAPS"));
        assert (f3.names()[4].equals("VOL"));
        assert (f3.names()[5].equals("GLEASON"));
        assert (f3.names()[6].equals("response"));
        assert (f3.names()[7].equals("MOV"));
        assert (f3.names()[8].equals("ASP"));
        assert (f3.names()[9].equals("SWP"));
    } finally {
        // cleanup
        if (f6 != null)
            f6.delete();
        if (f5 != null)
            f5.delete();
        if (f4 != null)
            f4.delete();
        if (f3 != null)
            f3.delete();
        if (f2 != null)
            f2.delete();
        if (f1 != null)
            f1.delete();
        if (f0 != null)
            f0.delete();
        if (frame != null)
            frame.delete();
        if (orig_response != null)
            UKV.remove(orig_response._key);
        UKV.remove(file);
    }
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec) NFSFileVec(water.fvec.NFSFileVec) Test(org.junit.Test)

Aggregations

Vec (water.fvec.Vec)280 Frame (water.fvec.Frame)213 Test (org.junit.Test)82 NFSFileVec (water.fvec.NFSFileVec)48 ValFrame (water.rapids.vals.ValFrame)47 Chunk (water.fvec.Chunk)30 Random (java.util.Random)25 NewChunk (water.fvec.NewChunk)23 DeepLearningParameters (hex.deeplearning.DeepLearningModel.DeepLearningParameters)22 Key (water.Key)21 MRTask (water.MRTask)17 Val (water.rapids.Val)14 File (java.io.File)11 ArrayList (java.util.ArrayList)11 Futures (water.Futures)11 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)11 ValNum (water.rapids.vals.ValNum)11 ShuffleSplitFrame (hex.splitframe.ShuffleSplitFrame)10 BufferedString (water.parser.BufferedString)10 AppendableVec (water.fvec.AppendableVec)9