本文整理汇总了Java中org.dmg.pmml.SimplePredicate类的典型用法代码示例。如果您正苦于以下问题:Java SimplePredicate类的具体用法?Java SimplePredicate怎么用?Java SimplePredicate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimplePredicate类属于org.dmg.pmml包,在下文中一共展示了SimplePredicate类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: evaluateSurrogateCompoundPredicate
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
@Test
public void evaluateSurrogateCompoundPredicate(){
FieldName temperature = FieldName.create("temperature");
FieldName humidity = FieldName.create("humidity");
CompoundPredicate temperaturePredicate = new CompoundPredicate(CompoundPredicate.BooleanOperator.AND)
.addPredicates(
new SimplePredicate(temperature, SimplePredicate.Operator.LESS_THAN).setValue("90"),
new SimplePredicate(temperature, SimplePredicate.Operator.GREATER_THAN).setValue("50")
);
SimplePredicate humidityPredicate = new SimplePredicate(humidity, SimplePredicate.Operator.GREATER_OR_EQUAL).setValue("80");
CompoundPredicate compoundPredicate = new CompoundPredicate(CompoundPredicate.BooleanOperator.SURROGATE)
.addPredicates(temperaturePredicate, humidityPredicate);
assertEquals(Boolean.TRUE, evaluate(compoundPredicate, temperature, 70, humidity, null));
assertEquals(Boolean.FALSE, evaluate(compoundPredicate, temperature, 40, humidity, null));
assertEquals(Boolean.FALSE, evaluate(compoundPredicate, temperature, 100, humidity, null));
assertEquals(Boolean.TRUE, evaluate(compoundPredicate, temperature, null, humidity, 90));
assertEquals(Boolean.FALSE, evaluate(compoundPredicate, temperature, null, humidity, 70));
assertEquals(null, evaluate(compoundPredicate, temperature, null, humidity, null));
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:26,代码来源:PredicateUtilTest.java
示例2: transform
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
private Predicate transform(SimpleSetPredicate simpleSetPredicate){
Array array = simpleSetPredicate.getArray();
List<String> content = ArrayUtil.getContent(array);
if(content.size() != 1){
return simpleSetPredicate;
}
String value = content.get(0);
SimpleSetPredicate.BooleanOperator booleanOperator = simpleSetPredicate.getBooleanOperator();
switch(booleanOperator){
case IS_IN:
return createSimplePredicate(simpleSetPredicate.getField(), SimplePredicate.Operator.EQUAL, value);
case IS_NOT_IN:
return createSimplePredicate(simpleSetPredicate.getField(), SimplePredicate.Operator.NOT_EQUAL, value);
default:
break;
}
return simpleSetPredicate;
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:23,代码来源:PredicateTransformer.java
示例3: intern
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
public Predicate intern(Predicate predicate){
if(predicate instanceof SimplePredicate){
return intern((SimplePredicate)predicate);
} else
if(predicate instanceof SimpleSetPredicate){
return intern((SimpleSetPredicate)predicate);
} else
if(predicate instanceof True){
return intern((True)predicate);
} else
if(predicate instanceof False){
return intern((False)predicate);
}
return predicate;
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:21,代码来源:PredicateInterner.java
示例4: buildPredicate
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
private Predicate buildPredicate(Split split,
CategoricalValueEncodings categoricalValueEncodings) {
if (split == null) {
// Left child always applies, but is evaluated second
return new True();
}
int featureIndex = inputSchema.predictorToFeatureIndex(split.feature());
FieldName fieldName = FieldName.create(inputSchema.getFeatureNames().get(featureIndex));
if (split.featureType().equals(FeatureType.Categorical())) {
// Note that categories in MLlib model select the *left* child but the
// convention here will be that the predicate selects the *right* child
// So the predicate will evaluate "not in" this set
// More ugly casting
@SuppressWarnings("unchecked")
List<Double> javaCategories = (List<Double>) (List<?>)
JavaConversions.seqAsJavaList(split.categories());
Set<Integer> negativeEncodings = javaCategories.stream().map(Double::intValue).collect(Collectors.toSet());
Map<Integer,String> encodingToValue =
categoricalValueEncodings.getEncodingValueMap(featureIndex);
List<String> negativeValues = negativeEncodings.stream().map(encodingToValue::get).collect(Collectors.toList());
String joinedValues = TextUtils.joinPMMLDelimited(negativeValues);
return new SimpleSetPredicate(fieldName,
SimpleSetPredicate.BooleanOperator.IS_NOT_IN,
new Array(Array.Type.STRING, joinedValues));
} else {
// For MLlib, left means <= threshold, so right means >
return new SimplePredicate(fieldName, SimplePredicate.Operator.GREATER_THAN)
.setValue(Double.toString(split.threshold()));
}
}
开发者ID:oncewang,项目名称:oryx2,代码行数:36,代码来源:RDFUpdate.java
示例5: encodePredicate
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
static
private Predicate encodePredicate(Feature feature, Node node, boolean left){
FieldName name = feature.getName();
SimplePredicate.Operator operator;
String value;
if(feature instanceof BinaryFeature){
BinaryFeature binaryFeature = (BinaryFeature)feature;
operator = (left ? SimplePredicate.Operator.NOT_EQUAL : SimplePredicate.Operator.EQUAL);
value = binaryFeature.getValue();
} else
{
ContinuousFeature continuousFeature = feature.toContinuousFeature();
Number splitValue = Float.intBitsToFloat(node.split_cond());
DataType dataType = continuousFeature.getDataType();
switch(dataType){
case INTEGER:
splitValue = (int)(splitValue.floatValue() + 1f);
break;
case FLOAT:
break;
default:
throw new IllegalArgumentException();
}
operator = (left ? SimplePredicate.Operator.LESS_THAN : SimplePredicate.Operator.GREATER_OR_EQUAL);
value = ValueUtil.formatValue(splitValue);
}
SimplePredicate simplePredicate = new SimplePredicate(name, operator)
.setValue(value);
return simplePredicate;
}
开发者ID:jpmml,项目名称:jpmml-xgboost,代码行数:39,代码来源:RegTree.java
示例6: getFieldNamesFromPredicate
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
protected static void getFieldNamesFromPredicate(Set<String> fieldNames, Predicate predicate) {
if (predicate instanceof CompoundPredicate) {
List<Predicate> predicates = ((CompoundPredicate) predicate).getPredicates();
for (Predicate predicate1 : predicates) {
getFieldNamesFromPredicate(fieldNames, predicate1);
}
} else {
if (predicate instanceof SimplePredicate) {
fieldNames.add(((SimplePredicate) predicate).getField().getValue());
} else if (predicate instanceof SimpleSetPredicate) {
fieldNames.add(((SimpleSetPredicate) predicate).getField().getValue());
}
}
}
开发者ID:brwe,项目名称:es-token-plugin,代码行数:15,代码来源:TreeModelFactory.java
示例7: createSimpleSetPredicate
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
public Predicate createSimpleSetPredicate(Feature feature, List<String> values){
if(values.size() == 1){
String value = values.get(0);
return createSimplePredicate(feature, SimplePredicate.Operator.EQUAL, value);
}
Predicate predicate = new InternableSimpleSetPredicate()
.setField(feature.getName())
.setBooleanOperator(SimpleSetPredicate.BooleanOperator.IS_IN)
.setArray(createArray(feature.getDataType(), values));
return intern(predicate);
}
开发者ID:jpmml,项目名称:jpmml-converter,代码行数:16,代码来源:PredicateManager.java
示例8: createSimplePredicate
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
public Predicate createSimplePredicate(Feature feature, SimplePredicate.Operator operator, String value){
Predicate predicate = new InternableSimplePredicate()
.setField(feature.getName())
.setOperator(operator)
.setValue(value);
return intern(predicate);
}
开发者ID:jpmml,项目名称:jpmml-converter,代码行数:9,代码来源:PredicateManager.java
示例9: getChildren
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
static
private Iterator<Node> getChildren(Node node){
Predicate predicate = node.getPredicate();
if(!(predicate instanceof SimplePredicate)){
return null;
}
SimplePredicate simplePredicate = (SimplePredicate)predicate;
FieldName name = simplePredicate.getField();
SimplePredicate.Operator operator = simplePredicate.getOperator();
if(!(SimplePredicate.Operator.LESS_OR_EQUAL).equals(operator)){
return null;
} // End if
if(node.hasNodes()){
List<Node> children = node.getNodes();
int endPos = 0;
for(Node child : children){
if(!checkPredicate(child, name, operator)){
break;
}
endPos++;
}
if(endPos > 0){
return (children.subList(0, endPos)).iterator();
}
return null;
}
return null;
}
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:41,代码来源:TreeModelFlattener.java
示例10: checkPredicate
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
static
private boolean checkPredicate(Node node, FieldName name, SimplePredicate.Operator operator){
Predicate predicate = node.getPredicate();
if(predicate instanceof SimplePredicate){
SimplePredicate simplePredicate = (SimplePredicate)predicate;
return (simplePredicate.getField()).equals(name) && (simplePredicate.getOperator()).equals(operator);
}
return false;
}
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:13,代码来源:TreeModelFlattener.java
示例11: encodePredicate
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
static
private Predicate encodePredicate(Feature feature, Node node, boolean left){
FieldName name = feature.getName();
SimplePredicate.Operator operator;
String value;
if(feature instanceof BinaryFeature){
BinaryFeature binaryFeature = (BinaryFeature)feature;
operator = (left ? SimplePredicate.Operator.NOT_EQUAL : SimplePredicate.Operator.EQUAL);
value = binaryFeature.getValue();
} else
{
ContinuousFeature continuousFeature = feature.toContinuousFeature();
Number splitValue = node.getThreshold();
DataType dataType = continuousFeature.getDataType();
switch(dataType){
case INTEGER:
splitValue = (int)(splitValue.floatValue() + 1f);
break;
case FLOAT:
break;
default:
throw new IllegalArgumentException();
}
operator = (left ? SimplePredicate.Operator.LESS_OR_EQUAL : SimplePredicate.Operator.GREATER_THAN);
value = ValueUtil.formatValue(splitValue);
}
SimplePredicate simplePredicate = new SimplePredicate(name, operator)
.setValue(value);
return simplePredicate;
}
开发者ID:cheng-li,项目名称:pyramid,代码行数:39,代码来源:RegressionTree.java
示例12: evaluatePredicate
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
static
Boolean evaluatePredicate(Predicate predicate, EvaluationContext context){
if(predicate instanceof SimplePredicate){
return evaluateSimplePredicate((SimplePredicate)predicate, context);
} else
if(predicate instanceof SimpleSetPredicate){
return evaluateSimpleSetPredicate((SimpleSetPredicate)predicate, context);
} else
if(predicate instanceof CompoundPredicate){
return evaluateCompoundPredicate((CompoundPredicate)predicate, context);
} else
if(predicate instanceof True){
return evaluateTrue((True)predicate);
} else
if(predicate instanceof False){
return evaluateFalse((False)predicate);
} // End if
if(predicate instanceof JavaPredicate){
return evaluateJavaPredicate((JavaPredicate)predicate, context);
}
throw new UnsupportedElementException(predicate);
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:30,代码来源:PredicateUtil.java
示例13: createSimplePredicate
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
static
private SimplePredicate createSimplePredicate(FieldName field, SimplePredicate.Operator operator, String value){
SimplePredicate simplePredicate = new SimplePredicate(field, operator)
.setValue(value);
return simplePredicate;
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:8,代码来源:PredicateTransformer.java
示例14: internSimplePredicate
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
@Test
public void internSimplePredicate(){
FieldName name = FieldName.create("x");
Predicate left = new SimplePredicate(name, SimplePredicate.Operator.EQUAL)
.setValue("1");
Predicate right = new SimplePredicate(name, SimplePredicate.Operator.EQUAL)
.setValue("1");
checkTree(left, right);
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:13,代码来源:PredicateInternerTest.java
示例15: optimizeSimplePredicate
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
@Test
public void optimizeSimplePredicate(){
Predicate predicate = new SimplePredicate(FieldName.create("x"), SimplePredicate.Operator.EQUAL)
.setValue("1");
checkTree(predicate, HasParsedValue.class);
}
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:8,代码来源:PredicateOptimizerTest.java
示例16: buildDummyRegressionModel
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
public static PMML buildDummyRegressionModel() {
PMML pmml = PMMLUtils.buildSkeletonPMML();
List<DataField> dataFields = new ArrayList<>();
dataFields.add(new DataField(FieldName.create("foo"), OpType.CONTINUOUS, DataType.DOUBLE));
dataFields.add(new DataField(FieldName.create("bar"), OpType.CONTINUOUS, DataType.DOUBLE));
DataDictionary dataDictionary =
new DataDictionary(dataFields).setNumberOfFields(dataFields.size());
pmml.setDataDictionary(dataDictionary);
List<MiningField> miningFields = new ArrayList<>();
MiningField predictorMF = new MiningField(FieldName.create("foo"))
.setOpType(OpType.CONTINUOUS)
.setUsageType(MiningField.UsageType.ACTIVE)
.setImportance(0.5);
miningFields.add(predictorMF);
MiningField targetMF = new MiningField(FieldName.create("bar"))
.setOpType(OpType.CONTINUOUS)
.setUsageType(MiningField.UsageType.PREDICTED);
miningFields.add(targetMF);
MiningSchema miningSchema = new MiningSchema(miningFields);
double dummyCount = 2.0;
Node rootNode = new Node().setId("r").setRecordCount(dummyCount).setPredicate(new True());
double halfCount = dummyCount / 2;
Node left = new Node()
.setId("r-")
.setRecordCount(halfCount)
.setPredicate(new True())
.setScore("-2.0");
Node right = new Node().setId("r+").setRecordCount(halfCount)
.setPredicate(new SimplePredicate(FieldName.create("foo"),
SimplePredicate.Operator.GREATER_THAN).setValue("3.14"))
.setScore("2.0");
rootNode.addNodes(right, left);
TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, miningSchema, rootNode)
.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT)
.setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD)
.setMiningSchema(miningSchema);
pmml.addModels(treeModel);
return pmml;
}
开发者ID:oncewang,项目名称:oryx2,代码行数:49,代码来源:RDFPMMLUtilsTest.java
示例17: handleNodePush
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
private void handleNodePush(Node node){
String id = node.getId();
String score = node.getScore();
if(id == null){
throw new IllegalArgumentException();
} // End if
if(node.hasNodes()){
List<Node> children = node.getNodes();
if(children.size() != 2 || score != null){
throw new IllegalArgumentException();
}
Node firstChild = children.get(0);
Node secondChild = children.get(1);
SimplePredicate firstPredicate = (SimplePredicate)firstChild.getPredicate();
SimplePredicate secondPredicate = (SimplePredicate)secondChild.getPredicate();
if(!(firstPredicate.getField()).equals(secondPredicate.getField()) || !(firstPredicate.getValue()).equals(secondPredicate.getValue())){
throw new IllegalArgumentException();
} // End if
if((SimplePredicate.Operator.NOT_EQUAL).equals(firstPredicate.getOperator()) && (SimplePredicate.Operator.EQUAL).equals(secondPredicate.getOperator())){
children.remove(0);
children.add(1, firstChild);
firstChild = children.get(0);
secondChild = children.get(1);
} else
if((SimplePredicate.Operator.LESS_OR_EQUAL).equals(firstPredicate.getOperator()) && (SimplePredicate.Operator.GREATER_THAN).equals(secondPredicate.getOperator())){
// Ignored
} else
{
throw new IllegalArgumentException();
}
secondChild.setPredicate(new True());
} else
{
if(score == null){
throw new IllegalArgumentException();
}
}
node.setId(null);
}
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:53,代码来源:TreeModelCompactor.java
示例18: encodeNode
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
private void encodeNode(Node node, RGenericVector tree, Schema schema){
RIntegerVector nodeId = (RIntegerVector)tree.getValue("nodeID");
RBooleanVector terminal = (RBooleanVector)tree.getValue("terminal");
RGenericVector psplit = (RGenericVector)tree.getValue("psplit");
RGenericVector ssplits = (RGenericVector)tree.getValue("ssplits");
RDoubleVector prediction = (RDoubleVector)tree.getValue("prediction");
RGenericVector left = (RGenericVector)tree.getValue("left");
RGenericVector right = (RGenericVector)tree.getValue("right");
node.setId(String.valueOf(nodeId.asScalar()));
if((Boolean.TRUE).equals(terminal.asScalar())){
node = encodeScore(node, prediction, schema);
return;
}
RNumberVector<?> splitpoint = (RNumberVector<?>)psplit.getValue("splitpoint");
RStringVector variableName = (RStringVector)psplit.getValue("variableName");
if(ssplits.size() > 0){
throw new IllegalArgumentException();
}
Predicate leftPredicate;
Predicate rightPredicate;
FieldName name = FieldName.create(variableName.asScalar());
Integer index = this.featureIndexes.get(name);
if(index == null){
throw new IllegalArgumentException();
}
Feature feature = schema.getFeature(index);
if(feature instanceof CategoricalFeature){
CategoricalFeature categoricalFeature = (CategoricalFeature)feature;
List<String> values = categoricalFeature.getValues();
List<Integer> splitValues = (List<Integer>)splitpoint.getValues();
leftPredicate = createSimpleSetPredicate(categoricalFeature, selectValues(values, splitValues, true));
rightPredicate = createSimpleSetPredicate(categoricalFeature, selectValues(values, splitValues, false));
} else
{
ContinuousFeature continuousFeature = feature.toContinuousFeature();
String value = ValueUtil.formatValue((Double)splitpoint.asScalar());
leftPredicate = createSimplePredicate(continuousFeature, SimplePredicate.Operator.LESS_OR_EQUAL, value);
rightPredicate = createSimplePredicate(continuousFeature, SimplePredicate.Operator.GREATER_THAN, value);
}
Node leftChild = new Node()
.setPredicate(leftPredicate);
encodeNode(leftChild, left, schema);
Node rightChild = new Node()
.setPredicate(rightPredicate);
encodeNode(rightChild, right, schema);
node.addNodes(leftChild, rightChild);
}
开发者ID:jpmml,项目名称:jpmml-r,代码行数:68,代码来源:BinaryTreeConverter.java
示例19: encodeNode
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
private <P extends Number> void encodeNode(Node node, int i, ScoreEncoder<P> scoreEncoder, List<? extends Number> leftDaughter, List<? extends Number> rightDaughter, List<? extends Number> bestvar, List<Double> xbestsplit, List<P> nodepred, Schema schema){
Predicate leftPredicate;
Predicate rightPredicate;
int var = ValueUtil.asInt(bestvar.get(i));
if(var != 0){
Feature feature = schema.getFeature(var - 1);
Double split = xbestsplit.get(i);
if(feature instanceof BooleanFeature){
BooleanFeature booleanFeature = (BooleanFeature)feature;
if(split != 0.5d){
throw new IllegalArgumentException();
}
leftPredicate = createSimplePredicate(booleanFeature, SimplePredicate.Operator.EQUAL, booleanFeature.getValue(0));
rightPredicate = createSimplePredicate(booleanFeature, SimplePredicate.Operator.EQUAL, booleanFeature.getValue(1));
} else
if(feature instanceof CategoricalFeature){
CategoricalFeature categoricalFeature = (CategoricalFeature)feature;
List<String> values = categoricalFeature.getValues();
leftPredicate = createSimpleSetPredicate(categoricalFeature, selectValues(values, split, true));
rightPredicate = createSimpleSetPredicate(categoricalFeature, selectValues(values, split, false));
} else
{
ContinuousFeature continuousFeature = feature.toContinuousFeature();
String value = ValueUtil.formatValue(split);
leftPredicate = createSimplePredicate(continuousFeature, SimplePredicate.Operator.LESS_OR_EQUAL, value);
rightPredicate = createSimplePredicate(continuousFeature, SimplePredicate.Operator.GREATER_THAN, value);
}
} else
{
P prediction = nodepred.get(i);
node.setScore(scoreEncoder.encode(prediction));
return;
}
int left = ValueUtil.asInt(leftDaughter.get(i));
if(left != 0){
Node leftChild = new Node()
.setId(String.valueOf(left))
.setPredicate(leftPredicate);
encodeNode(leftChild, left - 1, scoreEncoder, leftDaughter, rightDaughter, bestvar, xbestsplit, nodepred, schema);
node.addNodes(leftChild);
}
int right = ValueUtil.asInt(rightDaughter.get(i));
if(right != 0){
Node rightChild = new Node()
.setId(String.valueOf(right))
.setPredicate(rightPredicate);
encodeNode(rightChild, right - 1, scoreEncoder, leftDaughter, rightDaughter, bestvar, xbestsplit, nodepred, schema);
node.addNodes(rightChild);
}
}
开发者ID:jpmml,项目名称:jpmml-r,代码行数:71,代码来源:RandomForestConverter.java
示例20: createSimplePredicate
import org.dmg.pmml.SimplePredicate; //导入依赖的package包/类
public Predicate createSimplePredicate(Feature feature, SimplePredicate.Operator operator, String value){
PredicateManager predicateManager = getPredicateManager();
return predicateManager.createSimplePredicate(feature, operator, value);
}
开发者ID:jpmml,项目名称:jpmml-r,代码行数:6,代码来源:TreeModelConverter.java
注:本文中的org.dmg.pmml.SimplePredicate类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论