use of org.knime.base.data.neural.Architecture 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.base.data.neural.Architecture 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);
}
Aggregations