use of org.knime.core.node.ModelContent in project knime-core by knime.
the class SotaNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
// Save in data container
DataContainer.writeToZip(m_sota.getInDataContainer(), new File(internDir, IN_DATA_FILE), exec);
// Save original Data
DataContainer.writeToZip(m_sota.getOriginalData(), new File(internDir, ORIG_DATA_FILE), exec);
// Save tree
ModelContent modelContent = new ModelContent(INTERNAL_MODEL);
m_sota.getRoot().saveTo(modelContent, 0);
// Save settings
modelContent.addBoolean(SotaPortObject.CFG_KEY_USE_FUZZY_HIERARCHY, m_sota.isUseHierarchicalFuzzyData());
modelContent.addInt(SotaPortObject.CFG_KEY_MAX_FUZZY_LEVEL, m_sota.getMaxHierarchicalLevel());
modelContent.addInt(SotaPortObject.CFG_KEY_INDATA_SIZE, m_sota.getInDataContainer().size());
modelContent.addInt(SotaPortObject.CFG_KEY_ORIGDATA_SIZE, m_sota.getOriginalData().size());
File file = new File(internDir, TREE_FILE);
FileOutputStream fos = new FileOutputStream(file);
modelContent.saveToXML(fos);
fos.close();
}
use of org.knime.core.node.ModelContent in project knime-core by knime.
the class BasisFunctionLearnerNodeModel method execute.
/**
* Starts the learning algorithm in the learner.
*
* @param inData the input training data at index 0
* @param exec the execution monitor
* @return the output fuzzy rule model
* @throws CanceledExecutionException if the training was canceled
*/
@Override
public PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException {
BufferedDataTable data = (BufferedDataTable) inData[0];
// find all double cell columns in the data
DataTableSpec tSpec = data.getDataTableSpec();
LinkedHashSet<String> columns = new LinkedHashSet<String>(tSpec.getNumColumns());
List<String> targetHash = Arrays.asList(m_targetColumns);
for (int c = 0; c < tSpec.getNumColumns(); c++) {
DataColumnSpec cSpec = tSpec.getColumnSpec(c);
String name = cSpec.getName();
if (!targetHash.contains(name)) {
// TODO only numeric columns allowed
if (cSpec.getType().isCompatible(DoubleValue.class)) {
columns.add(cSpec.getName());
}
}
}
// get all data columns without target columns
String[] dataCols = BasisFunctionFactory.findDataColumns(tSpec, targetHash);
columns.addAll(Arrays.asList(dataCols));
// add target columns at the end
columns.addAll(Arrays.asList(m_targetColumns));
// filter selected columns from input data
String[] cols = columns.toArray(new String[] {});
ColumnRearranger colRe = new ColumnRearranger(tSpec);
colRe.keepOnly(cols);
BufferedDataTable trainData = exec.createColumnRearrangeTable(data, colRe, exec);
// print settings info
LOGGER.debug("distance : " + getDistance());
LOGGER.debug("missing : " + getMissingFct());
LOGGER.debug("target columns: " + Arrays.toString(m_targetColumns));
LOGGER.debug("shrink commit : " + isShrinkAfterCommit());
LOGGER.debug("max coverage : " + isMaxClassCoverage());
LOGGER.debug("max no. epochs: " + m_maxEpochs);
// create factory
BasisFunctionFactory factory = getFactory(trainData.getDataTableSpec());
// start training
BasisFunctionLearnerTable table = new BasisFunctionLearnerTable(trainData, dataCols, m_targetColumns, factory, BasisFunctionLearnerTable.MISSINGS[m_missing], m_shrinkAfterCommit, m_maxCoverage, m_maxEpochs, exec);
DataTableSpec modelSpec = table.getDataTableSpec();
DataColumnSpec[] modelSpecs = new DataColumnSpec[modelSpec.getNumColumns()];
for (int i = 0; i < modelSpecs.length; i++) {
DataColumnSpecCreator creator = new DataColumnSpecCreator(modelSpec.getColumnSpec(i));
creator.removeAllHandlers();
modelSpecs[i] = creator.createSpec();
}
// set translator mapping
m_translator.setMapper(table.getHiLiteMapper());
ModelContent modelInfo = new ModelContent(MODEL_INFO);
table.saveInfos(modelInfo);
m_modelInfo = modelInfo;
// return rules[0] and rule_model[1]
return new PortObject[] { exec.createBufferedDataTable(table, exec), createPortObject(new BasisFunctionModelContent(table.getDataTableSpec(), table.getBasisFunctions())) };
}
use of org.knime.core.node.ModelContent in project knime-core by knime.
the class DecTreeToImageNodeModel method saveInternals.
/**
* Save internals.
*
* @param nodeInternDir The intern node directory to save table to.
* @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
* #saveInternals(java.io.File,ExecutionMonitor)
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
// write the tree as pred params
ModelContent model = new ModelContent(DEC_TREE_FILE_NAME);
m_decTree.saveToPredictorParams(model, true);
File internalsFile = new File(nodeInternDir, DEC_TREE_FILE_NAME);
BufferedOutputStream out2 = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(internalsFile)));
model.saveToXML(out2);
out2.close();
exec.setProgress(0.5);
// write the image
File f = new File(nodeInternDir, IMAGE_FILE_NAME);
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(f));
m_imageContent.save(out);
out.close();
exec.setProgress(1.0);
}
use of org.knime.core.node.ModelContent in project knime-core by knime.
the class DecTreePredictorNodeModel method saveInternals.
/**
* Save internals.
*
* @param nodeInternDir The intern node directory to save table to.
* @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
* #saveInternals(java.io.File,ExecutionMonitor)
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
// write the tree as pred params
ModelContent model = new ModelContent(INTERNALS_FILE_NAME);
m_decTree.saveToPredictorParams(model, true);
File internalsFile = new File(nodeInternDir, INTERNALS_FILE_NAME);
BufferedOutputStream out2 = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(internalsFile)));
model.saveToXML(out2);
out2.close();
}
use of org.knime.core.node.ModelContent in project knime-core by knime.
the class CAIMDiscretizationNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
ModelContent binModel = new ModelContent(SAVE_INTERNALS_FILE_NAME);
// save the table spec of included names first
ModelContentWO sub = binModel.addModelContent(CONFIG_KEY_COLUMN_NANES);
DataTableSpec spec = (DataTableSpec) m_discretizationModel.getSpec();
spec.save(sub);
// now save the model.
m_discretizationModel.saveToModelContent(binModel);
File internalsFile = new File(nodeInternDir, SAVE_INTERNALS_FILE_NAME);
BufferedOutputStream out = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(internalsFile)));
binModel.saveToXML(out);
}
Aggregations