org.apache.commons.math3.geometry.euclidean.oned.Interval Java Examples

The following examples show how to use org.apache.commons.math3.geometry.euclidean.oned.Interval. 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: ExtendedRandomTreeTest.java    From AILibs with GNU Affero General Public License v3.0 6 votes vote down vote up
private double singleOptimaRun(final int plusMinus, final double startX, final Interval range) {
	double lower = range.getInf();
	double upper = range.getSup();
	double currentX = startX;
	double currentGrad = this.grad.apply(currentX);
	double nextX = currentX;
	double nextGrad = currentGrad;
	int runs = 0;
	while (runs < maxRuns && this.nextRunFitsANegativeUpdate(nextX, lower) && this.nextRunFitsAPositiveUpdate(nextX, upper) && !this.gradIsCloseToZero(nextGrad)) {
		currentX = nextX;
		currentGrad = nextGrad;
		int gradientSignum = currentGrad < 0 ? -1 : +1;
		nextX = currentX + (plusMinus * gradientSignum * gradientDescentStepSize);
		nextGrad = this.grad.apply(currentX);
		runs++;
	}
	// either of the conditions is met
	return this.fun.apply(currentX);
}
 
Example #2
Source File: PolygonsSet.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Add he contribution of a boundary facet.
 * @param sub boundary facet
 * @param reversed if true, the facet has the inside on its plus side
 */
private void addContribution(final SubHyperplane<Euclidean2D> sub, final boolean reversed) {
    @SuppressWarnings("unchecked")
    final AbstractSubHyperplane<Euclidean2D, Euclidean1D> absSub =
        (AbstractSubHyperplane<Euclidean2D, Euclidean1D>) sub;
    final Line line      = (Line) sub.getHyperplane();
    final List<Interval> intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList();
    for (final Interval i : intervals) {
        final Vector2D start = Double.isInfinite(i.getLower()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getLower()));
        final Vector2D end   = Double.isInfinite(i.getUpper()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getUpper()));
        if (reversed) {
            sorted.insert(new ComparableSegment(end, start, line.getReverse()));
        } else {
            sorted.insert(new ComparableSegment(start, end, line));
        }
    }
}
 
Example #3
Source File: SubLine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Get the endpoints of the sub-line.
 * <p>
 * A subline may be any arbitrary number of disjoints segments, so the endpoints
 * are provided as a list of endpoint pairs. Each element of the list represents
 * one segment, and each segment contains a start point at index 0 and an end point
 * at index 1. If the sub-line is unbounded in the negative infinity direction,
 * the start point of the first segment will have infinite coordinates. If the
 * sub-line is unbounded in the positive infinity direction, the end point of the
 * last segment will have infinite coordinates. So a sub-line covering the whole
 * line will contain just one row and both elements of this row will have infinite
 * coordinates. If the sub-line is empty, the returned list will contain 0 segments.
 * </p>
 * @return list of segments endpoints
 */
public List<Segment> getSegments() {

    final Line line = (Line) getHyperplane();
    final List<Interval> list = ((IntervalsSet) getRemainingRegion()).asList();
    final List<Segment> segments = new ArrayList<Segment>();

    for (final Interval interval : list) {
        final Vector2D start = line.toSpace(new Vector1D(interval.getLower()));
        final Vector2D end   = line.toSpace(new Vector1D(interval.getUpper()));
        segments.add(new Segment(start, end, line));
    }

    return segments;

}
 
Example #4
Source File: PolygonsSet.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Add he contribution of a boundary facet.
 * @param sub boundary facet
 * @param reversed if true, the facet has the inside on its plus side
 */
private void addContribution(final SubHyperplane<Euclidean2D> sub, final boolean reversed) {
    @SuppressWarnings("unchecked")
    final AbstractSubHyperplane<Euclidean2D, Euclidean1D> absSub =
        (AbstractSubHyperplane<Euclidean2D, Euclidean1D>) sub;
    final Line line      = (Line) sub.getHyperplane();
    final List<Interval> intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList();
    for (final Interval i : intervals) {
        final Vector2D start = Double.isInfinite(i.getInf()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getInf()));
        final Vector2D end   = Double.isInfinite(i.getSup()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getSup()));
        if (reversed) {
            sorted.insert(new ComparableSegment(end, start, line.getReverse()));
        } else {
            sorted.insert(new ComparableSegment(start, end, line));
        }
    }
}
 
