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 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 PMMLRegressionTranslator method initializeFrom.
/**
* {@inheritDoc}
*/
@Override
public void initializeFrom(final PMMLDocument pmmlDoc) {
m_nameMapper = new DerivedFieldMapper(pmmlDoc);
RegressionModel[] models = pmmlDoc.getPMML().getRegressionModelArray();
if (models.length == 0) {
throw new IllegalArgumentException("No regression model" + " provided.");
} else if (models.length > 1) {
LOGGER.warn("Multiple regression models found. " + "Only the first model is considered.");
}
RegressionModel regressionModel = models[0];
if (MININGFUNCTION.REGRESSION != regressionModel.getFunctionName()) {
LOGGER.error("Only regression is supported by KNIME.");
}
m_algorithmName = regressionModel.getAlgorithmName();
m_modelName = regressionModel.getModelName();
RegressionTableDocument.RegressionTable regressionTable = regressionModel.getRegressionTableArray(0);
List<NumericPredictor> knimePredictors = new ArrayList<NumericPredictor>();
for (NumericPredictorDocument.NumericPredictor pmmlPredictor : regressionTable.getNumericPredictorArray()) {
NumericPredictor knp = new NumericPredictor(m_nameMapper.getColumnName(pmmlPredictor.getName()), pmmlPredictor.getExponent().intValue(), pmmlPredictor.getCoefficient());
knimePredictors.add(knp);
}
m_regressionTable = new RegressionTable(regressionTable.getIntercept(), knimePredictors.toArray(new NumericPredictor[0]));
}
use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.
the class PMMLDecisionTreeTranslator method initializeFrom.
/**
* {@inheritDoc}
*/
@Override
public void initializeFrom(final PMMLDocument pmmlDoc) {
m_nameMapper = new DerivedFieldMapper(pmmlDoc);
TreeModel[] models = pmmlDoc.getPMML().getTreeModelArray();
if (models.length == 0) {
throw new IllegalArgumentException("No treemodel provided.");
}
TreeModel treeModel = models[0];
m_tree = parseDecTreeFromModel(treeModel);
}
use of org.knime.core.node.port.pmml.preproc.DerivedFieldMapper in project knime-core by knime.
the class PMMLNaiveBayesModelTranslator method exportTo.
/**
* {@inheritDoc}
*/
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
if (m_model == null) {
throw new NullPointerException("No model found to serialize");
}
DerivedFieldMapper mapper = new DerivedFieldMapper(pmmlDoc);
final PMML pmml = pmmlDoc.getPMML();
final org.dmg.pmml.NaiveBayesModelDocument.NaiveBayesModel bayesModel = pmml.addNewNaiveBayesModel();
PMMLMiningSchemaTranslator.writeMiningSchema(spec, bayesModel);
m_model.exportToPMML(bayesModel, mapper);
return org.dmg.pmml.NaiveBayesModelDocument.NaiveBayesModel.type;
}
Aggregations