@Override public VisitorAction visit(LocalTransformations localTransformations){ if(localTransformations.hasDerivedFields()){ this.localDerivedFields.addAll(localTransformations.getDerivedFields()); } return super.visit(localTransformations); }
/** * Create an instance of {@link LocalTransformations } * */ public LocalTransformations createLocalTransformations() { return new LocalTransformations(); }
@Override public LocalTransformations addExtensions(Extension... extensions) { getExtensions().addAll(Arrays.asList(extensions)); return this; }
public LocalTransformations addDerivedFields(DerivedField... derivedFields) { getDerivedFields().addAll(Arrays.asList(derivedFields)); return this; }
@Override public VisitorAction accept(Visitor visitor) { VisitorAction status = visitor.visit(this); if (status == VisitorAction.CONTINUE) { visitor.pushParent(this); if ((status == VisitorAction.CONTINUE)&&hasExtensions()) { status = org.dmg.pmml.PMMLObject.traverse(visitor, getExtensions()); } if ((status == VisitorAction.CONTINUE)&&hasDerivedFields()) { status = org.dmg.pmml.PMMLObject.traverse(visitor, getDerivedFields()); } visitor.popParent(); } if (status == VisitorAction.TERMINATE) { return VisitorAction.TERMINATE; } return VisitorAction.CONTINUE; }
private LocalTransformations getLocalTranformations(NeuralNetwork model) { // delete target List<DerivedField> derivedFields = model.getLocalTransformations().getDerivedFields(); // add bias DerivedField field = new DerivedField(OpType.CONTINUOUS, DataType.DOUBLE).withName(new FieldName( PluginConstants.biasValue)); field.withExpression(new Constant(String.valueOf(PluginConstants.bias))); derivedFields.add(field); return new LocalTransformations().withDerivedFields(derivedFields); }
@Override public LocalTransformations build(BasicML basicML) { LocalTransformations localTransformations = new LocalTransformations(); if(basicML instanceof BasicFloatNetwork) { BasicFloatNetwork bfn = (BasicFloatNetwork) basicML; Set<Integer> featureSet = bfn.getFeatureSet(); for(ColumnConfig config: columnConfigList) { if(config.isFinalSelect() && (CollectionUtils.isEmpty(featureSet) || featureSet.contains(config.getColumnNum()))) { double cutoff = modelConfig.getNormalizeStdDevCutOff(); localTransformations.withDerivedFields(config.isCategorical() ? createCategoricalDerivedField( config, cutoff, modelConfig.getNormalizeType()) : createNumericalDerivedField(config, cutoff, modelConfig.getNormalizeType())); } } } else { for(ColumnConfig config: columnConfigList) { if(config.isFinalSelect()) { double cutoff = modelConfig.getNormalizeStdDevCutOff(); localTransformations.withDerivedFields(config.isCategorical() ? createCategoricalDerivedField( config, cutoff, modelConfig.getNormalizeType()) : createNumericalDerivedField(config, cutoff, modelConfig.getNormalizeType())); } } } return localTransformations; }
@Override public PMMLObject popParent(){ PMMLObject parent = super.popParent(); if(parent instanceof Model){ Model model = (Model)parent; LocalTransformations localTransformations = model.getLocalTransformations(); if(localTransformations != null){ processLocalTransformations(localTransformations); if(!localTransformations.hasDerivedFields()){ model.setLocalTransformations(null); } } } else if(parent instanceof PMML){ PMML pmml = (PMML)parent; TransformationDictionary transformationDictionary = pmml.getTransformationDictionary(); if(transformationDictionary != null){ processTransformationDictionary(transformationDictionary); if(!transformationDictionary.hasDefineFunctions() && !transformationDictionary.hasDerivedFields()){ pmml.setTransformationDictionary(null); } } } return parent; }
public LocalTransformations addDerivedFields(DerivedField... derivedFields) { getDerivedFields().addAll(Arrays.asList(derivedFields)); return this; }
@Override public VisitorAction accept(Visitor visitor) { VisitorAction status = visitor.visit(this); if (status == VisitorAction.CONTINUE) { visitor.pushParent(this); if ((status == VisitorAction.CONTINUE)&&hasExtensions()) { status = org.dmg.pmml.PMMLObject.traverse(visitor, getExtensions()); } if ((status == VisitorAction.CONTINUE)&&hasDerivedFields()) { status = org.dmg.pmml.PMMLObject.traverse(visitor, getDerivedFields()); } visitor.popParent(); } if (status == VisitorAction.TERMINATE) { return VisitorAction.TERMINATE; } return VisitorAction.CONTINUE; }
@Override public PMMLObject popParent(){ PMMLObject parent = super.popParent(); if(parent instanceof Model){ Model model = (Model)parent; LocalTransformations localTransformations = model.getLocalTransformations(); if(localTransformations != null){ processLocalTransformations(localTransformations); if(!localTransformations.hasDerivedFields()){ model.setLocalTransformations(null); } } } else if(parent instanceof PMML){ PMML pmml = (PMML)parent; TransformationDictionary transformationDictionary = pmml.getTransformationDictionary(); if(transformationDictionary != null){ processTransformationDictionary(transformationDictionary); if(!transformationDictionary.hasDefineFunctions() && !transformationDictionary.hasDerivedFields()){ pmml.setTransformationDictionary(null); } } } return parent; }
@Override public VisitorAction visit(LocalTransformations localTransformations){ if(localTransformations.hasDerivedFields()){ this.localDerivedFields.addAll(localTransformations.getDerivedFields()); } return super.visit(localTransformations); }
@Override public Map<FieldName, DerivedField> load(LocalTransformations localTransformations){ return IndexableUtil.buildMap(localTransformations.getDerivedFields()); } });
if(localTransformations != null && localTransformations.hasDerivedFields()){ this.localDerivedFields = CacheUtil.getValue(localTransformations, ModelEvaluator.localDerivedFieldCache);
/** * Create an instance of {@link LocalTransformations } * */ public LocalTransformations createLocalTransformations() { return new LocalTransformations(); }
@Override public LocalTransformations addExtensions(Extension... extensions) { getExtensions().addAll(Arrays.asList(extensions)); return this; }
private void processLocalTransformations(LocalTransformations localTransformations){ if(localTransformations.hasDerivedFields()){ List<DerivedField> derivedFields = localTransformations.getDerivedFields(); Set<DerivedField> activeDerivedFields = getActiveDerivedFields(new HashSet<>(derivedFields)); derivedFields.retainAll(activeDerivedFields); } }
public static Map<FieldName, DerivedField> getDerivedFieldMap(LocalTransformations localTransformations) { Map<FieldName, DerivedField> derivedFieldMap = new HashMap<FieldName, DerivedField>(); for(DerivedField derivedField: localTransformations.getDerivedFields()) { derivedFieldMap.put(derivedField.getName(), derivedField); } return derivedFieldMap; }
private void processLocalTransformations(LocalTransformations localTransformations){ if(localTransformations.hasDerivedFields()){ List<DerivedField> derivedFields = localTransformations.getDerivedFields(); Set<DerivedField> activeDerivedFields = getActiveDerivedFields(new HashSet<>(derivedFields)); derivedFields.retainAll(activeDerivedFields); } }
public static Map<FieldName, DerivedField> getDerivedFieldMap(LocalTransformations localTransformations) { Map<FieldName, DerivedField> derivedFieldMap = new HashMap<FieldName, DerivedField>(); for(DerivedField derivedField: localTransformations.getDerivedFields()) { derivedFieldMap.put(derivedField.getName(), derivedField); } return derivedFieldMap; }