Example #5
Source File: DiscretizationHelper.java    From AILibs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Creates an equal size policy for the given values with respect to the given
 * number of categories. An equal size policy is a policy where the length of
 * the intervals is chosen such that in each interval there are equally many
 * values.
 *
 * @param numericValues
 *            Distinct attribute values in ascending order
 * @param numberOfCategories
 *            Number of categories
 * @return The created discretization policy consisting of one interval per
 *         category
 */
public AttributeDiscretizationPolicy equalSizePolicy(final List<Double> numericValues, final int numberOfCategories) {
	if (numericValues.isEmpty()) {
		throw new IllegalArgumentException("No values provided");
	}

	List<Interval> intervals = new ArrayList<>();
	int stepwidth = numericValues.size() / numberOfCategories;
	int limit = Math.min(numberOfCategories, numericValues.size());

	for (int i = 0; i < limit; i++) {
		int lower = i * stepwidth;
		int upper;
		if (i == limit - 1) {
			// Take the rest of the values
			upper = numericValues.size() - 1;
		} else {
			upper = ((i + 1) * stepwidth) - 1;
		}
		intervals.add(new Interval(numericValues.get(lower), numericValues.get(upper)));
	}

	return new AttributeDiscretizationPolicy(intervals);
}
 
Example #6
Source File: Util.java    From AILibs with GNU Affero General Public License v3.0 6 votes vote down vote up
public static List<Interval> refineOnLinearScale(final Interval interval, final int maxNumberOfSubIntervals, final double minimumLengthOfIntervals) {
	double min = interval.getInf();
	double max = interval.getSup();
	double length = max - min;
	List<Interval> intervals = new ArrayList<>();

	/* if no refinement is possible, return just the interval itself */
	if (length <= minimumLengthOfIntervals) {
		intervals.add(interval);
		return intervals;
	}

	/* otherwise compute the sub-intervals */
	int numberOfIntervals = Math.min((int) Math.ceil(length / minimumLengthOfIntervals), maxNumberOfSubIntervals);
	double stepSize = length / numberOfIntervals;
	for (int i = 0; i < numberOfIntervals; i++) {
		intervals.add(new Interval(min + i * stepSize, min + ((i + 1) * stepSize)));
	}
	return intervals;
}
 
Example #7
Source File: PolygonsSet.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Add he contribution of a boundary facet.
 * @param sub boundary facet
 * @param reversed if true, the facet has the inside on its plus side
 */
private void addContribution(final SubHyperplane<Euclidean2D> sub, final boolean reversed) {
    @SuppressWarnings("unchecked")
    final AbstractSubHyperplane<Euclidean2D, Euclidean1D> absSub =
        (AbstractSubHyperplane<Euclidean2D, Euclidean1D>) sub;
    final Line line      = (Line) sub.getHyperplane();
    final List<Interval> intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList();
    for (final Interval i : intervals) {
        final Vector2D start = Double.isInfinite(i.getInf()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getInf()));
        final Vector2D end   = Double.isInfinite(i.getSup()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getSup()));
        if (reversed) {
            sorted.insert(new ComparableSegment(end, start, line.getReverse()));
        } else {
            sorted.insert(new ComparableSegment(start, end, line));
        }
    }
}
 
Example #8
Source File: SubLine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Get the endpoints of the sub-line.
 * <p>
 * A subline may be any arbitrary number of disjoints segments, so the endpoints
 * are provided as a list of endpoint pairs. Each element of the list represents
 * one segment, and each segment contains a start point at index 0 and an end point
 * at index 1. If the sub-line is unbounded in the negative infinity direction,
 * the start point of the first segment will have infinite coordinates. If the
 * sub-line is unbounded in the positive infinity direction, the end point of the
 * last segment will have infinite coordinates. So a sub-line covering the whole
 * line will contain just one row and both elements of this row will have infinite
 * coordinates. If the sub-line is empty, the returned list will contain 0 segments.
 * </p>
 * @return list of segments endpoints
 */
public List<Segment> getSegments() {

    final Line line = (Line) getHyperplane();
    final List<Interval> list = ((IntervalsSet) getRemainingRegion()).asList();
    final List<Segment> segments = new ArrayList<Segment>(list.size());

    for (final Interval interval : list) {
        final Vector2D start = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getInf()));
        final Vector2D end   = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getSup()));
        segments.add(new Segment(start, end, line));
    }

    return segments;

}
 
