Java Code Examples for org.dmg.pmml.Interval#Closure
The following examples show how to use
org.dmg.pmml.Interval#Closure .
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: LightGBMUtil.java From jpmml-lightgbm with GNU Affero General Public License v3.0 | 5 votes |
static public Interval parseInterval(String string){ if(string.length() < 3){ throw new IllegalArgumentException(); } String bounds = string.substring(0, 1) + string.substring(string.length() - 1, string.length()); String margins = string.substring(1, string.length() - 1); Interval.Closure closure; switch(bounds){ case "[]": closure = Interval.Closure.CLOSED_CLOSED; break; default: throw new IllegalArgumentException(string); } String[] values = margins.split(":"); if(values.length != 2){ throw new IllegalArgumentException(margins); } Double leftMargin = Double.valueOf(values[0]); Double rightMargin = Double.valueOf(values[1]); Interval interval = new Interval(closure) .setLeftMargin(leftMargin) .setRightMargin(rightMargin); return interval; }
Example 2
Source File: DiscretizationUtilTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
static private Interval createInterval(Interval.Closure closure, Double leftMargin, Double rightMargin){ Interval result = new Interval(closure) .setLeftMargin(leftMargin) .setRightMargin(rightMargin); return result; }
Example 3
Source File: ModelUtil.java From openscoring with GNU Affero General Public License v3.0 | 5 votes |
static private <F extends org.dmg.pmml.Field<F> & HasContinuousDomain<F>> List<String> encodeContinuousDomain(F field){ if(field.hasIntervals()){ List<Interval> intervals = field.getIntervals(); Function<Interval, String> function = new Function<Interval, String>(){ @Override public String apply(Interval interval){ Number leftMargin = interval.getLeftMargin(); Number rightMargin = interval.getRightMargin(); String value = (leftMargin != null ? leftMargin : Double.NEGATIVE_INFINITY) + ", " + (rightMargin != null ? rightMargin : Double.POSITIVE_INFINITY); Interval.Closure closure = interval.getClosure(); switch(closure){ case OPEN_OPEN: return "(" + value + ")"; case OPEN_CLOSED: return "(" + value + "]"; case CLOSED_OPEN: return "[" + value + ")"; case CLOSED_CLOSED: return "[" + value + "]"; default: throw new IllegalArgumentException(); } } }; return intervals.stream() .map(function) .collect(Collectors.toList()); } return Collections.emptyList(); }
Example 4
Source File: DiscretizationUtil.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
static public Range<Double> toRange(Interval interval){ Double leftMargin = NumberUtil.asDouble(interval.getLeftMargin()); Double rightMargin = NumberUtil.asDouble(interval.getRightMargin()); // "The leftMargin and rightMargin attributes are optional, but at least one value must be defined" if(leftMargin == null && rightMargin == null){ throw new MissingAttributeException(interval, PMMLAttributes.INTERVAL_LEFTMARGIN); } // End if if(leftMargin != null && rightMargin != null && NumberUtil.compare(leftMargin, rightMargin) > 0){ throw new InvalidElementException(interval); } Interval.Closure closure = interval.getClosure(); if(closure == null){ throw new MissingAttributeException(interval, PMMLAttributes.INTERVAL_CLOSURE); } switch(closure){ case OPEN_OPEN: { if(leftMargin == null){ return Range.lessThan(rightMargin); } else if(rightMargin == null){ return Range.greaterThan(leftMargin); } return Range.open(leftMargin, rightMargin); } case OPEN_CLOSED: { if(leftMargin == null){ return Range.atMost(rightMargin); } else if(rightMargin == null){ return Range.greaterThan(leftMargin); } return Range.openClosed(leftMargin, rightMargin); } case CLOSED_OPEN: { if(leftMargin == null){ return Range.lessThan(rightMargin); } else if(rightMargin == null){ return Range.atLeast(leftMargin); } return Range.closedOpen(leftMargin, rightMargin); } case CLOSED_CLOSED: { if(leftMargin == null){ return Range.atMost(rightMargin); } else if(rightMargin == null){ return Range.atLeast(leftMargin); } return Range.closed(leftMargin, rightMargin); } default: throw new UnsupportedAttributeException(interval, closure); } }
Example 5
Source File: DiscretizationUtilTest.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
static private Range<Double> toRange(Interval.Closure closure, Double leftMargin, Double rightMargin){ return DiscretizationUtil.toRange(createInterval(closure, leftMargin, rightMargin)); }