当前位置: 首页>>代码示例>>Java>>正文


Java Predicate类代码示例

本文整理汇总了Java中org.dmg.pmml.Predicate的典型用法代码示例。如果您正苦于以下问题:Java Predicate类的具体用法?Java Predicate怎么用?Java Predicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Predicate类属于org.dmg.pmml包,在下文中一共展示了Predicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: evaluateNode

import org.dmg.pmml.Predicate; //导入依赖的package包/类
private Boolean evaluateNode(Trail trail, Node node, EvaluationContext context){
	EmbeddedModel embeddedModel = node.getEmbeddedModel();
	if(embeddedModel != null){
		throw new UnsupportedElementException(embeddedModel);
	}

	Predicate predicate = PredicateUtil.ensurePredicate(node);

	// A compound predicate whose boolean operator is "surrogate" represents a special case
	if(predicate instanceof CompoundPredicate){
		CompoundPredicate compoundPredicate = (CompoundPredicate)predicate;

		PredicateUtil.CompoundPredicateResult result = PredicateUtil.evaluateCompoundPredicateInternal(compoundPredicate, context);
		if(result.isAlternative()){
			trail.addMissingLevel();
		}

		return result.getResult();
	} else

	{
		return PredicateUtil.evaluate(predicate, context);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:25,代码来源:TreeModelEvaluator.java

示例2: transform

import org.dmg.pmml.Predicate; //导入依赖的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.Predicate; //导入依赖的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: handleNodePop

import org.dmg.pmml.Predicate; //导入依赖的package包/类
private void handleNodePop(Node node){
	Double recordCount = node.getRecordCount();
	String score = node.getScore();
	Predicate predicate = node.getPredicate();

	if(recordCount != null){
		node.setRecordCount(null);
	} // End if

	if(predicate instanceof True){
		Node parentNode = getParentNode();

		if(parentNode == null){
			return;
		}

		String parentScore = parentNode.getScore();
		if(parentScore != null){
			throw new IllegalArgumentException();
		}

		parentNode.setScore(score);

		List<Node> parentChildren = parentNode.getNodes();

		boolean success = parentChildren.remove(node);
		if(!success){
			throw new IllegalArgumentException();
		} // End if

		if(node.hasNodes()){
			List<Node> children = node.getNodes();

			parentChildren.addAll(children);
		}
	}
}
 
开发者ID:jpmml,项目名称:jpmml-lightgbm,代码行数:38,代码来源:TreeModelCompactor.java

示例5: buildPredicate

import org.dmg.pmml.Predicate; //导入依赖的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

示例6: handleNodePop

import org.dmg.pmml.Predicate; //导入依赖的package包/类
private void handleNodePop(Node node){
	String score = node.getScore();
	Predicate predicate = node.getPredicate();

	if(predicate instanceof True){
		Node parentNode = getParentNode();

		if(parentNode == null){
			return;
		}

		String parentScore = parentNode.getScore();
		if(parentScore != null){
			throw new IllegalArgumentException();
		}

		parentNode.setScore(score);

		List<Node> parentChildren = parentNode.getNodes();

		boolean success = parentChildren.remove(node);
		if(!success){
			throw new IllegalArgumentException();
		} // End if

		if(node.hasNodes()){
			List<Node> children = node.getNodes();

			parentChildren.addAll(children);
		}
	}
}
 
开发者ID:jpmml,项目名称:jpmml-xgboost,代码行数:33,代码来源:TreeModelCompactor.java

示例7: encodePredicate

import org.dmg.pmml.Predicate; //导入依赖的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

示例8: getFieldNamesFromNode

import org.dmg.pmml.Predicate; //导入依赖的package包/类
protected static void getFieldNamesFromNode(Set<String> fieldNames, Node startNode) {
    Predicate predicate = startNode.getPredicate();
    getFieldNamesFromPredicate(fieldNames, predicate);
    for (Node node : startNode.getNodes()) {
        getFieldNamesFromNode(fieldNames, node);
    }
}
 
开发者ID:brwe,项目名称:es-token-plugin,代码行数:8,代码来源:TreeModelFactory.java

示例9: getFieldNamesFromPredicate

import org.dmg.pmml.Predicate; //导入依赖的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

示例10: createSimpleSetPredicate

import org.dmg.pmml.Predicate; //导入依赖的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

示例11: createSimplePredicate

import org.dmg.pmml.Predicate; //导入依赖的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

示例12: getChildren

import org.dmg.pmml.Predicate; //导入依赖的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

示例13: checkPredicate

import org.dmg.pmml.Predicate; //导入依赖的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

示例14: encodePredicate

import org.dmg.pmml.Predicate; //导入依赖的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

示例15: ensurePredicate

import org.dmg.pmml.Predicate; //导入依赖的package包/类
static
public <E extends PMMLObject & HasPredicate<E>> Predicate ensurePredicate(E hasPredicate){
	Predicate predicate = hasPredicate.getPredicate();
	if(predicate == null){
		throw new MissingElementException(MissingElementException.formatMessage(XPathUtil.formatElement(hasPredicate.getClass()) + "/<Predicate>"), hasPredicate);
	}

	return predicate;
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:10,代码来源:PredicateUtil.java


注:本文中的org.dmg.pmml.Predicate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。