Example #9
Source File: SubLine_s.java    From coming with MIT License 6 votes vote down vote up
/** Get the endpoints of the sub-line.
 * <p>
 * A subline may be any arbitrary number of disjoints segments, so the endpoints
 * are provided as a list of endpoint pairs. Each element of the list represents
 * one segment, and each segment contains a start point at index 0 and an end point
 * at index 1. If the sub-line is unbounded in the negative infinity direction,
 * the start point of the first segment will have infinite coordinates. If the
 * sub-line is unbounded in the positive infinity direction, the end point of the
 * last segment will have infinite coordinates. So a sub-line covering the whole
 * line will contain just one row and both elements of this row will have infinite
 * coordinates. If the sub-line is empty, the returned list will contain 0 segments.
 * </p>
 * @return list of segments endpoints
 */
public List<Segment> getSegments() {

    final Line line = (Line) getHyperplane();
    final List<Interval> list = ((IntervalsSet) getRemainingRegion()).asList();
    final List<Segment> segments = new ArrayList<Segment>();

    for (final Interval interval : list) {
        final Vector2D start = line.toSpace(new Vector1D(interval.getInf()));
        final Vector2D end   = line.toSpace(new Vector1D(interval.getSup()));
        segments.add(new Segment(start, end, line));
    }

    return segments;

}
 
Example #10
Source File: Util.java    From AILibs with GNU Affero General Public License v3.0 6 votes vote down vote up
private static String getParamValue(final Parameter p, final String assignedValue, final boolean resolveIntervals) {
	if (assignedValue == null) {
		throw new IllegalArgumentException("Cannot determine true value for assigned param value " + assignedValue + " for parameter " + p.getName());
	}
	String interpretedValue = "";
	if (p.isNumeric()) {
		if (resolveIntervals) {
			NumericParameterDomain np = (NumericParameterDomain) p.getDefaultDomain();
			List<String> vals = SetUtil.unserializeList(assignedValue);
			Interval interval = new Interval(Double.valueOf(vals.get(0)), Double.valueOf(vals.get(1)));
			if (np.isInteger()) {
				interpretedValue = String.valueOf((int) Math.round(interval.getBarycenter()));
			} else {
				interpretedValue = String.valueOf(interval.checkPoint((double) p.getDefaultValue(), 0.001) == Location.INSIDE ? (double) p.getDefaultValue() : interval.getBarycenter());
			}
		} else {
			interpretedValue = assignedValue;
		}
	} else if (p.getDefaultDomain() instanceof CategoricalParameterDomain) {
		interpretedValue = assignedValue;
	} else {
		throw new UnsupportedOperationException("No support for parameters of type " + p.getClass().getName());
	}
	return interpretedValue;
}
 
Example #11
Source File: Math_32_PolygonsSet_s.java    From coming with MIT License 6 votes vote down vote up
/** Add he contribution of a boundary facet.
 * @param sub boundary facet
 * @param reversed if true, the facet has the inside on its plus side
 */
private void addContribution(final SubHyperplane<Euclidean2D> sub, final boolean reversed) {
    @SuppressWarnings("unchecked")
    final AbstractSubHyperplane<Euclidean2D, Euclidean1D> absSub =
        (AbstractSubHyperplane<Euclidean2D, Euclidean1D>) sub;
    final Line line      = (Line) sub.getHyperplane();
    final List<Interval> intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList();
    for (final Interval i : intervals) {
        final Vector2D start = Double.isInfinite(i.getLower()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getLower()));
        final Vector2D end   = Double.isInfinite(i.getUpper()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getUpper()));
        if (reversed) {
            sorted.insert(new ComparableSegment(end, start, line.getReverse()));
        } else {
            sorted.insert(new ComparableSegment(start, end, line));
        }
    }
}
 
Example #12
Source File: NPEfix15_fifteen_t.java    From coming with MIT License 6 votes vote down vote up
/** Get the endpoints of the sub-line.
 * <p>
 * A subline may be any arbitrary number of disjoints segments, so the endpoints
 * are provided as a list of endpoint pairs. Each element of the list represents
 * one segment, and each segment contains a start point at index 0 and an end point
 * at index 1. If the sub-line is unbounded in the negative infinity direction,
 * the start point of the first segment will have infinite coordinates. If the
 * sub-line is unbounded in the positive infinity direction, the end point of the
 * last segment will have infinite coordinates. So a sub-line covering the whole
 * line will contain just one row and both elements of this row will have infinite
 * coordinates. If the sub-line is empty, the returned list will contain 0 segments.
 * </p>
 * @return list of segments endpoints
 */
