use of org.dmg.pmml.neural_network.NeuralInput in project shifu by ShifuML.
the class NeuralNetworkModelIntegrator method getNeuralInputs.
private NeuralInputs getNeuralInputs(final NeuralNetwork model) {
NeuralInputs nnInputs = new NeuralInputs();
// get HashMap for local transform and MiningSchema fields
HashMap<FieldName, FieldName> reversMiningTransformMap = new HashMap<FieldName, FieldName>();
HashMap<FieldName, List<FieldName>> treeMapOfTransform = new HashMap<FieldName, List<FieldName>>();
for (DerivedField dField : model.getLocalTransformations().getDerivedFields()) {
// Apply z-scale normalization on numerical variables
FieldName parentField = null;
if (dField.getExpression() instanceof NormContinuous) {
parentField = ((NormContinuous) dField.getExpression()).getField();
reversMiningTransformMap.put(dField.getName(), parentField);
} else // Apply bin map on categorical variables
if (dField.getExpression() instanceof MapValues) {
parentField = ((MapValues) dField.getExpression()).getFieldColumnPairs().get(0).getField();
reversMiningTransformMap.put(dField.getName(), parentField);
} else if (dField.getExpression() instanceof Discretize) {
parentField = ((Discretize) dField.getExpression()).getField();
reversMiningTransformMap.put(dField.getName(), parentField);
}
List<FieldName> fieldNames = treeMapOfTransform.get(parentField);
if (fieldNames == null) {
fieldNames = new ArrayList<FieldName>();
}
fieldNames.add(dField.getName());
treeMapOfTransform.put(parentField, fieldNames);
}
// comment here
List<MiningField> miningList = model.getMiningSchema().getMiningFields();
int index = 0;
for (DerivedField dField : model.getLocalTransformations().getDerivedFields()) {
List<FieldName> list = treeMapOfTransform.get(dField.getName());
boolean isLeaf = (list == null || list.size() == 0);
FieldName root = getRoot(dField.getName(), reversMiningTransformMap);
if (isLeaf && isRootInMiningList(root, miningList)) {
DerivedField field = new DerivedField(OpType.CONTINUOUS, DataType.DOUBLE).setName(dField.getName()).setExpression(new FieldRef(dField.getName()));
nnInputs.addNeuralInputs(new NeuralInput("0," + (index++), field));
}
}
DerivedField field = new DerivedField(OpType.CONTINUOUS, DataType.DOUBLE).setName(new FieldName(PluginConstants.biasValue)).setExpression(new FieldRef(new FieldName(PluginConstants.biasValue)));
nnInputs.addNeuralInputs(new NeuralInput(PluginConstants.biasValue, field));
return nnInputs;
}
Aggregations