org.dmg.pmml.Visitor.applyTo()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(113)

本文整理了Java中org.dmg.pmml.Visitor.applyTo()方法的一些代码示例,展示了Visitor.applyTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Visitor.applyTo()方法的具体详情如下:
包路径:org.dmg.pmml.Visitor
类名称:Visitor
方法名:applyTo

Visitor.applyTo介绍

暂无

代码示例

代码示例来源:origin: jpmml/jpmml-model

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);
    }
  }
}

代码示例来源:origin: org.jpmml/pmml-model

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);
    }
  }
}

代码示例来源:origin: jpmml/jpmml-evaluator

static
protected void ensureValidity(PMMLObject object){
  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(object);
  }
}

代码示例来源:origin: jpmml/jpmml-lightgbm

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;
}

代码示例来源:origin: org.jpmml/pmml-evaluator-test

static
protected void ensureValidity(PMMLObject object){
  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(object);
  }
}

代码示例来源:origin: jpmml/jpmml-model

@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;
}

代码示例来源:origin: jpmml/jpmml-xgboost

/**
 * @see XGBoostUtil#toXGBoostSchema(Schema)
 */
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");
  if((Boolean.TRUE).equals(compact)){
    Visitor visitor = new TreeModelCompactor();
    visitor.applyTo(miningModel);
  }
  return miningModel;
}

代码示例来源:origin: org.jpmml/jpmml-xgboost

/**
 * @see XGBoostUtil#toXGBoostSchema(Schema)
 */
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");
  if((Boolean.TRUE).equals(compact)){
    Visitor visitor = new TreeModelCompactor();
    visitor.applyTo(miningModel);
  }
  return miningModel;
}

代码示例来源:origin: stackoverflow.com

PMML pmml = loadSasEmPMML()

Visitor invalidSubstringCorrector = new AbstractVisitor(){

  @Override
  public VisitorAction visit(Apply apply){
    if(isInvalidSubstring(apply)){
      List<Expression> expressions = apply.getExpressions();

      expressions.set(2, new FieldRef(new FieldName("FMTWIDTH")));
    }
    return super.visit(apply);
  }

  private boolean isInvalidSubstring(Apply apply){
    if(("substring").equals(apply.getFunction())){
      List<Expression> expressions = apply.getExpressions();

      Expression lengthArgument = expressions.get(2);
      if(lengthArgument instanceof Constant){
        Constant constant = (Constant)lengthArgument;
        return ("FMTWIDTH").equals(constant.getValue());
      }
    }
    return false;
  }
};

invalidSubstringCorrector.applyTo(pmml);

代码示例来源:origin: jpmml/jpmml-sparkml

Visitor visitor = new TreeModelCompactor();
visitor.applyTo(treeModel);

代码示例来源:origin: jpmml/jpmml-model

@Test
public void findChained() throws Exception {
  PMML pmml = ResourceUtil.unmarshal(ChainedSegmentationTest.class);
  Visitor visitor = new AbstractVisitor(){
    @Override
    public VisitorAction visit(Segment segment){
      Model model = segment.getModel();
      String id = segment.getId();
      if("first".equals(id)){
        checkFields(FieldNameUtil.create("x1_squared"), model);
      } else
      if("second".equals(id)){
        checkFields(FieldNameUtil.create("x2", "x2_squared"), model);
      } else
      if("third".equals(id)){
        checkFields(FieldNameUtil.create("x3"), model);
      } else
      if("sum".equals(id)){
        checkFields(FieldNameUtil.create("first_output", "second_output", "third_output"), model);
      } else
      {
        throw new AssertionError();
      }
      return super.visit(segment);
    }
  };
  visitor.applyTo(pmml);
}

代码示例来源:origin: jpmml/jpmml-evaluator

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.size() > 0){
    visitors.applyTo(pmml);
  }
  Model model = PMMLUtil.findModel(pmml, modelName);
  setPMML(pmml);
  setModel(model);
  return this;
}

代码示例来源:origin: jpmml/jpmml-model

miningModelVisitor.applyTo(pmml);
regressionModelVisitor.applyTo(pmml);

代码示例来源:origin: jpmml/jpmml-r

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(new True(), 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;
}

代码示例来源:origin: jpmml/jpmml-model

@Test
public void unmarshal() throws Exception {
  PMML pmml = ResourceUtil.unmarshal(InlineTableTest.class);
  Row row = getRow(pmml);
  List<?> content = row.getContent();
  assertEquals(9, content.size());
  Visitor visitor = new RowCleaner();
  visitor.applyTo(pmml);
  assertEquals(4, content.size());
  Object first = content.get(0);
  Object second = content.get(1);
  Object third = content.get(2);
  Object fourth = content.get(3);
  assertTrue(first instanceof Element);
  assertTrue(second instanceof InputCell);
  assertTrue(third instanceof OutputCell);
  assertTrue(fourth instanceof Element);
  assertEquals("0", ((InputCell)second).getValue());
  assertEquals("zero", ((OutputCell)third).getValue());
}

代码示例来源:origin: jpmml/jpmml-model

visitor.applyTo(pmml);

代码示例来源:origin: jpmml/jpmml-model

miningModelVisitor.applyTo(pmml);
regressionModelVisitor.applyTo(pmml);

代码示例来源:origin: jpmml/jpmml-model

visitor.applyTo(pmml);

代码示例来源:origin: jpmml/jpmml-model

visitor.applyTo(pmml);

代码示例来源:origin: jpmml/jpmml-model

visitor.applyTo(pmml);

相关文章