public List<Segment> getSegments() {

    final Line line = (Line) getHyperplane();
    final List<Interval> list = ((IntervalsSet) getRemainingRegion()).asList();
    final List<Segment> segments = new ArrayList<Segment>();

    for (final Interval interval : list) {
        final Vector2D start = line.toSpace(new Vector1D(interval.getInf()));
        final Vector2D end   = line.toSpace(new Vector1D(interval.getSup()));
        segments.add(new Segment(start, end, line));
    }

    return segments;

}
 
Example #13
Source File: SubLine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Get the endpoints of the sub-line.
 * <p>
 * A subline may be any arbitrary number of disjoints segments, so the endpoints
 * are provided as a list of endpoint pairs. Each element of the list represents
 * one segment, and each segment contains a start point at index 0 and an end point
 * at index 1. If the sub-line is unbounded in the negative infinity direction,
 * the start point of the first segment will have infinite coordinates. If the
 * sub-line is unbounded in the positive infinity direction, the end point of the
 * last segment will have infinite coordinates. So a sub-line covering the whole
 * line will contain just one row and both elements of this row will have infinite
 * coordinates. If the sub-line is empty, the returned list will contain 0 segments.
 * </p>
 * @return list of segments endpoints
 */
public List<Segment> getSegments() {

    final Line line = (Line) getHyperplane();
    final List<Interval> list = ((IntervalsSet) getRemainingRegion()).asList();
    final List<Segment> segments = new ArrayList<Segment>();

    for (final Interval interval : list) {
        final Vector2D start = line.toSpace(new Vector1D(interval.getLower()));
        final Vector2D end   = line.toSpace(new Vector1D(interval.getUpper()));
        segments.add(new Segment(start, end, line));
    }

    return segments;

}
 
Example #14
Source File: NPEfix11_eleven_t.java    From coming with MIT License 6 votes vote down vote up
/** Add the contribution of a boundary facet.
 * @param sub boundary facet
 * @param reversed if true, the facet has the inside on its plus side
 */
private void addContribution(final SubHyperplane<Euclidean2D> sub, final boolean reversed) {
    @SuppressWarnings("unchecked")
    final AbstractSubHyperplane<Euclidean2D, Euclidean1D> absSub =
            (AbstractSubHyperplane<Euclidean2D, Euclidean1D>) sub;
    final Line line      = (Line) sub.getHyperplane();
    final List<Interval> intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList();
    for (final Interval i : intervals) {
        final Vector2D start = Double.isInfinite(i.getInf()) ?
                null : (Vector2D) line.toSpace((Point<Euclidean1D>) new Vector1D(i.getInf()));
        final Vector2D end   = Double.isInfinite(i.getSup()) ?
                null : (Vector2D) line.toSpace((Point<Euclidean1D>) new Vector1D(i.getSup()));
        if (reversed) {
            sorted.insert(new ComparableSegment(end, start, line.getReverse()));
        } else {
            sorted.insert(new ComparableSegment(start, end, line));
        }
    }
}
 
Example #15
Source File: SubLine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Get the endpoints of the sub-line.
 * <p>
 * A subline may be any arbitrary number of disjoints segments, so the endpoints
 * are provided as a list of endpoint pairs. Each element of the list represents
 * one segment, and each segment contains a start point at index 0 and an end point
 * at index 1. If the sub-line is unbounded in the negative infinity direction,
 * the start point of the first segment will have infinite coordinates. If the
 * sub-line is unbounded in the positive infinity direction, the end point of the
 * last segment will have infinite coordinates. So a sub-line covering the whole
 * line will contain just one row and both elements of this row will have infinite
 * coordinates. If the sub-line is empty, the returned list will contain 0 segments.
 * </p>
 * @return list of segments endpoints
 */
