use of ambit2.core.data.model.IEvaluation.EVType in project ambit-mirror by ideaconsult.
the class ModelJSONReporter method parseContent.
protected void parseContent(ModelQueryResults model) {
ObjectInputStream ois = null;
try {
Form form = new Form(model.getContent());
InputStream in = new ByteArrayInputStream(Base64.decode(form.getFirstValue("model")));
ois = new ObjectInputStream(in);
Object o = ois.readObject();
if (o == null)
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, String.format("Error when reading model %s", model.getName()));
List<IEvaluation<String>> e = new ArrayList<IEvaluation<String>>();
for (EVType evt : EVType.values()) {
String[] evals = form.getValuesArray(evt.name());
for (int i = 0; i < evals.length; i++) {
EvaluationStats<String> stats = new EvaluationStats<String>(evt, evals[i]);
for (EVStatsType evst : EVStatsType.values()) {
Object value = form.getFirstValue(evt.name() + "_" + evst.name());
if (value == null)
continue;
try {
stats.getStats().put(evst, Double.parseDouble(value.toString()));
} catch (Exception x) {
}
}
e.add(stats);
}
}
if (e.size() == 0)
model.setEvaluation(null);
else
model.setEvaluation(e);
} catch (Exception x) {
} finally {
try {
ois.close();
} catch (Exception x) {
}
}
}
use of ambit2.core.data.model.IEvaluation.EVType in project ambit-mirror by ideaconsult.
the class ModelPredictor method createPredictor.
public Predictor createPredictor(ModelQueryResults model) throws ResourceException {
this.model = model;
try {
Form form = new Form(model.getContent());
Object o = null;
Object modeltype = form.getFirstValue("objecttype");
try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(Base64.decode(form.getFirstValue("model"))))) {
o = ois.readObject();
if (o == null)
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, String.format("Error when reading model %s", model.getName()));
if (modeltype != null && AlgorithmFormat.JAVA_CLASS.name().equals(modeltype))
try {
o = Class.forName(o.toString()).newInstance();
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, String.format("Wrong model type %s %s", model.getName(), o.getClass().getName()));
}
if (!isSupported(o))
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, String.format("Wrong model type %s %s", model.getName(), o.getClass().getName()));
}
for (EVType evt : EVType.values()) {
String[] evals = form.getValuesArray(evt.name());
if (evals == null)
continue;
for (String eval : evals) model.addEvaluation(new EvaluationStats<String>(evt, eval));
}
header = getHeader(form);
classIndex = getClassIndex(form);
if ((header != null) && (classIndex >= 0) && (classIndex < header.numAttributes()))
header.setClassIndex(classIndex);
if (header != null) {
String[] options = new String[2];
options[0] = "-R";
options[1] = "1";
Remove remove = new Remove();
try {
remove.setOptions(options);
} catch (Exception x) {
}
;
filter = remove;
} else
filter = null;
return (Predictor) o;
} catch (ResourceException x) {
throw x;
} catch (NumberFormatException x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
} catch (IOException x) {
throw new ResourceException(Status.SERVER_ERROR_SERVICE_UNAVAILABLE, x.getMessage(), x);
} catch (ClassNotFoundException x) {
throw new ResourceException(Status.CLIENT_ERROR_NOT_ACCEPTABLE, x.getMessage(), x);
} catch (Exception x) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, x.getMessage(), x);
} finally {
}
}
Aggregations