Search in sources :

Example 1 with InputLayer

use of org.knime.base.data.neural.InputLayer in project knime-core by knime.

the class PMMLNeuralNetworkTranslator method addInputLayer.

/**
 * Writes the PMML input layer of the MLP.
 *
 * @param nnModel
 *            the Neural Network model.
 * @param mlp
 *            the underlying {@link MultiLayerPerceptron}.
 */
protected void addInputLayer(final NeuralNetwork nnModel, final MultiLayerPerceptron mlp) {
    Layer inputlayer = mlp.getLayer(0);
    Perceptron[] inputperceptrons = inputlayer.getPerceptrons();
    HashMap<String, Integer> inputmap = mlp.getInputMapping();
    NeuralInputs neuralInputs = nnModel.addNewNeuralInputs();
    neuralInputs.setNumberOfInputs(BigInteger.valueOf(inputperceptrons.length));
    for (int i = 0; i < inputperceptrons.length; i++) {
        NeuralInput neuralInput = neuralInputs.addNewNeuralInput();
        neuralInput.setId(0 + "," + i);
        // search corresponding input column
        String colname = "";
        for (Entry<String, Integer> e : inputmap.entrySet()) {
            if (e.getValue().equals(i)) {
                colname = e.getKey();
            }
        }
        DerivedField df = neuralInput.addNewDerivedField();
        df.setOptype(OPTYPE.CONTINUOUS);
        df.setDataType(DATATYPE.DOUBLE);
        FieldRef fieldRef = df.addNewFieldRef();
        fieldRef.setField(m_nameMapper.getDerivedFieldName(colname));
    }
}
Also used : BigInteger(java.math.BigInteger) SigmoidPerceptron(org.knime.base.data.neural.SigmoidPerceptron) MultiLayerPerceptron(org.knime.base.data.neural.MultiLayerPerceptron) Perceptron(org.knime.base.data.neural.Perceptron) InputPerceptron(org.knime.base.data.neural.InputPerceptron) FieldRef(org.dmg.pmml.FieldRefDocument.FieldRef) NeuralInputs(org.dmg.pmml.NeuralInputsDocument.NeuralInputs) 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) DerivedField(org.dmg.pmml.DerivedFieldDocument.DerivedField) NeuralInput(org.dmg.pmml.NeuralInputDocument.NeuralInput)

Example 2 with InputLayer

use of org.knime.base.data.neural.InputLayer in project knime-core by knime.

the class PMMLNeuralNetworkTranslator method initInputLayer.

/**
 * @param nnModel the PMML neural network model
 */
private void initInputLayer(final NeuralNetwork nnModel) {
    NeuralInputs neuralInputs = nnModel.getNeuralInputs();
    m_idPosMap = new HashMap<String, Integer>();
    m_curPerceptrons = new Vector<Perceptron>();
    m_inputmap = new HashMap<String, Integer>();
    m_counter = 0;
    m_curLayer = 0;
    for (NeuralInput ni : neuralInputs.getNeuralInputArray()) {
        m_curPercpetronID = ni.getId();
        String fieldName = m_nameMapper.getColumnName(ni.getDerivedField().getFieldRef().getField());
        Perceptron p = new InputPerceptron();
        p.setClassValue(fieldName);
        m_inputmap.put(fieldName, m_counter);
        m_curPerceptrons.add(p);
        m_idPosMap.put(m_curPercpetronID, m_counter);
        m_counter++;
    }
    Perceptron[] curPerceptrons = new Perceptron[m_curPerceptrons.size()];
    curPerceptrons = m_curPerceptrons.toArray(curPerceptrons);
    m_predLayer = new InputLayer(curPerceptrons);
    m_allLayers.add(m_curLayer, new InputLayer(curPerceptrons));
    m_predPerceptrons = curPerceptrons;
    m_predidPosMap = new HashMap<String, Integer>(m_idPosMap);
}
Also used : BigInteger(java.math.BigInteger) SigmoidPerceptron(org.knime.base.data.neural.SigmoidPerceptron) MultiLayerPerceptron(org.knime.base.data.neural.MultiLayerPerceptron) Perceptron(org.knime.base.data.neural.Perceptron) InputPerceptron(org.knime.base.data.neural.InputPerceptron) InputLayer(org.knime.base.data.neural.InputLayer) NeuralInputs(org.dmg.pmml.NeuralInputsDocument.NeuralInputs) InputPerceptron(org.knime.base.data.neural.InputPerceptron) NeuralInput(org.dmg.pmml.NeuralInputDocument.NeuralInput)

Example 3 with InputLayer

use of org.knime.base.data.neural.InputLayer in project knime-core by knime.

the class PMMLNeuralNetworkTranslator method addInputLayer.

/**
 * Writes the PMML input layer of the MLP.
 *
 * @param nnModel
 *            the Neural Network model.
 * @param mlp
 *            the underlying {@link MultiLayerPerceptron}.
 */
