Search in sources :

Example 26 with DerivedFieldMapper

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;
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) NeuralNetwork(org.dmg.pmml.NeuralNetworkDocument.NeuralNetwork)

Example 27 with DerivedFieldMapper

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);
}
Also used : ACTIVATIONFUNCTION(org.dmg.pmml.ACTIVATIONFUNCTION) Architecture(org.knime.base.data.neural.Architecture) NeuralNetwork(org.dmg.pmml.NeuralNetworkDocument.NeuralNetwork) NeuralLayer(org.dmg.pmml.NeuralLayerDocument.NeuralLayer) Layer(org.knime.base.data.neural.Layer) InputLayer(org.knime.base.data.neural.InputLayer) HiddenLayer(org.knime.base.data.neural.HiddenLayer) MultiLayerPerceptron(org.knime.base.data.neural.MultiLayerPerceptron) DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) MININGFUNCTION(org.dmg.pmml.MININGFUNCTION) NNNORMALIZATIONMETHOD(org.dmg.pmml.NNNORMALIZATIONMETHOD)

Example 28 with DerivedFieldMapper

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]));
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) ArrayList(java.util.ArrayList) RegressionTableDocument(org.dmg.pmml.RegressionTableDocument) NumericPredictorDocument(org.dmg.pmml.NumericPredictorDocument) RegressionModel(org.dmg.pmml.RegressionModelDocument.RegressionModel)

Example 29 with DerivedFieldMapper

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);
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) TreeModel(org.dmg.pmml.TreeModelDocument.TreeModel)

Example 30 with DerivedFieldMapper

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;
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) PMML(org.dmg.pmml.PMMLDocument.PMML)

Aggregations

DerivedFieldMapper (org.knime.core.node.port.pmml.preproc.DerivedFieldMapper)37 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)11 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)11 PMML (org.dmg.pmml.PMMLDocument.PMML)9 DataTableSpec (org.knime.core.data.DataTableSpec)8 DerivedField (org.dmg.pmml.DerivedFieldDocument.DerivedField)7 BufferedDataTable (org.knime.core.node.BufferedDataTable)7 PortObject (org.knime.core.node.port.PortObject)7 ArrayList (java.util.ArrayList)4 NeuralNetwork (org.dmg.pmml.NeuralNetworkDocument.NeuralNetwork)4 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)4 MININGFUNCTION (org.dmg.pmml.MININGFUNCTION)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)3 DataType (org.knime.core.data.DataType)3 BigInteger (java.math.BigInteger)2 HashMap (java.util.HashMap)2 SchemaType (org.apache.xmlbeans.SchemaType)2 ACTIVATIONFUNCTION (org.dmg.pmml.ACTIVATIONFUNCTION)2 ArrayType (org.dmg.pmml.ArrayType)2 ClusterDocument (org.dmg.pmml.ClusterDocument)2