org.dmg.pmml.NormContinuous Java Examples
The following examples show how to use
org.dmg.pmml.NormContinuous.
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: NormalizationUtilTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 6 votes |
@Test public void normalizeOutliers(){ NormContinuous normContinuous = createNormContinuous(); assertEquals(interpolate(-1d, BEGIN, MIDPOINT), (double)NormalizationUtil.normalize(normContinuous, -1d), 1e-8); assertEquals(interpolate(12.2d, MIDPOINT, END), (double)NormalizationUtil.normalize(normContinuous, 12.2d), 1e-8); normContinuous.setOutliers(OutlierTreatmentMethod.AS_MISSING_VALUES); assertNull(NormalizationUtil.normalize(normContinuous, -1d)); assertNull(NormalizationUtil.normalize(normContinuous, 12.2d)); normContinuous.setOutliers(OutlierTreatmentMethod.AS_EXTREME_VALUES); assertEquals(BEGIN[1], (double)NormalizationUtil.normalize(normContinuous, -1d), 1e-8); assertEquals(END[1], (double)NormalizationUtil.normalize(normContinuous, 12.2d), 1e-8); }
Example #2
Source File: NormalizationUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
static public Number normalize(NormContinuous normContinuous, Number value){ Value<Double> doubleValue = new DoubleValue(value); doubleValue = normalize(normContinuous, doubleValue); if(doubleValue == null){ return null; } return doubleValue.getValue(); }
Example #3
Source File: NormalizationUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
static public Number denormalize(NormContinuous normContinuous, Number value){ Value<Double> doubleValue = new DoubleValue(value); doubleValue = denormalize(normContinuous, doubleValue); return doubleValue.getValue(); }
Example #4
Source File: NormalizationUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
static private List<LinearNorm> ensureLinearNorms(NormContinuous normContinuous){ if(!normContinuous.hasLinearNorms()){ throw new MissingElementException(normContinuous, PMMLElements.NORMCONTINUOUS_LINEARNORMS); } List<LinearNorm> linearNorms = normContinuous.getLinearNorms(); if(linearNorms.size() < 2){ throw new InvalidElementListException(linearNorms); } return linearNorms; }
Example #5
Source File: ExpressionUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
static public FieldValue evaluateNormContinuous(NormContinuous normContinuous, EvaluationContext context){ FieldValue value = context.evaluate(ensureField(normContinuous)); if(FieldValueUtil.isMissing(value)){ return FieldValueUtil.create(TypeInfos.CONTINUOUS_DOUBLE, normContinuous.getMapMissingTo()); } return NormalizationUtil.normalize(normContinuous, value); }
Example #6
Source File: ExpressionUtilTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Test public void evaluateNormContinuous(){ FieldName name = FieldName.create("x"); NormContinuous normContinuous = new NormContinuous(name, null) .setMapMissingTo(5d); assertEquals(5d, evaluate(normContinuous, name, null)); }
Example #7
Source File: NormalizationUtilTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Test public void normalize(){ NormContinuous normContinuous = createNormContinuous(); assertEquals(BEGIN[1], (double)NormalizationUtil.normalize(normContinuous, BEGIN[0]), 1e-8); assertEquals(interpolate(1.212d, BEGIN, MIDPOINT), (double)NormalizationUtil.normalize(normContinuous, 1.212d), 1e-8); assertEquals(MIDPOINT[1], (double)NormalizationUtil.normalize(normContinuous, MIDPOINT[0]), 1e-8); assertEquals(interpolate(6.5d, MIDPOINT, END), (double)NormalizationUtil.normalize(normContinuous, 6.5d), 1e-8); assertEquals(END[1], (double)NormalizationUtil.normalize(normContinuous, END[0]), 1e-8); }
Example #8
Source File: NormalizationUtilTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Test public void denormalize(){ NormContinuous normContinuous = createNormContinuous(); assertEquals(BEGIN[0], (double)NormalizationUtil.denormalize(normContinuous, BEGIN[1]), 1e-8); assertEquals(0.3d, (double)NormalizationUtil.denormalize(normContinuous, interpolate(0.3d, BEGIN, MIDPOINT)), 1e-8); assertEquals(MIDPOINT[0], (double)NormalizationUtil.denormalize(normContinuous, MIDPOINT[1]), 1e-8); assertEquals(7.123d, (double)NormalizationUtil.denormalize(normContinuous, interpolate(7.123d, MIDPOINT, END)), 1e-8); assertEquals(END[0], (double)NormalizationUtil.denormalize(normContinuous, END[1]), 1e-8); }
Example #9
Source File: NormalizationUtilTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
static private NormContinuous createNormContinuous(){ NormContinuous result = new NormContinuous(FieldName.create("x"), null) .addLinearNorms( new LinearNorm(BEGIN[0], BEGIN[1]), new LinearNorm(MIDPOINT[0], MIDPOINT[1]), new LinearNorm(END[0], END[1]) ); return result; }
Example #10
Source File: FieldReferenceFinder.java From jpmml-model with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public VisitorAction visit(NormContinuous normContinuous){ process(normContinuous.getField()); return super.visit(normContinuous); }
Example #11
Source File: NormalizationUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
static public FieldValue normalize(NormContinuous normContinuous, FieldValue value){ Number result = normalize(normContinuous, value.asNumber()); return FieldValueUtil.create(TypeInfos.CONTINUOUS_DOUBLE, result); }
Example #12
Source File: NormalizationUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
static public <V extends Number> Value<V> denormalize(NormContinuous normContinuous, Value<V> value){ List<LinearNorm> linearNorms = ensureLinearNorms(normContinuous); LinearNorm start = linearNorms.get(0); LinearNorm end = linearNorms.get(linearNorms.size() - 1); Number startNorm = start.getNorm(); if(startNorm == null){ throw new MissingAttributeException(start, PMMLAttributes.LINEARNORM_NORM); } Number endNorm = end.getNorm(); if(endNorm == null){ throw new MissingAttributeException(end, PMMLAttributes.LINEARNORM_NORM); } for(int i = 1, max = (linearNorms.size() - 1); i < max; i++){ LinearNorm linearNorm = linearNorms.get(i); Number norm = linearNorm.getNorm(); if(norm == null){ throw new MissingAttributeException(linearNorm, PMMLAttributes.LINEARNORM_NORM); } // End if if(value.compareTo(norm) >= 0){ start = linearNorm; startNorm = norm; } else if(value.compareTo(norm) <= 0){ end = linearNorm; endNorm = norm; break; } } Number startOrig = start.getOrig(); if(startOrig == null){ throw new MissingAttributeException(start, PMMLAttributes.LINEARNORM_ORIG); } Number endOrig = end.getOrig(); if(endOrig == null){ throw new MissingAttributeException(end, PMMLAttributes.LINEARNORM_ORIG); } return value.denormalize(startOrig, startNorm, endOrig, endNorm); }
Example #13
Source File: ExpressionUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
static FieldValue evaluateExpression(Expression expression, EvaluationContext context){ if(expression instanceof Constant){ return evaluateConstant((Constant)expression); } else if(expression instanceof FieldRef){ return evaluateFieldRef((FieldRef)expression, context); } else if(expression instanceof NormContinuous){ return evaluateNormContinuous((NormContinuous)expression, context); } else if(expression instanceof NormDiscrete){ return evaluateNormDiscrete((NormDiscrete)expression, context); } else if(expression instanceof Discretize){ return evaluateDiscretize((Discretize)expression, context); } else if(expression instanceof MapValues){ return evaluateMapValues((MapValues)expression, context); } else if(expression instanceof TextIndex){ return evaluateTextIndex((TextIndex)expression, context); } else if(expression instanceof Apply){ return evaluateApply((Apply)expression, context); } else if(expression instanceof Aggregate){ return evaluateAggregate((Aggregate)expression, context); } // End if if(expression instanceof JavaExpression){ return evaluateJavaExpression((JavaExpression)expression, context); } throw new UnsupportedElementException(expression); }