/** Get the lower bound of the interval. * @return lower bound of the interval * @deprecated as of 3.1, replaced by {@link #getInf()} */ @Deprecated public double getLower() { return getInf(); }
/** 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 List<Interval> list = remainingRegion.asList(); final List<Segment> segments = new ArrayList<Segment>(list.size()); for (final Interval interval : list) { final Vector3D start = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getInf())); final Vector3D end = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getSup())); segments.add(new Segment(start, end, line)); } return segments; }
/** 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; }
/** Get the lower bound of the interval. * @return lower bound of the interval * @deprecated as of 3.1, replaced by {@link #getInf()} */ @Deprecated public double getLower() { return getInf(); }
/** 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 List<Interval> list = remainingRegion.asList(); final List<Segment> segments = new ArrayList<Segment>(list.size()); for (final Interval interval : list) { final Vector3D start = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getInf())); final Vector3D end = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getSup())); segments.add(new Segment(start, end, line)); } return segments; }
/** 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; }
/** * Maximizes a univariate function using a grid search followed by Brent's algorithm. * * @param fn the likelihood function to minimize * @param gridStart the lower bound for the grid search * @param gridEnd the upper bound for the grid search * @param gridStep step size for the grid search * @param relErr relative error tolerance for Brent's algorithm * @param absErr absolute error tolerance for Brent's algorithm * @param maxIter maximum # of iterations to perform in Brent's algorithm * @param maxEval maximum # of Likelihood function evaluations in Brent's algorithm * * @return the value of the parameter that maximizes the function */ public static double maximize(UnivariateFunction fn, double gridStart, double gridEnd, double gridStep, double relErr, double absErr, int maxIter, int maxEval) { Interval interval = gridSearch(fn, gridStart, gridEnd, gridStep); BrentOptimizer bo = new BrentOptimizer(relErr, absErr); UnivariatePointValuePair max = bo.optimize( new MaxIter(maxIter), new MaxEval(maxEval), new SearchInterval(interval.getInf(), interval.getSup()), new UnivariateObjectiveFunction(fn), GoalType.MAXIMIZE); return max.getPoint(); } }
/** * Maximizes a univariate function using a grid search followed by Brent's algorithm. * * @param fn the likelihood function to minimize * @param gridStart the lower bound for the grid search * @param gridEnd the upper bound for the grid search * @param gridStep step size for the grid search * @param relErr relative error tolerance for Brent's algorithm * @param absErr absolute error tolerance for Brent's algorithm * @param maxIter maximum # of iterations to perform in Brent's algorithm * @param maxEval maximum # of Likelihood function evaluations in Brent's algorithm * * @return the value of the parameter that maximizes the function */ public static double maximize(UnivariateFunction fn, double gridStart, double gridEnd, double gridStep, double relErr, double absErr, int maxIter, int maxEval) { Interval interval = gridSearch(fn, gridStart, gridEnd, gridStep); BrentOptimizer bo = new BrentOptimizer(relErr, absErr); UnivariatePointValuePair max = bo.optimize( new MaxIter(maxIter), new MaxEval(maxEval), new SearchInterval(interval.getInf(), interval.getSup()), new UnivariateObjectiveFunction(fn), GoalType.MAXIMIZE); return max.getPoint(); } }
@Test public void testGridSearch() { Interval interval = Solver.gridSearch(new Parabola(0.25), 0.0, 1.0, 0.1); assertEquals(Precision.compareTo(interval.getInf(), 0.1, 1), 0); assertEquals(Precision.compareTo(interval.getSup(), 0.3, 1), 0); interval = Solver.gridSearch(new Parabola(1.2), 0.0, 1.0, 0.1); assertEquals(Precision.compareTo(interval.getInf(), 0.9, 1), 0); assertEquals(Precision.compareTo(interval.getSup(), 1.0, 1), 0); interval = Solver.gridSearch(new Parabola(1.2), 0.0, 1.0, 0.3); assertEquals(Precision.compareTo(interval.getInf(), 0.9, 1), 0); assertEquals(Precision.compareTo(interval.getSup(), 1.0, 1), 0); }