Search in sources :

Example 6 with H2OIllegalArgumentException

use of water.exceptions.H2OIllegalArgumentException in project h2o-3 by h2oai.

the class AUC2 method checkRecallValidity.

// Checks that recall is monotonic function.
// According to Leland, it should be; otherwise it's an error.
void checkRecallValidity() {
    double x0 = recall.exec(this, 0);
    for (int i = 1; i < _nBins; i++) {
        double x1 = recall.exec(this, i);
        if (x0 >= x1)
            throw new H2OIllegalArgumentException("" + i, "recall", "" + x1 + "<" + x0);
        x1 = x0;
    }
}
Also used : H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException)

Example 7 with H2OIllegalArgumentException

use of water.exceptions.H2OIllegalArgumentException in project h2o-3 by h2oai.

the class ModelMetrics method getMetricFromModel.

public static double getMetricFromModel(Key<Model> key, String criterion) {
    Model model = DKV.getGet(key);
    if (null == model)
        throw new H2OIllegalArgumentException("Cannot find model " + key);
    if (null == criterion || criterion.equals(""))
        throw new H2OIllegalArgumentException("Need a valid criterion, but got '" + criterion + "'.");
    ModelMetrics m = model._output._cross_validation_metrics != null ? model._output._cross_validation_metrics : model._output._validation_metrics != null ? model._output._validation_metrics : model._output._training_metrics;
    Method method = null;
    ConfusionMatrix cm = m.cm();
    try {
        method = m.getClass().getMethod(criterion.toLowerCase());
    } catch (Exception e) {
    // fall through
    }
    if (null == method && null != cm) {
        try {
            method = cm.getClass().getMethod(criterion.toLowerCase());
        } catch (Exception e) {
        // fall through
        }
    }
    if (null == method)
        throw new H2OIllegalArgumentException("Failed to find ModelMetrics for criterion: " + criterion);
    double c;
    try {
        c = (double) method.invoke(m);
    } catch (Exception fallthru) {
        try {
            c = (double) method.invoke(cm);
        } catch (Exception e) {
            throw new H2OIllegalArgumentException("Failed to get metric: " + criterion + " from ModelMetrics object: " + m, "Failed to get metric: " + criterion + " from ModelMetrics object: " + m + ", criterion: " + method + ", exception: " + e);
        }
    }
    return c;
}
Also used : H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException) Method(java.lang.reflect.Method) H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException)

Example 8 with H2OIllegalArgumentException

use of water.exceptions.H2OIllegalArgumentException in project h2o-3 by h2oai.

the class ModelSchemaV3 method writeJSON_impl.

public final AutoBuffer writeJSON_impl(AutoBuffer ab) {
    ab.putJSONStr("algo", algo);
    ab.put1(',');
    ab.putJSONStr("algo_full_name", algo_full_name);
    ab.put1(',');
    ab.putJSON("model_id", model_id);
    ab.put1(',');
    // Builds ModelParameterSchemaV2 objects for each field, and then calls writeJSON on the array
    try {
        PS defaults = createParametersSchema().fillFromImpl(parameters.getImplClass().newInstance());
        ModelParametersSchemaV3.writeParametersJSON(ab, parameters, defaults);
        ab.put1(',');
    } catch (Exception e) {
        String msg = "Error creating an instance of ModelParameters for algo: " + algo;
        String dev_msg = "Error creating an instance of ModelParameters for algo: " + algo + ": " + this.getImplClass();
        throw new H2OIllegalArgumentException(msg, dev_msg);
    }
    if (null == output) {
        // allow key-only output
        output = createOutputSchema();
    }
    // Let output render itself:
    ab.putJSON("output", output);
    ab.put1(',');
    ab.putJSONAStr("compatible_frames", compatible_frames);
    return ab;
}
Also used : H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException) H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException)

Example 9 with H2OIllegalArgumentException

use of water.exceptions.H2OIllegalArgumentException in project h2o-3 by h2oai.

the class Schema method markdown.

/**
   * Generate Markdown documentation for this Schema, given we already have the metadata constructed.
   * @throws H2ONotFoundArgumentException if reflection on a field fails
   */
