Search in sources :

Example 11 with Frame

use of water.fvec.Frame 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 12 with Frame

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

the class Models method findCompatibleFrames.

private static Map<String, Frame> findCompatibleFrames(Model model, Map<String, Frame> all_frames, Map<String, Set<String>> all_frames_cols) {
    Map<String, Frame> compatible_frames = new TreeMap<String, Frame>();
    Set<String> model_column_names = new HashSet(Arrays.asList(model._names));
    for (Map.Entry<String, Set<String>> entry : all_frames_cols.entrySet()) {
        Set<String> frame_cols = entry.getValue();
        if (frame_cols.containsAll(model_column_names)) {
            /// See if adapt throws an exception or not.
            try {
                Frame frame = all_frames.get(entry.getKey());
                // TODO: this does too much work; write canAdapt()
                Frame[] outputs = model.adapt(frame, false);
                Frame adapted = outputs[0];
                Frame trash = outputs[1];
                // adapted.delete();  // TODO: shouldn't we clean up adapted vecs?  But we can't delete() the frame as a whole. . .
                trash.delete();
                // A-Ok
                compatible_frames.put(entry.getKey(), frame);
            } catch (Exception e) {
            // skip
            }
        }
    }
    return compatible_frames;
}
Also used : Frame(water.fvec.Frame)

Example 13 with Frame

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

the class Predict method serve.

@Override
protected Response serve() {
    Frame fr = null;
    try {
        if (model == null)
            throw new IllegalArgumentException("Model is required to perform validation!");
        // Create a new random key
        if (prediction == null)
            prediction = Key.make("__Prediction_" + Key.make());
        fr = new Frame(prediction, new String[0], new Vec[0]).delete_and_lock(null);
        fr = model.score(data);
        // Jam in the frame key
        fr = new Frame(prediction, fr._names, fr.vecs());
        return Inspect2.redirect(this, prediction.toString());
    } catch (Throwable t) {
        return Response.error(t);
    } finally {
        if (fr != null)
            fr.unlock(null);
    }
}
Also used : Frame(water.fvec.Frame)

Example 14 with Frame

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

the class ASTNum method select.

// Execute a col/row selection & return the selection.  NULL means "all".
// Error to mix negatives & positive.  Negative list is sorted, with dups
// removed.  Positive list can have dups (which replicates cols) and is
// ordered.  numbers.  1-based numbering; 0 is ignored & removed.
static Object select(long len, AST ast, Env env) {
    // Trivial "all"
    if (ast == null)
        return null;
    ast.exec(env);
    long[] cols;
    if (!env.isAry()) {
        // Peek double; Silent truncation (R semantics)
        int col = (int) env._d[env._sp - 1];
        // Ignore a non-existent column
        if (col < 0 && col < -len)
            col = 0;
        if (col == 0)
            return new long[0];
        return new long[] { col };
    }
    // Got a frame/list of results.
    // Decide if we're a toss-out or toss-in list
    // Peek-frame
    Frame ary = env._ary[env._sp - 1];
    if (ary.numCols() != 1)
        throw new IllegalArgumentException("Selector must be a single column: " + ary.toStringNames());
    Vec vec = ary.anyVec();
    // Check for a matching column of bools.
    if (ary.numRows() == len && vec.min() >= 0 && vec.max() <= 1 && vec.isInt() && ary.numRows() > 1)
        // Boolean vector selection.
        return ary;
    // Convert single vector to a list of longs selecting rows
    if (ary.numRows() > 10000000)
        throw H2O.fail("Unimplemented: Cannot explicitly select > 10000000 rows in slice.");
    cols = MemoryManager.malloc8((int) ary.numRows());
    for (int i = 0; i < cols.length; ++i) {
        if (vec.isNA(i))
            throw new IllegalArgumentException("Can not use NA as index!");
        cols[i] = vec.at8(i);
    }
    return cols;
}
Also used : Frame(water.fvec.Frame) Vec(water.fvec.Vec)

Example 15 with Frame

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

the class GLRM method init.

/**
   * Validate all parameters, and prepare the model for training.
   */