public List<Segment> getSegments() {

    final Line line = (Line) getHyperplane();
    final List<Interval> list = ((IntervalsSet) getRemainingRegion()).asList();
    final List<Segment> segments = new ArrayList<Segment>(list.size());

    for (final Interval interval : list) {
        final Vector2D start = line.toSpace(new Vector1D(interval.getInf()));
        final Vector2D end   = line.toSpace(new Vector1D(interval.getSup()));
        segments.add(new Segment(start, end, line));
    }

    return segments;

}
 
Example #16
Source File: SubLine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Get the endpoints of the sub-line.
 * <p>
 * A subline may be any arbitrary number of disjoints segments, so the endpoints
 * are provided as a list of endpoint pairs. Each element of the list represents
 * one segment, and each segment contains a start point at index 0 and an end point
 * at index 1. If the sub-line is unbounded in the negative infinity direction,
 * the start point of the first segment will have infinite coordinates. If the
 * sub-line is unbounded in the positive infinity direction, the end point of the
 * last segment will have infinite coordinates. So a sub-line covering the whole
 * line will contain just one row and both elements of this row will have infinite
 * coordinates. If the sub-line is empty, the returned list will contain 0 segments.
 * </p>
 * @return list of segments endpoints
 */
public List<Segment> getSegments() {

    final Line line = (Line) getHyperplane();
    final List<Interval> list = ((IntervalsSet) getRemainingRegion()).asList();
    final List<Segment> segments = new ArrayList<Segment>(list.size());

    for (final Interval interval : list) {
        final Vector2D start = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getInf()));
        final Vector2D end   = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getSup()));
        segments.add(new Segment(start, end, line));
    }

    return segments;

}
 
Example #17
Source File: RQPHelper.java    From AILibs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Maps the WEKA query to a tree-friendly query while also preserving the header
 * information of the query, this is important for M5 trees.
 *
 * @param data
 * @return
 */
public static final IntervalAndHeader mapWEKAToTree(final Instance data) {
	Interval[] mappedData = new Interval[data.numAttributes() / 2];
	int counter = 0;
	ArrayList<Attribute> attributes = new ArrayList<>();
	attributes.add(new Attribute("bias"));
	for (int attrNum = 0; attrNum < data.numAttributes(); attrNum = attrNum + 2) {
		mappedData[counter] = new Interval(data.value(attrNum), data.value(attrNum + 1));
		attributes.add(new Attribute("xVal" + counter));
		counter++;
	}
	Instances header = new Instances("queriedInterval", attributes, 2);
	header.setClassIndex(-1);
	return new IntervalAndHeader(mappedData, header);

}
 
Example #18
Source File: ExtendedM5TreeTest.java    From AILibs with GNU Affero General Public License v3.0 6 votes vote down vote up
private double singleOptimaRun(final int plusMinus, final double startX, final Interval range) {
	double lower = range.getInf();
	double upper = range.getSup();
	double currentX = startX;
	double currentGrad = this.grad.apply(currentX);
	double nextX = currentX;
	double nextGrad = currentGrad;
	int runs = 0;
	// System.out.println("Random start point is " + startX + ", seraching for max:"
	// + (plusMinus == +1));
	while (runs < maxRuns && this.nextRunFitsANegativeUpdate(nextX, lower) && this.nextRunFitsAPositiveUpdate(nextX, upper) && !this.gradIsCloseToZero(nextGrad)) {
		currentX = nextX;
		currentGrad = nextGrad;
		int gradientSignum = currentGrad < 0 ? -1 : +1;
		nextX = currentX + (plusMinus * gradientSignum * gradientDescentStepSize);
		nextGrad = this.grad.apply(currentX);
		runs++;
	}
	// System.out.println("Returning with X:" + currentX + ", grad:" + currentGrad +
	// " f(X):" + fun.apply(currentX));
	// either of the conditions is met
	return this.fun.apply(currentX);
}
 
Example #19
Source File: ExtendedRandomTreeTest.java    From AILibs with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Test the classifier without any cross-validation
 * @throws IOException
 */
@Test
public void testPredict() throws IOException {
	try (BufferedReader reader = Files.newBufferedReader(Paths.get(testFile), StandardCharsets.UTF_8)) {
		ArffReader arffReader = new ArffReader(reader);
		Instances data = arffReader.getData();
		for (Instance instance : data) {
			// construct the real interval
			double lower = instance.value(data.numAttributes() - 1);
			double upper = instance.value(data.numAttributes() - 2);
			Instance strippedInstance = new DenseInstance(data.numAttributes() - 2);
			for (int i = 0; i < data.numAttributes() - 2; i++) {
				strippedInstance.setValue(i, instance.value(i));
			}
			Interval actualInterval = new Interval(upper, lower);
			Interval predictedInterval = this.classifier.predictInterval(strippedInstance);
			System.out.println("Actual interval: " + actualInterval + ", predicted Interval " + predictedInterval);
		}

	}
}
 