public StringBuffer markdown(SchemaMetadata meta, boolean include_input_fields, boolean include_output_fields) {
    MarkdownBuilder builder = new MarkdownBuilder();
    builder.comment("Preview with http://jbt.github.io/markdown-editor");
    builder.heading1("schema ", this.getClass().getSimpleName());
    builder.hline();
    // builder.paragraph(metadata.summary);
    // TODO: refactor with Route.markdown():
    // fields
    // don't print the table at all if there are no rows
    boolean first;
    try {
        if (include_input_fields) {
            first = true;
            builder.heading2("input fields");
            for (SchemaMetadata.FieldMetadata field_meta : meta.fields) {
                if (field_meta.direction == API.Direction.INPUT || field_meta.direction == API.Direction.INOUT) {
                    if (first) {
                        builder.tableHeader("name", "required?", "level", "type", "schema?", "schema", "default", "description", "values", "is member of frames", "is mutually exclusive with");
                        first = false;
                    }
                    builder.tableRow(field_meta.name, String.valueOf(field_meta.required), field_meta.level.name(), field_meta.type, String.valueOf(field_meta.is_schema), // Something better for toString()?
                    field_meta.is_schema ? field_meta.schema_name : "", // Something better for toString()?
                    (null == field_meta.value ? "(null)" : field_meta.value.toString()), field_meta.help, (field_meta.values == null || field_meta.values.length == 0 ? "" : Arrays.toString(field_meta.values)), (field_meta.is_member_of_frames == null ? "[]" : Arrays.toString(field_meta.is_member_of_frames)), (field_meta.is_mutually_exclusive_with == null ? "[]" : Arrays.toString(field_meta.is_mutually_exclusive_with)));
                }
            }
            if (first)
                builder.paragraph("(none)");
        }
        if (include_output_fields) {
            first = true;
            builder.heading2("output fields");
            for (SchemaMetadata.FieldMetadata field_meta : meta.fields) {
                if (field_meta.direction == API.Direction.OUTPUT || field_meta.direction == API.Direction.INOUT) {
                    if (first) {
                        builder.tableHeader("name", "type", "schema?", "schema", "default", "description", "values", "is member of frames", "is mutually exclusive with");
                        first = false;
                    }
                    builder.tableRow(field_meta.name, field_meta.type, String.valueOf(field_meta.is_schema), field_meta.is_schema ? field_meta.schema_name : "", // something better than toString()?
                    (null == field_meta.value ? "(null)" : field_meta.value.toString()), field_meta.help, (field_meta.values == null || field_meta.values.length == 0 ? "" : Arrays.toString(field_meta.values)), (field_meta.is_member_of_frames == null ? "[]" : Arrays.toString(field_meta.is_member_of_frames)), (field_meta.is_mutually_exclusive_with == null ? "[]" : Arrays.toString(field_meta.is_mutually_exclusive_with)));
                }
            }
            if (first)
                builder.paragraph("(none)");
        }
    // TODO: render examples and other stuff, if it's passed in
    } catch (Exception e) {
        IcedHashMapGeneric.IcedHashMapStringObject values = new IcedHashMapGeneric.IcedHashMapStringObject();
        values.put("schema", this);
        // TODO: This isn't quite the right exception type:
        throw new H2OIllegalArgumentException("Caught exception using reflection on schema: " + this, "Caught exception using reflection on schema: " + this + ": " + e, values);
    }
    return builder.stringBuffer();
}
Also used : H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException) H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException) InvocationTargetException(java.lang.reflect.InvocationTargetException) H2OKeyNotFoundArgumentException(water.exceptions.H2OKeyNotFoundArgumentException) H2ONotFoundArgumentException(water.exceptions.H2ONotFoundArgumentException)

Example 10 with H2OIllegalArgumentException

use of water.exceptions.H2OIllegalArgumentException in project h2o-3 by h2oai.

the class ByteVec method getPreviewChunkBytes.

/** Get all the bytes of a given chunk.
   *  Useful for previewing sections of files.
   *
   *  @param chkIdx index of desired chunk
   *  @return array of initial bytes
   */
public byte[] getPreviewChunkBytes(int chkIdx) {
    if (chkIdx >= nChunks())
        throw new H2OIllegalArgumentException("Asked for chunk index beyond the number of chunks.");
    if (chkIdx == 0)
        return chunkForChunkIdx(chkIdx)._mem;
    else {
        //must eat partial lines
        // FIXME: a hack to consume partial lines since each preview chunk is seen as cidx=0
        byte[] mem = chunkForChunkIdx(chkIdx)._mem;
        int i = 0, j = mem.length - 1;
        while (i < mem.length && mem[i] != CHAR_CR && mem[i] != CHAR_LF) i++;
        while (j > i && mem[j] != CHAR_CR && mem[j] != CHAR_LF) j--;
        if (j - i > 1)
            return Arrays.copyOfRange(mem, i, j);
        else
            return null;
    }
}
Also used : H2OIllegalArgumentException(water.exceptions.H2OIllegalArgumentException)

Aggregations

H2OIllegalArgumentException (water.exceptions.H2OIllegalArgumentException)43 Frame (water.fvec.Frame)16 Key (water.Key)6 H2OKeyNotFoundArgumentException (water.exceptions.H2OKeyNotFoundArgumentException)6 Vec (water.fvec.Vec)6 Field (java.lang.reflect.Field)3 Chunk (water.fvec.Chunk)3 NewChunk (water.fvec.NewChunk)3 DeepLearningParameters (hex.deeplearning.DeepLearningModel.DeepLearningParameters)2 GLMModel (hex.glm.GLMModel)2 DRFModel (hex.tree.drf.DRFModel)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Iced (water.Iced)2 FrameV3 (water.api.schemas3.FrameV3)2 JobV3 (water.api.schemas3.JobV3)2 KeyV3 (water.api.schemas3.KeyV3)2 ByteVec (water.fvec.ByteVec)2 C0DChunk (water.fvec.C0DChunk)2