Java Code Examples for org.jpmml.evaluator.FieldValueUtil#create()

The following examples show how to use org.jpmml.evaluator.FieldValueUtil#create() . 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: StandardDeviationFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public FieldValue evaluate(List<FieldValue> arguments){
	checkVariableArityArguments(arguments, 1, 2);

	Double result;

	if(arguments.size() > 1){
		result = evaluate(getRequiredArgument(arguments, 0).asCollection(), getRequiredArgument(arguments, 1).asBoolean());
	} else

	{
		result = evaluate(getRequiredArgument(arguments, 0).asCollection(), Boolean.FALSE);
	}

	return FieldValueUtil.create(TypeInfos.CONTINUOUS_DOUBLE, result);
}
 
Example 2
Source File: ArithmeticFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public FieldValue evaluate(FieldValue first, FieldValue second){

	// "If one of the input fields of a simple arithmetic function is a missing value, then the result evaluates to missing value"
	if(FieldValueUtil.isMissing(first) || FieldValueUtil.isMissing(second)){
		return FieldValues.MISSING_VALUE;
	}

	DataType dataType = TypeUtil.getCommonDataType(first.getDataType(), second.getDataType());

	Number result;

	try {
		result = evaluate(first.asNumber(), second.asNumber());
	} catch(ArithmeticException ae){
		throw new UndefinedResultException()
			.initCause(ae);
	}

	return FieldValueUtil.create(dataType, OpType.CONTINUOUS, result);
}
 
Example 3
Source File: AggregateMathFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public FieldValue evaluate(List<FieldValue> arguments){
	StorelessUnivariateStatistic statistic = createStatistic();

	DataType dataType = null;

	for(int i = 0; i < arguments.size(); i++){
		FieldValue value = getOptionalArgument(arguments, i);

		// "Missing values in the input to an aggregate function are simply ignored"
		if(FieldValueUtil.isMissing(value)){
			continue;
		}

		statistic.increment((value.asNumber()).doubleValue());

		if(dataType != null){
			dataType = TypeUtil.getCommonDataType(dataType, value.getDataType());
		} else

		{
			dataType = value.getDataType();
		}
	}

	// "If all inputs are missing, then the result evaluates to a missing value"
	if(statistic.getN() == 0){
		return FieldValues.MISSING_VALUE;
	}

	Double result = statistic.getResult();

	return FieldValueUtil.create(getResultDataType(dataType), OpType.CONTINUOUS, result);
}
 
Example 4
Source File: TrigonometricFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @param value Angle in radians.
 */
@Override
public FieldValue evaluate(FieldValue value){
	Double result = evaluate(value.asNumber());
	if(result.isNaN()){
		throw new NaNResultException();
	}

	return FieldValueUtil.create(TypeInfos.CONTINUOUS_DOUBLE, result);
}
 
Example 5
Source File: LogicalFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public FieldValue evaluate(List<FieldValue> arguments){
	checkVariableArityArguments(arguments, 2);

	Boolean result = getRequiredArgument(arguments, 0).asBoolean();

	for(int i = 1; i < arguments.size(); i++){
		result = evaluate(result, getRequiredArgument(arguments, i).asBoolean());
	}

	return FieldValueUtil.create(TypeInfos.CATEGORICAL_BOOLEAN, result);
}
 
Example 6
Source File: ValueSpaceFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
private FieldValue evaluate(FieldValue value, List<FieldValue> values){
	Boolean result;

	if(FieldValueUtil.isMissing(value)){
		result = evaluate(values.contains(FieldValues.MISSING_VALUE));
	} else

	{
		result = evaluate(value.isIn(values));
	}

	return FieldValueUtil.create(TypeInfos.CATEGORICAL_BOOLEAN, result);
}
 
Example 7
Source File: UnaryMathFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public FieldValue evaluate(FieldValue value){
	DataType dataType = value.getDataType();

	Number result = evaluate(value.asNumber());

	return FieldValueUtil.create(dataType, OpType.CONTINUOUS, result);
}
 
Example 8
Source File: DoubleUnaryMathFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public FieldValue evaluate(FieldValue value){
	Number result = evaluate(value.asNumber());

	return FieldValueUtil.create(TypeInfos.CONTINUOUS_DOUBLE, result);
}
 
Example 9
Source File: MeanFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public FieldValue evaluate(FieldValue value){
	Double result = evaluate(value.asCollection());

	return FieldValueUtil.create(TypeInfos.CONTINUOUS_DOUBLE, result);
}
 
Example 10
Source File: PercentileFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public FieldValue evaluate(FieldValue first, FieldValue second){
	Double result = evaluate(first.asCollection(), second.asInteger());

	return FieldValueUtil.create(TypeInfos.CONTINUOUS_DOUBLE, result);
}
 
Example 11
Source File: RoundingFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public FieldValue evaluate(FieldValue value){
	Number result = evaluate(value.asNumber());

	return FieldValueUtil.create(TypeInfos.CONTINUOUS_INTEGER, result);
}
 
Example 12
Source File: NearestNeighborModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public FieldValue prepare(Object value){
	return FieldValueUtil.create(TypeInfos.CATEGORICAL_STRING, value);
}
 
Example 13
Source File: UnaryStringFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public FieldValue evaluate(FieldValue value){
	String result = evaluate(value.asString());

	return FieldValueUtil.create(TypeInfos.CATEGORICAL_STRING, result);
}
 
Example 14
Source File: UnaryBooleanFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public FieldValue evaluate(FieldValue value){
	Boolean result = evaluate(value.asBoolean());

	return FieldValueUtil.create(TypeInfos.CATEGORICAL_BOOLEAN, result);
}
 
Example 15
Source File: EqualityFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public FieldValue evaluate(FieldValue first, FieldValue second){
	Boolean result = evaluate((first).equalsValue(second));

	return FieldValueUtil.create(TypeInfos.CATEGORICAL_BOOLEAN, result);
}
 
Example 16
Source File: ComparisonFunction.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public FieldValue evaluate(FieldValue first, FieldValue second){
	Boolean result = evaluate((first).compareToValue(second));

	return FieldValueUtil.create(TypeInfos.CATEGORICAL_BOOLEAN, result);
}
 
Example 17
Source File: NearestNeighborModelEvaluator.java    From jpmml-evaluator with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public FieldValue prepare(Object value){
	DerivedField derivedField = getDerivedField();
	MiningField miningField = getMiningField();

	if(miningField != null){
		return InputFieldUtil.prepareInputValue(derivedField, miningField, value);
	}

	TypeInfo typeInfo = new TypeInfo(){

		@Override
		public DataType getDataType(){
			DataType dataType = derivedField.getDataType();
			if(dataType == null){
				throw new MissingAttributeException(derivedField, org.dmg.pmml.PMMLAttributes.DERIVEDFIELD_DATATYPE);
			}

			return dataType;
		}

		@Override
		public OpType getOpType(){
			OpType opType = derivedField.getOpType();
			if(opType == null){
				throw new MissingAttributeException(derivedField, org.dmg.pmml.PMMLAttributes.DERIVEDFIELD_OPTYPE);
			}

			return opType;
		}

		@Override
		public List<?> getOrdering(){
			List<?> ordering = FieldUtil.getValidValues(derivedField);

			return ordering;
		}
	};

	return FieldValueUtil.create(typeInfo, value);
}