Example #20
Source File: SubLine.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Get the endpoints of the sub-line.
 * <p>
 * A subline may be any arbitrary number of disjoints segments, so the endpoints
 * are provided as a list of endpoint pairs. Each element of the list represents
 * one segment, and each segment contains a start point at index 0 and an end point
 * at index 1. If the sub-line is unbounded in the negative infinity direction,
 * the start point of the first segment will have infinite coordinates. If the
 * sub-line is unbounded in the positive infinity direction, the end point of the
 * last segment will have infinite coordinates. So a sub-line covering the whole
 * line will contain just one row and both elements of this row will have infinite
 * coordinates. If the sub-line is empty, the returned list will contain 0 segments.
 * </p>
 * @return list of segments endpoints
 */
public List<Segment> getSegments() {

    final Line line = (Line) getHyperplane();
    final List<Interval> list = ((IntervalsSet) getRemainingRegion()).asList();
    final List<Segment> segments = new ArrayList<Segment>();

    for (final Interval interval : list) {
        final Vector2D start = line.toSpace(new Vector1D(interval.getInf()));
        final Vector2D end   = line.toSpace(new Vector1D(interval.getSup()));
        segments.add(new Segment(start, end, line));
    }

    return segments;

}
 
Example #21
Source File: jKali_0010_s.java    From coming with MIT License 6 votes vote down vote up
/** Add he contribution of a boundary facet.
 * @param sub boundary facet
 * @param reversed if true, the facet has the inside on its plus side
 */
private void addContribution(final SubHyperplane<Euclidean2D> sub, final boolean reversed) {
    @SuppressWarnings("unchecked")
    final AbstractSubHyperplane<Euclidean2D, Euclidean1D> absSub =
        (AbstractSubHyperplane<Euclidean2D, Euclidean1D>) sub;
    final Line line      = (Line) sub.getHyperplane();
    final List<Interval> intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList();
    for (final Interval i : intervals) {
        final Vector2D start = Double.isInfinite(i.getLower()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getLower()));
        final Vector2D end   = Double.isInfinite(i.getUpper()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getUpper()));
        if (reversed) {
            sorted.insert(new ComparableSegment(end, start, line.getReverse()));
        } else {
            sorted.insert(new ComparableSegment(start, end, line));
        }
    }
}
 
Example #22
Source File: PolygonsSet.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Add he contribution of a boundary facet.
 * @param sub boundary facet
 * @param reversed if true, the facet has the inside on its plus side
 */
private void addContribution(final SubHyperplane<Euclidean2D> sub, final boolean reversed) {
    @SuppressWarnings("unchecked")
    final AbstractSubHyperplane<Euclidean2D, Euclidean1D> absSub =
        (AbstractSubHyperplane<Euclidean2D, Euclidean1D>) sub;
    final Line line      = (Line) sub.getHyperplane();
    final List<Interval> intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList();
    for (final Interval i : intervals) {
        final Vector2D start = Double.isInfinite(i.getInf()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getInf()));
        final Vector2D end   = Double.isInfinite(i.getSup()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getSup()));
        if (reversed) {
            sorted.insert(new ComparableSegment(end, start, line.getReverse()));
        } else {
            sorted.insert(new ComparableSegment(start, end, line));
        }
    }
}
 
Example #23
Source File: Elixir_0023_s.java    From coming with MIT License 6 votes vote down vote up
/** Add he contribution of a boundary facet.
 * @param sub boundary facet
 * @param reversed if true, the facet has the inside on its plus side
 */
private void addContribution(final SubHyperplane<Euclidean2D> sub, final boolean reversed) {
    @SuppressWarnings("unchecked")
    final AbstractSubHyperplane<Euclidean2D, Euclidean1D> absSub =
        (AbstractSubHyperplane<Euclidean2D, Euclidean1D>) sub;
    final Line line      = (Line) sub.getHyperplane();
    final List<Interval> intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList();
    for (final Interval i : intervals) {
        final Vector2D start = Double.isInfinite(i.getLower()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getLower()));
        final Vector2D end   = Double.isInfinite(i.getUpper()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getUpper()));
        if (reversed) {
            sorted.insert(new ComparableSegment(end, start, line.getReverse()));
        } else {
            sorted.insert(new ComparableSegment(start, end, line));
        }
    }
}
 
