org.dmg.pmml.Visitor Java Examples
The following examples show how to use
org.dmg.pmml.Visitor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RandomForestConverter.java From jpmml-r with GNU Affero General Public License v3.0 | 6 votes |
private <P extends Number> TreeModel encodeTreeModel(MiningFunction miningFunction, ScoreEncoder<P> scoreEncoder, List<? extends Number> leftDaughter, List<? extends Number> rightDaughter, List<P> nodepred, List<? extends Number> bestvar, List<Double> xbestsplit, Schema schema){ RGenericVector randomForest = getObject(); Node root = encodeNode(True.INSTANCE, 0, scoreEncoder, leftDaughter, rightDaughter, bestvar, xbestsplit, nodepred, new CategoryManager(), schema); TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root) .setMissingValueStrategy(TreeModel.MissingValueStrategy.NULL_PREDICTION) .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT); if(this.compact){ Visitor visitor = new RandomForestCompactor(); visitor.applyTo(treeModel); } return treeModel; }
Example #2
Source File: JavaModel.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 6 votes |
@Override public VisitorAction accept(Visitor visitor){ VisitorAction status = visitor.visit(this); if(status == VisitorAction.CONTINUE){ visitor.pushParent(this); status = PMMLObject.traverse(visitor, getMiningSchema(), getOutput(), getModelStats(), getModelExplanation(), getTargets(), getLocalTransformations(), getModelVerification()); visitor.popParent(); } // End if if(status == VisitorAction.TERMINATE){ return VisitorAction.TERMINATE; } return VisitorAction.CONTINUE; }
Example #3
Source File: GBDT.java From jpmml-lightgbm with GNU Affero General Public License v3.0 | 5 votes |
public MiningModel encodeMiningModel(Map<String, ?> options, Schema schema){ Boolean compact = (Boolean)options.get(HasLightGBMOptions.OPTION_COMPACT); Integer numIterations = (Integer)options.get(HasLightGBMOptions.OPTION_NUM_ITERATION); MiningModel miningModel = this.object_function_.encodeMiningModel(Arrays.asList(this.models_), numIterations, schema) .setAlgorithmName("LightGBM"); if((Boolean.TRUE).equals(compact)){ Visitor visitor = new TreeModelCompactor(); visitor.applyTo(miningModel); } return miningModel; }
Example #4
Source File: Learner.java From jpmml-xgboost with GNU Affero General Public License v3.0 | 5 votes |
public MiningModel encodeMiningModel(Map<String, ?> options, Schema schema){ Boolean compact = (Boolean)options.get(HasXGBoostOptions.OPTION_COMPACT); Integer ntreeLimit = (Integer)options.get(HasXGBoostOptions.OPTION_NTREE_LIMIT); MiningModel miningModel = this.gbtree.encodeMiningModel(this.obj, this.base_score, ntreeLimit, schema) .setAlgorithmName("XGBoost (" + this.gbtree.getAlgorithmName() + ")"); if((Boolean.TRUE).equals(compact)){ Visitor visitor = new TreeModelCompactor(); visitor.applyTo(miningModel); } return miningModel; }
Example #5
Source File: FunctionExpression.java From jpmml-r with GNU Affero General Public License v3.0 | 5 votes |
@Override public VisitorAction accept(Visitor visitor){ VisitorAction status = visitor.visit(this); if(status == VisitorAction.CONTINUE){ visitor.pushParent(this); if(hasArguments()){ List<Argument> arguments = getArguments(); for(Argument argument : arguments){ status = PMMLObject.traverse(visitor, argument.getExpression()); if(status != VisitorAction.CONTINUE){ break; } } } visitor.popParent(); } // End if if(status == VisitorAction.TERMINATE){ return VisitorAction.TERMINATE; } return VisitorAction.CONTINUE; }
Example #6
Source File: VisitorBattery.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void applyTo(Visitable visitable){ List<Class<? extends Visitor>> visitorClazzes = this; for(Class<? extends Visitor> visitorClazz : visitorClazzes){ Visitor visitor; try { visitor = visitorClazz.newInstance(); } catch(ReflectiveOperationException roe){ throw new RuntimeException(roe); } visitor.applyTo(visitable); } }
Example #7
Source File: SimpleNode.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public VisitorAction accept(Visitor visitor){ VisitorAction status = visitor.visit(this); if(status == VisitorAction.CONTINUE){ visitor.pushParent(this); if(status == VisitorAction.CONTINUE && hasExtensions()){ status = PMMLObject.traverse(visitor, getExtensions()); } // End if if(status == VisitorAction.CONTINUE){ status = PMMLObject.traverse(visitor, getPredicate(), getPartition()); } // End if if(status == VisitorAction.CONTINUE && hasScoreDistributions()){ status = PMMLObject.traverse(visitor, getScoreDistributions()); } // End if if(status == VisitorAction.CONTINUE && hasNodes()){ status = PMMLObject.traverse(visitor, getNodes()); } // End if if(status == VisitorAction.CONTINUE){ status = PMMLObject.traverse(visitor, getEmbeddedModel()); } visitor.popParent(); } // End if if(status == VisitorAction.TERMINATE){ return VisitorAction.TERMINATE; } return VisitorAction.CONTINUE; }
Example #8
Source File: CopyExample.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public PMML transform(PMML pmml) throws Exception { if(this.summary){ printSummary(pmml); } List<String> visitorClasses = this.visitorClasses; for(String visitorClass : visitorClasses){ Class<?> clazz = Class.forName(visitorClass); long begin = System.currentTimeMillis(); Visitor visitor = (Visitor)clazz.newInstance(); visitor.applyTo(pmml); long end = System.currentTimeMillis(); System.out.println("Applied " + clazz.getName() + " in " + (end - begin) + " ms."); if(this.summary){ printSummary(pmml); } } return pmml; }
Example #9
Source File: JavaExpression.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Override public VisitorAction accept(Visitor visitor){ VisitorAction status = visitor.visit(this); if(status == VisitorAction.CONTINUE){ visitor.pushParent(this); visitor.popParent(); } // End if if(status == VisitorAction.TERMINATE){ return VisitorAction.TERMINATE; } return VisitorAction.CONTINUE; }
Example #10
Source File: JavaPredicate.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Override public VisitorAction accept(Visitor visitor){ VisitorAction status = visitor.visit(this); if(status == VisitorAction.CONTINUE){ visitor.pushParent(this); visitor.popParent(); } // End if if(status == VisitorAction.TERMINATE){ return VisitorAction.TERMINATE; } return VisitorAction.CONTINUE; }
Example #11
Source File: LoadingModelEvaluatorBuilder.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
public LoadingModelEvaluatorBuilder load(InputStream is, String modelName) throws SAXException, JAXBException { Schema schema = getSchema(); ValidationEventHandler validationEventHandler = getValidationEventHandler(); List<? extends XMLFilter> filters = getFilters(); boolean locatable = getLocatable(); VisitorBattery visitors = getVisitors(); Unmarshaller unmarshaller = JAXBUtil.createUnmarshaller(); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(validationEventHandler); if(filters == null){ filters = Collections.singletonList(new ImportFilter()); } Source source = SAXUtil.createFilteredSource(is, filters.toArray(new XMLFilter[filters.size()])); PMML pmml = (PMML)unmarshaller.unmarshal(source); Visitor locatorHandler = (locatable ? new LocatorTransformer() : new LocatorNullifier()); locatorHandler.applyTo(pmml); if(visitors != null && !visitors.isEmpty()){ visitors.applyTo(pmml); } Model model = PMMLUtil.findModel(pmml, modelName); setPMML(pmml); setModel(model); return this; }
Example #12
Source File: IntegrationTestBatch.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
protected void validatePMML(PMML pmml) throws Exception { List<Visitor> visitors = Arrays.<Visitor>asList( new UnsupportedMarkupInspector(), new InvalidMarkupInspector(){ @Override public VisitorAction visit(Application application){ String name = application.getName(); if(name == null){ return VisitorAction.SKIP; } return super.visit(application); } @Override public VisitorAction visit(MiningSchema miningSchema){ if(!miningSchema.hasMiningFields()){ return VisitorAction.SKIP; } return super.visit(miningSchema); } } ); for(Visitor visitor : visitors){ visitor.applyTo(pmml); } }
Example #13
Source File: GBDT.java From jpmml-lightgbm with GNU Affero General Public License v3.0 | 4 votes |
public PMML encodePMML(Map<String, ?> options, FieldName targetField, List<String> targetCategories){ LightGBMEncoder encoder = new LightGBMEncoder(); Boolean nanAsMissing = (Boolean)options.get(HasLightGBMOptions.OPTION_NAN_AS_MISSING); Schema schema = encodeSchema(targetField, targetCategories, encoder); MiningModel miningModel = encodeMiningModel(options, schema); PMML pmml = encoder.encodePMML(miningModel); if((Boolean.TRUE).equals(nanAsMissing)){ Visitor visitor = new NaNAsMissingDecorator(); visitor.applyTo(pmml); } return pmml; }
Example #14
Source File: VariableField.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Override public VisitorAction accept(Visitor visitor){ throw new UnsupportedOperationException(); }
Example #15
Source File: Openscoring.java From openscoring with GNU Affero General Public License v3.0 | 4 votes |
static private LoadingModelEvaluatorBuilder createLoadingModelEvaluatorBuilder(Config config){ Config modelEvaluatorBuilderConfig = config.getConfig("modelEvaluatorBuilder"); LoadingModelEvaluatorBuilder modelEvaluatorBuilder = new LoadingModelEvaluatorBuilder(); Class<? extends ModelEvaluatorFactory> modelEvaluatorFactoryClazz = loadClass(ModelEvaluatorFactory.class, modelEvaluatorBuilderConfig); modelEvaluatorBuilder.setModelEvaluatorFactory(newInstance(modelEvaluatorFactoryClazz)); Class<? extends ValueFactoryFactory> valueFactoryFactoryClazz = loadClass(ValueFactoryFactory.class, modelEvaluatorBuilderConfig); modelEvaluatorBuilder.setValueFactoryFactory(newInstance(valueFactoryFactoryClazz)); modelEvaluatorBuilder.setOutputFilter(OutputFilters.KEEP_FINAL_RESULTS); // Jackson does not support the JSON serialization of <code>null</code> map keys ResultMapper resultMapper = new ResultMapper(){ private FieldName defaultTargetName = FieldName.create(ModelResponse.DEFAULT_TARGET_NAME); @Override public FieldName apply(FieldName name){ // A "phantom" default target field if(name == null){ return this.defaultTargetName; } return name; } }; modelEvaluatorBuilder.setResultMapper(resultMapper); boolean validate = modelEvaluatorBuilderConfig.getBoolean("validate"); if(validate){ Schema schema; try { schema = JAXBUtil.getSchema(); } catch(SAXException | IOException e){ throw new RuntimeException(e); } modelEvaluatorBuilder .setSchema(schema) .setValidationEventHandler(new SimpleValidationEventHandler()); } boolean locatable = modelEvaluatorBuilderConfig.getBoolean("locatable"); modelEvaluatorBuilder.setLocatable(locatable); VisitorBattery visitors = new VisitorBattery(); List<String> visitorClassNames = modelEvaluatorBuilderConfig.getStringList("visitorClasses"); for(String visitorClassName : visitorClassNames){ Class<?> clazz = loadClass(Object.class, visitorClassName); if((Visitor.class).isAssignableFrom(clazz)){ Class<? extends Visitor> visitorClazz = clazz.asSubclass(Visitor.class); visitors.add(visitorClazz); } else if((VisitorBattery.class).isAssignableFrom(clazz)){ Class<? extends VisitorBattery> visitorBatteryClazz = clazz.asSubclass(VisitorBattery.class); VisitorBattery visitorBattery = newInstance(visitorBatteryClazz); visitors.addAll(visitorBattery); } else { throw new IllegalArgumentException(new ClassCastException(clazz.toString())); } } modelEvaluatorBuilder.setVisitors(visitors); return modelEvaluatorBuilder; }