@Override
public void init(boolean expensive) {
    super.init(expensive);
    _ncolX = _parms._k;
    _ncolA = _train == null ? -1 : _train.numCols();
    _ncolY = _train == null ? -1 : LinearAlgebraUtils.numColsExp(_train, true);
    initLoss();
    if (_parms._gamma_x < 0)
        error("_gamma_x", "gamma must be a non-negative number");
    if (_parms._gamma_y < 0)
        error("_gamma_y", "gamma_y must be a non-negative number");
    if (_parms._max_iterations < 1 || _parms._max_iterations > 1e6)
        error("_max_iterations", "max_iterations must be between 1 and 1e6 inclusive");
    if (_parms._init_step_size <= 0)
        error("_init_step_size", "init_step_size must be a positive number");
    if (_parms._min_step_size < 0 || _parms._min_step_size > _parms._init_step_size)
        error("_min_step_size", "min_step_size must be between 0 and " + _parms._init_step_size);
    // Cannot recover SVD of original _train from XY of transformed _train
    if (_parms._recover_svd && (_parms._impute_original && _parms._transform != DataInfo.TransformType.NONE))
        error("_recover_svd", "_recover_svd and _impute_original cannot both be true if _train is transformed");
    if (_train == null)
        return;
    if (_ncolA < 2)
        error("_train", "_train must have more than one column");
    if (_valid != null && _valid.numRows() != _train.numRows())
        error("_valid", "_valid must have same number of rows as _train");
    if (_ncolY > 5000)
        warn("_train", "_train has " + _ncolY + " columns when categoricals are expanded. Algorithm may be slow.");
    if (_parms._k < 1 || _parms._k > _ncolY)
        error("_k", "_k must be between 1 and " + _ncolY + " inclusive");
    if (_parms._user_y != null) {
        // Check dimensions of user-specified initial Y
        if (_parms._init != GlrmInitialization.User)
            error("_init", "init must be 'User' if providing user-specified points");
        Frame user_y = _parms._user_y.get();
        assert user_y != null;
        int user_y_cols = _parms._expand_user_y ? _ncolA : _ncolY;
        // Check dimensions of user-specified initial Y
        if (user_y.numCols() != user_y_cols)
            error("_user_y", "The user-specified Y must have the same number of columns (" + user_y_cols + ") " + "as the training observations");
        else if (user_y.numRows() != _parms._k)
            error("_user_y", "The user-specified Y must have k = " + _parms._k + " rows");
        else {
            int zero_vec = 0;
            Vec[] centersVecs = user_y.vecs();
            for (int c = 0; c < _ncolA; c++) {
                if (centersVecs[c].naCnt() > 0) {
                    error("_user_y", "The user-specified Y cannot contain any missing values");
                    break;
                } else if (centersVecs[c].isConst() && centersVecs[c].max() == 0)
                    zero_vec++;
            }
            if (zero_vec == _ncolA)
                error("_user_y", "The user-specified Y cannot all be zero");
        }
    }
    if (_parms._user_x != null) {
        // Check dimensions of user-specified initial X
        if (_parms._init != GlrmInitialization.User)
            error("_init", "init must be 'User' if providing user-specified points");
        Frame user_x = _parms._user_x.get();
        assert user_x != null;
        if (user_x.numCols() != _parms._k)
            error("_user_x", "The user-specified X must have k = " + _parms._k + " columns");
        else if (user_x.numRows() != _train.numRows())
            error("_user_x", "The user-specified X must have the same number of rows " + "(" + _train.numRows() + ") as the training observations");
        else {
            int zero_vec = 0;
            Vec[] centersVecs = user_x.vecs();
            for (int c = 0; c < _parms._k; c++) {
                if (centersVecs[c].naCnt() > 0) {
                    error("_user_x", "The user-specified X cannot contain any missing values");
                    break;
                } else if (centersVecs[c].isConst() && centersVecs[c].max() == 0)
                    zero_vec++;
            }
            if (zero_vec == _parms._k)
                error("_user_x", "The user-specified X cannot all be zero");
        }
    }
    for (int i = 0; i < _ncolA; i++) {
        if (_train.vec(i).isString() || _train.vec(i).isUUID())
            throw H2O.unimpl("GLRM cannot handle String or UUID data");
    }
    // check to make sure we can fit.
    if (expensive && error_count() == 0)
        checkMemoryFootPrint();
}
Also used : Frame(water.fvec.Frame)

Aggregations

Frame (water.fvec.Frame)782 Test (org.junit.Test)435 Vec (water.fvec.Vec)215 ValFrame (water.rapids.vals.ValFrame)132 NFSFileVec (water.fvec.NFSFileVec)66 Val (water.rapids.Val)65 SplitFrame (hex.SplitFrame)59 Key (water.Key)56 DeepLearningParameters (hex.deeplearning.DeepLearningModel.DeepLearningParameters)54 Chunk (water.fvec.Chunk)50 NewChunk (water.fvec.NewChunk)37 MRTask (water.MRTask)33 ShuffleSplitFrame (hex.splitframe.ShuffleSplitFrame)31 Ignore (org.junit.Ignore)28 Random (java.util.Random)26 File (java.io.File)25 BufferedString (water.parser.BufferedString)21 H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)19 HashMap (java.util.HashMap)17 hex (hex)16