use of org.knime.core.node.ModelContentRO in project knime-core by knime.
the class DecisionTreeLearnerNodeModel method loadInternals.
/**
* {@inheritDoc}
*/
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
File internalsFile = new File(nodeInternDir, SAVE_INTERNALS_FILE_NAME);
if (!internalsFile.exists()) {
// file to load internals from not available
return;
}
BufferedInputStream in = new BufferedInputStream(new GZIPInputStream(new FileInputStream(internalsFile)));
ModelContentRO decisionTreeModel = ModelContent.loadFromXML(in);
try {
m_decisionTree = new DecisionTree(decisionTreeModel);
} catch (Exception e) {
// continue, but inform the user via a message
setWarningMessage("Internal model could not be loaded: " + e.getMessage() + ". The view will not display properly.");
}
}
use of org.knime.core.node.ModelContentRO in project knime-core by knime.
the class AffineTransConfiguration method load.
/**
* Restores content.
* @param settings To load from.
* @return A new configuration object
* @throws InvalidSettingsException If that fails.
*/
public static AffineTransConfiguration load(final ModelContentRO settings) throws InvalidSettingsException {
ModelContentRO colSub = settings.getModelContent(CFG_COLUMNS);
int colCount = colSub.keySet().size();
double[] scales = new double[colCount];
double[] translations = new double[colCount];
double[] mins = new double[colCount];
double[] maxs = new double[colCount];
Arrays.fill(scales, Double.NaN);
Arrays.fill(translations, Double.NaN);
Arrays.fill(mins, Double.NaN);
Arrays.fill(maxs, Double.NaN);
String[] names = new String[colCount];
int index = 0;
for (String key : colSub.keySet()) {
ModelContentRO sub = colSub.getModelContent(key);
String name = sub.getString(CFG_NAME);
double scale = sub.getDouble(CFG_SCALE);
double trans = sub.getDouble(CFG_TRANSLATE);
double min = sub.getDouble(CFG_MIN);
mins[index] = min;
double max = sub.getDouble(CFG_MAX);
maxs[index] = max;
scales[index] = scale;
translations[index] = trans;
names[index] = name;
index++;
}
String summary = settings.getString(CFG_SUMMARY);
return new AffineTransConfiguration(names, scales, translations, mins, maxs, summary);
}
use of org.knime.core.node.ModelContentRO in project knime-core by knime.
the class LinReg2LearnerNodeModel method loadInternals.
/**
* {@inheritDoc}
*/
@Override
protected void loadInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
File inFile = new File(internDir, FILE_SAVE);
ModelContentRO c = ModelContent.loadFromXML(new BufferedInputStream(new GZIPInputStream(new FileInputStream(inFile))));
try {
ModelContentRO specContent = c.getModelContent(CFG_SPEC);
DataTableSpec spec = DataTableSpec.load(specContent);
ModelContentRO parContent = c.getModelContent(CFG_LinReg2_CONTENT);
m_content = LinearRegressionContent.load(parContent, spec);
} catch (InvalidSettingsException ise) {
IOException ioe = new IOException("Unable to restore state: " + ise.getMessage());
ioe.initCause(ise);
throw ioe;
}
File dataFile = new File(internDir, FILE_DATA);
ContainerTable t = DataContainer.readFromZip(dataFile);
int rowCount = t.getRowCount();
m_rowContainer = new DefaultDataArray(t, 1, rowCount, exec);
}
use of org.knime.core.node.ModelContentRO in project knime-core by knime.
the class DecTreeToImageNodeModel method loadInternals.
/**
* Load internals.
*
* @param nodeInternDir The intern node directory to load tree from.
* @param exec Used to report progress or cancel saving.
* @throws IOException Always, since this method has not been implemented
* yet.
* @see org.knime.core.node.NodeModel
* #loadInternals(java.io.File,ExecutionMonitor)
*/
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
// read the decision tree
File internalsFile = new File(nodeInternDir, DEC_TREE_FILE_NAME);
if (!internalsFile.exists()) {
// file to load internals from not available
setWarningMessage("Internal model could not be loaded.");
return;
}
BufferedInputStream in2 = new BufferedInputStream(new GZIPInputStream(new FileInputStream(internalsFile)));
ModelContentRO binModel = ModelContent.loadFromXML(in2);
try {
m_decTree = new DecisionTree(binModel);
} catch (InvalidSettingsException ise) {
LOGGER.warn("Model (internals) could not be loaded.", ise);
setWarningMessage("Internal model could not be loaded.");
}
exec.setProgress(0.5);
// read image content
File f = new File(nodeInternDir, IMAGE_FILE_NAME);
ObjectInputStream in = new ObjectInputStream(new FileInputStream(f));
try {
m_imageContent = new PNGImageContent(in);
} catch (Exception e) {
in.close();
LOGGER.warn("Model (internals) could not be loaded.", e);
setWarningMessage("Internal model could not be loaded.");
}
in.close();
exec.setProgress(1.0);
}
use of org.knime.core.node.ModelContentRO in project knime-core by knime.
the class DecisionTreeLearnerNodeModel2 method loadInternals.
/**
* {@inheritDoc}
*/
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
File internalsFile = new File(nodeInternDir, SAVE_INTERNALS_FILE_NAME);
if (!internalsFile.exists()) {
// file to load internals from not available
return;
}
BufferedInputStream in = new BufferedInputStream(new GZIPInputStream(new FileInputStream(internalsFile)));
ModelContentRO decisionTreeModel = ModelContent.loadFromXML(in);
try {
m_decisionTree = new DecisionTree(decisionTreeModel);
} catch (Exception e) {
// continue, but inform the user via a message
setWarningMessage("Internal model could not be loaded: " + e.getMessage() + ". The view will not display properly.");
}
}
Aggregations