use of water.api.schemas3.KeyV3 in project h2o-3 by h2oai.
the class GridSearchSchema method fillFromParms.
@Override
public S fillFromParms(Properties parms) {
if (parms.containsKey("hyper_parameters")) {
Map<String, Object> m = water.util.JSONUtils.parse(parms.getProperty("hyper_parameters"));
// Convert lists and singletons into arrays
for (Map.Entry<String, Object> e : m.entrySet()) {
Object o = e.getValue();
Object[] o2 = o instanceof List ? ((List) o).toArray() : new Object[] { o };
hyper_parameters.put(e.getKey(), o2);
}
parms.remove("hyper_parameters");
}
if (parms.containsKey("search_criteria")) {
Properties p = water.util.JSONUtils.parseToProperties(parms.getProperty("search_criteria"));
if (!p.containsKey("strategy")) {
throw new H2OIllegalArgumentException("search_criteria.strategy", "null");
}
// TODO: move this into a factory method in HyperSpaceSearchCriteriaV99
String strategy = (String) p.get("strategy");
if ("Cartesian".equals(strategy)) {
search_criteria = new HyperSpaceSearchCriteriaV99.CartesianSearchCriteriaV99();
} else if ("RandomDiscrete".equals(strategy)) {
search_criteria = new HyperSpaceSearchCriteriaV99.RandomDiscreteValueSearchCriteriaV99();
if (p.containsKey("max_runtime_secs") && Double.parseDouble((String) p.get("max_runtime_secs")) < 0) {
throw new H2OIllegalArgumentException("max_runtime_secs must be >= 0 (0 for unlimited time)", strategy);
}
if (p.containsKey("max_models") && Integer.parseInt((String) p.get("max_models")) < 0) {
throw new H2OIllegalArgumentException("max_models must be >= 0 (0 for all models)", strategy);
}
} else {
throw new H2OIllegalArgumentException("search_criteria.strategy", strategy);
}
search_criteria.fillWithDefaults();
search_criteria.fillFromParms(p);
parms.remove("search_criteria");
} else {
// Fall back to Cartesian if there's no search_criteria specified.
search_criteria = new HyperSpaceSearchCriteriaV99.CartesianSearchCriteriaV99();
}
if (parms.containsKey("grid_id")) {
grid_id = new KeyV3.GridKeyV3(Key.<Grid>make(parms.getProperty("grid_id")));
parms.remove("grid_id");
}
// Do not check validity of parameters, GridSearch is tolerant of bad
// parameters (on purpose, many hyper-param points in the grid might be
// illegal for whatever reason).
this.parameters.fillFromParms(parms, false);
return (S) this;
}
use of water.api.schemas3.KeyV3 in project h2o-3 by h2oai.
the class CreateFrameHandler method run.
public JobV3 run(int version, CreateFrameV3 cf) {
if (cf.dest == null) {
cf.dest = new KeyV3.FrameKeyV3();
cf.dest.name = Key.rand();
}
CreateFrame cfr = new CreateFrame(cf.dest.key());
cf.fillImpl(cfr);
return new JobV3(cfr.execImpl());
}
use of water.api.schemas3.KeyV3 in project h2o-3 by h2oai.
the class MakeGLMModelHandler method getDataInfoFrame.
// instead of adding a new endpoint, just put this stupid test functionality here
/** Get the expanded (interactions + offsets) dataset. Careful printing! Test only
*/
public DataInfoFrameV3 getDataInfoFrame(int version, DataInfoFrameV3 args) {
Frame fr = DKV.getGet(args.frame.key());
if (null == fr)
throw new IllegalArgumentException("no frame found");
args.result = new KeyV3.FrameKeyV3(oneHot(fr, args.interactions, args.use_all, args.standardize, args.interactions_only, true)._key);
return args;
}
use of water.api.schemas3.KeyV3 in project h2o-3 by h2oai.
the class MakeGLMModelHandler method computeGram.
public GramV3 computeGram(int v, GramV3 input) {
if (DKV.get(input.X.key()) == null)
throw new IllegalArgumentException("Frame " + input.X.key() + " does not exist.");
Frame fr = input.X.key().get();
Frame frcpy = new Frame(fr._names.clone(), fr.vecs().clone());
String wname = null;
Vec weight = null;
if (input.W != null && !input.W.column_name.isEmpty()) {
wname = input.W.column_name;
if (fr.find(wname) == -1)
throw new IllegalArgumentException("Did not find weight vector " + wname);
weight = frcpy.remove(wname);
}
DataInfo dinfo = new DataInfo(frcpy, null, 0, input.use_all_factor_levels, input.standardize ? TransformType.STANDARDIZE : TransformType.NONE, TransformType.NONE, input.skip_missing, false, !input.skip_missing, /* weight */
false, /* offset */
false, /* fold */
false, /* intercept */
true);
DKV.put(dinfo);
if (weight != null)
dinfo.setWeights(wname, weight);
Gram.GramTask gt = new Gram.GramTask(null, dinfo, false, true).doAll(dinfo._adaptedFrame);
double[][] gram = gt._gram.getXX();
dinfo.remove();
String[] names = water.util.ArrayUtils.append(dinfo.coefNames(), "Intercept");
Vec[] vecs = new Vec[gram.length];
Key[] keys = new VectorGroup().addVecs(vecs.length);
for (int i = 0; i < vecs.length; ++i) vecs[i] = Vec.makeVec(gram[i], keys[i]);
input.destination_frame = new KeyV3.FrameKeyV3();
String keyname = input.X.key().toString();
if (keyname.endsWith(".hex"))
keyname = keyname.substring(0, keyname.lastIndexOf("."));
keyname = keyname + "_gram";
if (weight != null)
keyname = keyname + "_" + wname;
Key k = Key.make(keyname);
if (DKV.get(k) != null) {
int cnt = 0;
while (cnt < 1000 && DKV.get(k = Key.make(keyname + "_" + cnt)) != null) cnt++;
if (cnt == 1000)
throw new IllegalArgumentException("unable to make unique key");
}
input.destination_frame.fillFromImpl(k);
DKV.put(new Frame(k, names, vecs));
return input;
}
use of water.api.schemas3.KeyV3 in project h2o-3 by h2oai.
the class Word2VecHandler method transform.
public Word2VecTransformV3 transform(int version, Word2VecTransformV3 args) {
Word2VecModel model = DKV.getGet(args.model.key());
if (model == null)
throw new IllegalArgumentException("missing source model " + args.model);
Frame words = DKV.getGet(args.words_frame.key());
if (words == null)
throw new IllegalArgumentException("missing words frame " + args.words_frame);
if (words.numCols() != 1) {
throw new IllegalArgumentException("words frame is expected to have a single string column, got" + words.numCols());
}
if (args.aggregate_method == null)
args.aggregate_method = Word2VecModel.AggregateMethod.NONE;
Frame vectors = model.transform(words.vec(0), args.aggregate_method);
args.vectors_frame = new KeyV3.FrameKeyV3(vectors._key);
return args;
}
Aggregations