Example #24
Source File: NPEfix11_eleven_s.java    From coming with MIT License 6 votes vote down vote up
/** Add the contribution of a boundary facet.
 * @param sub boundary facet
 * @param reversed if true, the facet has the inside on its plus side
 */
private void addContribution(final SubHyperplane<Euclidean2D> sub, final boolean reversed) {
    @SuppressWarnings("unchecked")
    final AbstractSubHyperplane<Euclidean2D, Euclidean1D> absSub =
            (AbstractSubHyperplane<Euclidean2D, Euclidean1D>) sub;
    final Line line      = (Line) sub.getHyperplane();
    final List<Interval> intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList();
    for (final Interval i : intervals) {
        final Vector2D start = Double.isInfinite(i.getInf()) ?
                null : (Vector2D) line.toSpace((Point<Euclidean1D>) new Vector1D(i.getInf()));
        final Vector2D end   = Double.isInfinite(i.getSup()) ?
                null : (Vector2D) line.toSpace((Point<Euclidean1D>) new Vector1D(i.getSup()));
        if (reversed) {
            sorted.insert(new ComparableSegment(end, start, line.getReverse()));
        } else {
            sorted.insert(new ComparableSegment(start, end, line));
        }
    }
}
 
Example #25
Source File: PolygonsSet.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Add he contribution of a boundary facet.
 * @param sub boundary facet
 * @param reversed if true, the facet has the inside on its plus side
 */
private void addContribution(final SubHyperplane<Euclidean2D> sub, final boolean reversed) {
    @SuppressWarnings("unchecked")
    final AbstractSubHyperplane<Euclidean2D, Euclidean1D> absSub =
        (AbstractSubHyperplane<Euclidean2D, Euclidean1D>) sub;
    final Line line      = (Line) sub.getHyperplane();
    final List<Interval> intervals = ((IntervalsSet) absSub.getRemainingRegion()).asList();
    for (final Interval i : intervals) {
        final Vector2D start = Double.isInfinite(i.getLower()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getLower()));
        final Vector2D end   = Double.isInfinite(i.getUpper()) ?
                              null : (Vector2D) line.toSpace(new Vector1D(i.getUpper()));
        if (reversed) {
            sorted.insert(new ComparableSegment(end, start, line.getReverse()));
        } else {
            sorted.insert(new ComparableSegment(start, end, line));
        }
    }
}
 
Example #26
Source File: NPEfix15_fifteen_s.java    From coming with MIT License 6 votes vote down vote up
/** Get the endpoints of the sub-line.
 * <p>
 * A subline may be any arbitrary number of disjoints segments, so the endpoints
 * are provided as a list of endpoint pairs. Each element of the list represents
 * one segment, and each segment contains a start point at index 0 and an end point
 * at index 1. If the sub-line is unbounded in the negative infinity direction,
 * the start point of the first segment will have infinite coordinates. If the
 * sub-line is unbounded in the positive infinity direction, the end point of the
 * last segment will have infinite coordinates. So a sub-line covering the whole
 * line will contain just one row and both elements of this row will have infinite
 * coordinates. If the sub-line is empty, the returned list will contain 0 segments.
 * </p>
 * @return list of segments endpoints
 */
public List<Segment> getSegments() {

    final Line line = (Line) getHyperplane();
    final List<Interval> list = ((IntervalsSet) getRemainingRegion()).asList();
    final List<Segment> segments = new ArrayList<Segment>();

    for (final Interval interval : list) {
        final Vector2D start = line.toSpace(new Vector1D(interval.getInf()));
        final Vector2D end   = line.toSpace(new Vector1D(interval.getSup()));
        segments.add(new Segment(start, end, line));
    }

    return segments;

}
 
