use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.
the class PMMLRuleTranslator method exportTo.
/**
* {@inheritDoc}
*/
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
m_nameMapper = new DerivedFieldMapper(pmmlDoc);
PMML pmml = pmmlDoc.getPMML();
RuleSetModel ruleSetModel = pmml.addNewRuleSetModel();
PMMLMiningSchemaTranslator.writeMiningSchema(spec, ruleSetModel);
ruleSetModel.setModelName("RuleSet");
ruleSetModel.setFunctionName(MININGFUNCTION.CLASSIFICATION);
RuleSet ruleSet = ruleSetModel.addNewRuleSet();
RuleSelectionMethod ruleSelectionMethod = ruleSet.addNewRuleSelectionMethod();
RuleSet origRs = m_originalRuleModel == null ? null : m_originalRuleModel.getRuleSet();
final List<RuleSelectionMethod> origMethods = origRs == null ? Collections.<RuleSelectionMethod>emptyList() : origRs.getRuleSelectionMethodList();
ruleSelectionMethod.setCriterion(origMethods.isEmpty() ? Criterion.FIRST_HIT : origMethods.get(0).getCriterion());
if (!Double.isNaN(m_recordCount)) {
ruleSet.setRecordCount(m_recordCount);
}
if (!Double.isNaN(m_nbCorrect)) {
ruleSet.setNbCorrect(m_nbCorrect);
}
if (!Double.isNaN(m_defaultConfidence)) {
ruleSet.setDefaultConfidence(m_defaultConfidence);
}
if (m_defaultScore != null) {
ruleSet.setDefaultScore(m_defaultScore);
}
new DerivedFieldMapper(pmmlDoc);
addRules(ruleSet, m_rules);
return RuleSetModel.type;
}
use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.
the class PMMLNeuralNetworkTranslator method initializeFrom.
/**
* {@inheritDoc}
*/
@Override
public void initializeFrom(final PMMLDocument pmmlDoc) {
m_nameMapper = new DerivedFieldMapper(pmmlDoc);
NeuralNetwork[] models = pmmlDoc.getPMML().getNeuralNetworkArray();
if (models.length == 0) {
throw new IllegalArgumentException("No neural network model" + " provided.");
} else if (models.length > 1) {
LOGGER.warn("Multiple neural network models found. " + "Only the first model is considered.");
}
NeuralNetwork nnModel = models[0];
// ------------------------------
// initiate Neural Input
initInputLayer(nnModel);
// -------------------------------
// initiate Hidden Layer
initiateHiddenLayers(nnModel);
// -------------------------------
// initiate Final Layer
initiateFinalLayer(nnModel);
// --------------------------------
// initiate Neural Outputs
initiateNeuralOutputs(nnModel);
// --------------------------------
// initiate Neural Network properties
ACTIVATIONFUNCTION.Enum actFunc = nnModel.getActivationFunction();
NNNORMALIZATIONMETHOD.Enum normMethod = nnModel.getNormalizationMethod();
if (ACTIVATIONFUNCTION.LOGISTIC != actFunc) {
LOGGER.error("Only logistic activation function is " + "supported in KNIME MLP.");
}
if (NNNORMALIZATIONMETHOD.NONE != normMethod) {
LOGGER.error("No normalization method is " + "supported in KNIME MLP.");
}
MININGFUNCTION.Enum functionName = nnModel.getFunctionName();
if (MININGFUNCTION.CLASSIFICATION == functionName) {
m_mlpMethod = MultiLayerPerceptron.CLASSIFICATION_MODE;
} else if (MININGFUNCTION.REGRESSION == functionName) {
m_mlpMethod = MultiLayerPerceptron.REGRESSION_MODE;
}
if (m_allLayers.size() < 3) {
throw new IllegalArgumentException("Only neural networks with 3 Layers supported in KNIME MLP.");
}
Layer[] allLayers = new Layer[m_allLayers.size()];
allLayers = m_allLayers.toArray(allLayers);
m_mlp = new MultiLayerPerceptron(allLayers);
Architecture myarch = new Architecture(allLayers[0].getPerceptrons().length, allLayers.length - 2, allLayers[1].getPerceptrons().length, allLayers[allLayers.length - 1].getPerceptrons().length);
m_mlp.setArchitecture(myarch);
m_mlp.setClassMapping(m_classmap);
m_mlp.setInputMapping(m_inputmap);
m_mlp.setMode(m_mlpMethod);
}
use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.
the class PMMLNeuralNetworkTranslator method exportTo.
/**
* {@inheritDoc}
*/
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
m_nameMapper = new DerivedFieldMapper(pmmlDoc);
NeuralNetwork nnModel = pmmlDoc.getPMML().addNewNeuralNetwork();
PMMLMiningSchemaTranslator.writeMiningSchema(spec, nnModel);
if (m_mlp.getMode() == MultiLayerPerceptron.CLASSIFICATION_MODE) {
nnModel.setFunctionName(MININGFUNCTION.CLASSIFICATION);
} else if (m_mlp.getMode() == MultiLayerPerceptron.REGRESSION_MODE) {
nnModel.setFunctionName(MININGFUNCTION.REGRESSION);
}
nnModel.setAlgorithmName("RProp");
nnModel.setActivationFunction(ACTIVATIONFUNCTION.LOGISTIC);
nnModel.setNormalizationMethod(NNNORMALIZATIONMETHOD.NONE);
nnModel.setWidth(0.0);
nnModel.setNumberOfLayers(BigInteger.valueOf(m_mlp.getNrLayers() - 1));
// add input layer
addInputLayer(nnModel, m_mlp);
// add hidden & final layers
for (int i = 1; i < m_mlp.getNrLayers(); i++) {
addLayer(nnModel, m_mlp, i);
}
// add output layer
addOutputLayer(nnModel, m_mlp, spec);
return NeuralNetwork.type;
}
use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.
the class CategoryToNumberNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
if (m_settings.getIncludedColumns().length == 0) {
// nothing to convert, let's return the input table.
setWarningMessage("No columns selected," + " returning input.");
}
BufferedDataTable inData = (BufferedDataTable) inObjects[0];
DataTableSpec inSpec = (DataTableSpec) inObjects[0].getSpec();
ColumnRearranger rearranger = createRearranger(inSpec);
BufferedDataTable outTable = exec.createColumnRearrangeTable(inData, rearranger, exec);
// the optional PMML in port (can be null)
PMMLPortObject inPMMLPort = (PMMLPortObject) inObjects[1];
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, rearranger.createSpec());
PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
for (CategoryToNumberCellFactory factory : m_factories) {
PMMLMapValuesTranslator trans = new PMMLMapValuesTranslator(factory.getConfig(), new DerivedFieldMapper(inPMMLPort));
outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
}
return new PortObject[] { outTable, outPMMLPort };
}
use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.
the class AbstractTreeModelPMMLTranslator method exportTo.
/**
* {@inheritDoc}
*/
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
PMML pmml = pmmlDoc.getPMML();
TreeModelDocument.TreeModel treeModel = pmml.addNewTreeModel();
AbstractTreeModelExporter<N> exporter = createExporter(new DerivedFieldMapper(pmmlDoc));
SchemaType st = exporter.writeModelToPMML(treeModel, spec);
if (exporter.hasWarning()) {
addWarning(exporter.getWarning());
}
return st;
}
Aggregations