protected void addInputLayer(final NeuralNetwork nnModel, final MultiLayerPerceptron mlp) {
    Layer inputlayer = mlp.getLayer(0);
    Perceptron[] inputperceptrons = inputlayer.getPerceptrons();
    HashMap<String, Integer> inputmap = mlp.getInputMapping();
    NeuralInputs neuralInputs = nnModel.addNewNeuralInputs();
    neuralInputs.setNumberOfInputs(BigInteger.valueOf(inputperceptrons.length));
    for (int i = 0; i < inputperceptrons.length; i++) {
        NeuralInput neuralInput = neuralInputs.addNewNeuralInput();
        neuralInput.setId(0 + "," + i);
        // search corresponding input column
        String colname = "";
        for (Entry<String, Integer> e : inputmap.entrySet()) {
            if (e.getValue().equals(i)) {
                colname = e.getKey();
            }
        }
        DerivedField df = neuralInput.addNewDerivedField();
        df.setOptype(OPTYPE.CONTINUOUS);
        df.setDataType(DATATYPE.DOUBLE);
        FieldRef fieldRef = df.addNewFieldRef();
        fieldRef.setField(m_nameMapper.getDerivedFieldName(colname));
    }
}
Also used : BigInteger(java.math.BigInteger) SigmoidPerceptron(org.knime.base.data.neural.SigmoidPerceptron) MultiLayerPerceptron(org.knime.base.data.neural.MultiLayerPerceptron) Perceptron(org.knime.base.data.neural.Perceptron) InputPerceptron(org.knime.base.data.neural.InputPerceptron) FieldRef(org.dmg.pmml.FieldRefDocument.FieldRef) NeuralInputs(org.dmg.pmml.NeuralInputsDocument.NeuralInputs) 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) DerivedField(org.dmg.pmml.DerivedFieldDocument.DerivedField) NeuralInput(org.dmg.pmml.NeuralInputDocument.NeuralInput)

Example 4 with InputLayer

use of org.knime.base.data.neural.InputLayer in project knime-core by knime.

the class PMMLNeuralNetworkTranslator method initInputLayer.

/**
 * @param nnModel the PMML neural network model
 */
private void initInputLayer(final NeuralNetwork nnModel) {
    NeuralInputs neuralInputs = nnModel.getNeuralInputs();
    m_idPosMap = new HashMap<String, Integer>();
    m_curPerceptrons = new Vector<Perceptron>();
    m_inputmap = new HashMap<String, Integer>();
    m_counter = 0;
    m_curLayer = 0;
    for (NeuralInput ni : neuralInputs.getNeuralInputArray()) {
        m_curPercpetronID = ni.getId();
        String fieldName = m_nameMapper.getColumnName(ni.getDerivedField().getFieldRef().getField());
        Perceptron p = new InputPerceptron();
        p.setClassValue(fieldName);
        m_inputmap.put(fieldName, m_counter);
        m_curPerceptrons.add(p);
        m_idPosMap.put(m_curPercpetronID, m_counter);
        m_counter++;
    }
    Perceptron[] curPerceptrons = new Perceptron[m_curPerceptrons.size()];
    curPerceptrons = m_curPerceptrons.toArray(curPerceptrons);
    m_predLayer = new InputLayer(curPerceptrons);
    m_allLayers.add(m_curLayer, new InputLayer(curPerceptrons));
    m_predPerceptrons = curPerceptrons;
    m_predidPosMap = new HashMap<String, Integer>(m_idPosMap);
}
Also used : BigInteger(java.math.BigInteger) SigmoidPerceptron(org.knime.base.data.neural.SigmoidPerceptron) MultiLayerPerceptron(org.knime.base.data.neural.MultiLayerPerceptron) Perceptron(org.knime.base.data.neural.Perceptron) InputPerceptron(org.knime.base.data.neural.InputPerceptron) InputLayer(org.knime.base.data.neural.InputLayer) NeuralInputs(org.dmg.pmml.NeuralInputsDocument.NeuralInputs) InputPerceptron(org.knime.base.data.neural.InputPerceptron) NeuralInput(org.dmg.pmml.NeuralInputDocument.NeuralInput)

Aggregations

BigInteger (java.math.BigInteger)4 NeuralInput (org.dmg.pmml.NeuralInputDocument.NeuralInput)4 NeuralInputs (org.dmg.pmml.NeuralInputsDocument.NeuralInputs)4 InputLayer (org.knime.base.data.neural.InputLayer)4 InputPerceptron (org.knime.base.data.neural.InputPerceptron)4 MultiLayerPerceptron (org.knime.base.data.neural.MultiLayerPerceptron)4 Perceptron (org.knime.base.data.neural.Perceptron)4 SigmoidPerceptron (org.knime.base.data.neural.SigmoidPerceptron)4 DerivedField (org.dmg.pmml.DerivedFieldDocument.DerivedField)2 FieldRef (org.dmg.pmml.FieldRefDocument.FieldRef)2 NeuralLayer (org.dmg.pmml.NeuralLayerDocument.NeuralLayer)2 HiddenLayer (org.knime.base.data.neural.HiddenLayer)2 Layer (org.knime.base.data.neural.Layer)2