Example #27
Source File: IsValidParameterRangeRefinementPredicate.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
private Collection<List<ConstantParam>> getGroundingsForIntervals(final List<Interval> refinements, final List<ConstantParam> partialGrounding) {
	List<String> paramValues = new ArrayList<>();
	for (Interval oracledInterval : refinements) {
		paramValues.add("[" + oracledInterval.getInf() + ", " + oracledInterval.getSup() + "]");
	}
	return this.getGroundingsForOracledValues(paramValues, partialGrounding);
}
 
Example #28
Source File: ExtendedM5TreeTest.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
private double getOptima(final int plusMinus, final Interval xInterval) {
	// strategy: gradient descent pick 10 random start points got into the negative
	// direction until either a local optima has been reached(gradient close enough
	// to 0), or, an upper/lower bound has been reached.
	double[] randomStart = new double[randomStarts];
	for (int i = 0; i < randomStarts; i++) {
		randomStart[i] = Math.random() * (xInterval.getSup() - xInterval.getInf()) + xInterval.getInf();
	}
	if (plusMinus == +1) {
		return Arrays.stream(randomStart).mapToObj(x -> this.singleOptimaRun(plusMinus, x, xInterval)).max(Double::compare).orElseThrow(() -> new IllegalStateException());
	} else {
		return Arrays.stream(randomStart).mapToObj(x -> this.singleOptimaRun(plusMinus, x, xInterval)).min(Double::compare).orElseThrow(() -> new IllegalStateException());
	}

}
 
Example #29
Source File: ExtendedRandomTreeTest.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
private double getOptima(final int plusMinus, final Interval xInterval) {
	// strategy: gradient descent pick 10 random start points got into the negative
	// direction until either a local optima has been reached(gradient close enough
	// to 0), or, an upper/lower bound has been reached.
	double[] randomStart = new double[randomStarts];
	for (int i = 0; i < randomStarts; i++) {
		randomStart[i] = Math.random() * (xInterval.getSup() - xInterval.getInf()) + xInterval.getInf();
	}
	if (plusMinus == +1) {
		return Arrays.stream(randomStart).mapToObj(x -> this.singleOptimaRun(plusMinus, x, xInterval)).max(Double::compare).orElseThrow(() -> new IllegalStateException());
	} else {
		return Arrays.stream(randomStart).mapToObj(x -> this.singleOptimaRun(plusMinus, x, xInterval)).min(Double::compare).orElseThrow(() -> new IllegalStateException());
	}

}
 
Example #30
Source File: IntervalsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testMultiple() {
    RegionFactory<Euclidean1D> factory = new RegionFactory<Euclidean1D>();
    IntervalsSet set = (IntervalsSet)
    factory.intersection(factory.union(factory.difference(new IntervalsSet(1.0, 6.0, 1.0e-10),
                                                          new IntervalsSet(3.0, 5.0, 1.0e-10)),
                                                          new IntervalsSet(9.0, Double.POSITIVE_INFINITY, 1.0e-10)),
                                                          new IntervalsSet(Double.NEGATIVE_INFINITY, 11.0, 1.0e-10));
    Assert.assertEquals(5.0, set.getSize(), 1.0e-10);
    Assert.assertEquals(5.9, ((Vector1D) set.getBarycenter()).getX(), 1.0e-10);
    Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(0.0)));
    Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(4.0)));
    Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(8.0)));
    Assert.assertEquals(Region.Location.OUTSIDE,  set.checkPoint(new Vector1D(12.0)));
    Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Vector1D(1.2)));
    Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Vector1D(5.9)));
    Assert.assertEquals(Region.Location.INSIDE,   set.checkPoint(new Vector1D(9.01)));
    Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(5.0)));
    Assert.assertEquals(Region.Location.BOUNDARY, set.checkPoint(new Vector1D(11.0)));
    Assert.assertEquals( 1.0, set.getInf(), 1.0e-10);
    Assert.assertEquals(11.0, set.getSup(), 1.0e-10);

    List<Interval> list = set.asList();
    Assert.assertEquals(3, list.size());
    Assert.assertEquals( 1.0, list.get(0).getInf(), 1.0e-10);
    Assert.assertEquals( 3.0, list.get(0).getSup(), 1.0e-10);
    Assert.assertEquals( 5.0, list.get(1).getInf(), 1.0e-10);
    Assert.assertEquals( 6.0, list.get(1).getSup(), 1.0e-10);
    Assert.assertEquals( 9.0, list.get(2).getInf(), 1.0e-10);
    Assert.assertEquals(11.0, list.get(2).getSup(), 1.0e-10);

}