use of org.knime.core.node.ModelContentRO in project knime-core by knime.
the class TreeEnsembleModelPortObject method load.
private void load(final PortObjectZipInputStream in, final PortObjectSpec spec, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
m_spec = (TreeEnsembleModelPortObjectSpec) spec;
m_modelRef = new WeakReference<TreeEnsembleModel>(null);
ModelContentRO mc = ModelContent.loadFromXML(in);
try {
m_nrAttributes = mc.getInt(CFG_NRATTRIBUTES);
m_nrModels = mc.getInt(CFG_NRMODELS);
} catch (InvalidSettingsException ise) {
IOException ioe = new IOException("Unable to restore meta information: " + ise.getMessage());
ioe.initCause(ise);
throw ioe;
}
// in.getNextEntry();
// m_modelRef = new WeakReference<TreeEnsembleModel>(TreeEnsembleModel.load(in, exec));
// in.closeEntry();
// call to ensure that the framework has established the FileStore
}
use of org.knime.core.node.ModelContentRO in project knime-core by knime.
the class RandomForestDistanceConfig method loadInternals.
/**
* {@inheritDoc}
*/
@Override
protected void loadInternals(final String prefix, final PortObjectZipInputStream inputStream, final ExecutionMonitor exec) throws InvalidSettingsException, CanceledExecutionException, IOException {
ZipEntry nextEntry = inputStream.getNextEntry();
if (new ZipEntry("model.zip").equals(nextEntry)) {
throw new IOException("Expected model.zip entry");
}
m_ensembleModel = TreeEnsembleModel.load(inputStream, exec);
inputStream.closeEntry();
nextEntry = inputStream.getNextEntry();
ModelContentRO mc = ModelContent.loadFromXML(inputStream);
m_learnTableSpec = DataTableSpec.load(mc.getModelContent(CFG_TABLESPEC));
}
use of org.knime.core.node.ModelContentRO in project knime-core by knime.
the class LogRegLearnerNodeModel 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_LOGREG_CONTENT);
m_content = LogisticRegressionContent.load(parContent, spec);
} catch (InvalidSettingsException ise) {
IOException ioe = new IOException("Unable to restore state: " + ise.getMessage());
ioe.initCause(ise);
throw ioe;
}
}
use of org.knime.core.node.ModelContentRO in project knime-core by knime.
the class FrequentItemSetModel method loadFromModelContent.
/**
* @param model the model containing information about the itemsets
* @throws InvalidSettingsException if the model is not valid
*/
public void loadFromModelContent(final ModelContentRO model) throws InvalidSettingsException {
// if (!model.getString(TYPE, "").equals(ITEMSET_MODEL)) {
// throw new IllegalArgumentException("Model input is not "
// + "a frequent itemset model!");
// }
int idCounter = 0;
m_itemSets = new ArrayList<FrequentItemSet>();
ModelContentRO itemsetsModel = model.getModelContent(ITEMSET_MODEL);
String[] nameMapping = itemsetsModel.getStringArray(NAME_MAPPING);
if (nameMapping.length > 0) {
m_nameMapping = Arrays.asList(nameMapping);
}
int nrItemSets = itemsetsModel.getInt(NUMBER_OF_ITEMSETS);
for (int i = 0; i < nrItemSets; i++) {
ModelContentRO itemSet = itemsetsModel.getModelContent(ITEMSET + i);
List<Integer> items = new ArrayList<Integer>();
double support = itemSet.getDouble(SUPPORT_ABS);
int nrOfItems = itemSet.getInt(ITEMSET_SIZE);
for (int j = 0; j < nrOfItems; j++) {
int pos;
if (m_nameMapping == null) {
pos = j;
} else {
String name = itemSet.getString(ITEM + j);
pos = m_nameMapping.indexOf(name);
}
items.add(pos);
}
FrequentItemSet freqSet = new FrequentItemSet("" + idCounter++, items, support);
m_itemSets.add(freqSet);
}
}
use of org.knime.core.node.ModelContentRO in project knime-core by knime.
the class SotaNodeModel method loadInternals.
/**
* {@inheritDoc}
*/
@Override
protected void loadInternals(final File internDir, final ExecutionMonitor exec) throws IOException {
File file = new File(internDir, TREE_FILE);
FileInputStream fis = new FileInputStream(file);
ModelContentRO modelContent = ModelContent.loadFromXML(fis);
// Load settings
int inDataSize = 0;
int origDataSize = 0;
try {
m_sota.setUseHierarchicalFuzzyData(modelContent.getBoolean(SotaPortObject.CFG_KEY_USE_FUZZY_HIERARCHY));
m_sota.setMaxHierarchicalLevel(modelContent.getInt(SotaPortObject.CFG_KEY_MAX_FUZZY_LEVEL));
inDataSize = modelContent.getInt(SotaPortObject.CFG_KEY_INDATA_SIZE);
origDataSize = modelContent.getInt(SotaPortObject.CFG_KEY_ORIGDATA_SIZE);
} catch (InvalidSettingsException e1) {
IOException ioe = new IOException("Could not load settings," + "due to invalid settings in model content !");
ioe.initCause(e1);
fis.close();
throw ioe;
}
// Load in data
DataTable table = DataContainer.readFromZip(new File(internDir, IN_DATA_FILE));
final DataArray inData = new DefaultDataArray(table, 1, inDataSize);
m_sota.setInData(inData);
// Load orig data
table = DataContainer.readFromZip(new File(internDir, ORIG_DATA_FILE));
final DataArray origData = new DefaultDataArray(table, 1, origDataSize);
m_sota.setOriginalData(origData);
// Load tree
SotaTreeCell root = new SotaTreeCell(0, false);
try {
root.loadFrom(modelContent, 0, null, false);
} catch (InvalidSettingsException e) {
IOException ioe = new IOException("Could not load tree cells," + "due to invalid settings in model content !");
ioe.initCause(e);
fis.close();
throw ioe;
}
m_sota.setRoot(root);
fis.close();
}
Aggregations