Package org.apache.commons.math.analysis

Examples of org.apache.commons.math.analysis.UnivariateRealFunction


            String name,
            TrackAnalyzer.Quantity q,
            TrackAnalyzer ta) throws SAXException, IOException{

        ValueFunction vf = ColorFunctionFactory.createValueFunction(ta, q);
        UnivariateRealFunction hue = null;
        double ymin = Double.POSITIVE_INFINITY;
        double ymax = Double.NEGATIVE_INFINITY;

        if (q == TrackAnalyzer.Quantity.Bearing){
            hue = new UnivariateRealFunction(){
                @Override
                public double value(double bearing){
                    return DEFAULT_STARTHUE - Math.round(bearing)/360.;
                }
            };
View Full Code Here


               } else if (x[i] > maxX){
                   maxX = x[i];
                   maxY = y[i];
               }
           }
           UnivariateRealFunction result = null;
           switch(n){
               case 1:
                   result = LinearFunction.withUnitySlope(y[0] - x[0]);
                   break;
               case 2:
View Full Code Here

          }

          // An alternative implementation for getModelFunction() that
          // uses Horner's method to avoid exponentiation.
          public UnivariateRealFunction getModelFunctionHorner() {
            UnivariateRealFunction func = new UnivariateRealFunction() {
              @Override
              public double value(double x)
                  throws FunctionEvaluationException {
                // Compute the value of the polynomial for x via
                // Horner's method.
View Full Code Here

    return strRepr;
  }

  @Override
  public ContinuousModelFunction getModelFunction() {
    UnivariateRealFunction func = new UnivariateRealFunction() {
      @Override
      public double value(double t) throws FunctionEvaluationException {
        double y = parameters.get(0).getConstantCoefficient();
       
        for (int i = 0; i < parameters.size(); i++) {
View Full Code Here

          // there is a sign change: an event is expected during this step

          // variation direction, with respect to the integration direction
          increasing = (gb >= ga);

          UnivariateRealSolver solver = new BrentSolver(new UnivariateRealFunction() {
              public double value(double t) throws FunctionEvaluationException {
                  try {
                      interpolator.setInterpolatedTime(t);
                      return function.g(t, interpolator.getInterpolatedState());
                  } catch (DerivativeException e) {
View Full Code Here

                    // there is a sign change: an event is expected during this step

                    // variation direction, with respect to the integration direction
                    increasing = gb >= ga;

                    final UnivariateRealFunction f = new UnivariateRealFunction() {
                        public double value(final double t) {
                            try {
                                interpolator.setInterpolatedTime(t);
                                return handler.g(t, interpolator.getInterpolatedState());
                            } catch (DerivativeException e) {
                                throw new EmbeddedDerivativeException(e);
                            } catch (EventException e) {
                                throw new EmbeddedEventException(e);
                            }
                        }
                    };
                    final BrentSolver solver = new BrentSolver(convergence);

                    if (ga * gb >= 0) {
                        // this is a corner case:
                        // - there was an event near ta,
                        // - there is another event between ta and tb
                        // - when ta was computed, convergence was reached on the "wrong side" of the interval
                        // this implies that the real sign of ga is the same as gb, so we need to slightly
                        // shift ta to make sure ga and gb get opposite signs and the solver won't complain
                        // about bracketing
                        final double epsilon = (forward ? 0.25 : -0.25) * convergence;
                        for (int k = 0; (k < 4) && (ga * gb > 0); ++k) {
                            ta += epsilon;
                            try {
                                ga = f.value(ta);
                            } catch (FunctionEvaluationException ex) {
                                throw new DerivativeException(ex);
                            }
                        }
                        if (ga * gb > 0) {
View Full Code Here

                  LocalizedFormats.OUT_OF_RANGE_SIMPLE, p, 0.0, 1.0);
        }

        // by default, do simple root finding using bracketing and default solver.
        // subclasses can override if there is a better method.
        UnivariateRealFunction rootFindingFunction =
            new UnivariateRealFunction() {
            public double value(double x) throws FunctionEvaluationException {
                double ret = Double.NaN;
                try {
                    ret = cumulativeProbability(x) - p;
                } catch (MathException ex) {
                    throw new FunctionEvaluationException(x, ex.getSpecificPattern(), ex.getGeneralPattern(), ex.getArguments());
                }
                if (Double.isNaN(ret)) {
                    throw new FunctionEvaluationException(x, LocalizedFormats.CUMULATIVE_PROBABILITY_RETURNED_NAN, x, p);
                }
                return ret;
            }
        };

        // Try to bracket root, test domain endpoints if this fails
        double lowerBound = getDomainLowerBound(p);
        double upperBound = getDomainUpperBound(p);
        double[] bracket = null;
        try {
            bracket = UnivariateRealSolverUtils.bracket(
                    rootFindingFunction, getInitialDomain(p),
                    lowerBound, upperBound);
        catch (ConvergenceException ex) {
            /*
             * Check domain endpoints to see if one gives value that is within
             * the default solver's defaultAbsoluteAccuracy of 0 (will be the
             * case if density has bounded support and p is 0 or 1).
             */
            if (FastMath.abs(rootFindingFunction.value(lowerBound)) < getSolverAbsoluteAccuracy()) {
                return lowerBound;
            }
            if (FastMath.abs(rootFindingFunction.value(upperBound)) < getSolverAbsoluteAccuracy()) {
                return upperBound;
            }
            // Failed bracket convergence was not because of corner solution
            throw new MathException(ex);
        }
View Full Code Here

                        final double min, final double max, final double startValue)
        throws MaxIterationsExceededException, FunctionEvaluationException {

        try {

            final UnivariateRealFunction derivative =
                ((DifferentiableUnivariateRealFunction) f).derivative();
            clearResult();
            verifySequence(min, startValue, max);

            double x0 = startValue;
            double x1;

            int i = 0;
            while (i < maximalIterationCount) {

                x1 = x0 - (f.value(x0) / derivative.value(x0));
                if (FastMath.abs(x1 - x0) <= absoluteAccuracy) {
                    setResult(x1, i);
                    return x1;
                }
View Full Code Here

        }

        // Partial derivatives with respect to x at the grid knots
        final double[][] dFdX = new double[xLen][yLen];
        for (int j = 0; j < yLen; j++) {
            final UnivariateRealFunction f = ySplineX[j].derivative();
            for (int i = 0; i < xLen; i++) {
                dFdX[i][j] = f.value(xval[i]);
            }
        }

        // Partial derivatives with respect to y at the grid knots
        final double[][] dFdY = new double[xLen][yLen];
        for (int i = 0; i < xLen; i++) {
            final UnivariateRealFunction f = xSplineY[i].derivative();
            for (int j = 0; j < yLen; j++) {
                dFdY[i][j] = f.value(yval[j]);
            }
        }

        // Cross partial derivatives
        final double[][] d2FdXdY = new double[xLen][yLen];
View Full Code Here

        }

        // Partial derivatives with respect to x at the grid knots
        final double[][] dZdX = new double[xLen][yLen];
        for (int j = 0; j < yLen; j++) {
            final UnivariateRealFunction f = ySplineX[j].derivative();
            for (int i = 0; i < xLen; i++) {
                dZdX[i][j] = f.value(xval[i]);
            }
        }

        // Partial derivatives with respect to y at the grid knots
        final double[][] dZdY = new double[xLen][yLen];
        for (int i = 0; i < xLen; i++) {
            final UnivariateRealFunction f = xSplineY[i].derivative();
            for (int j = 0; j < yLen; j++) {
                dZdY[i][j] = f.value(yval[j]);
            }
        }

        // Cross partial derivatives
        final double[][] dZdXdY = new double[xLen][yLen];
View Full Code Here

TOP

Related Classes of org.apache.commons.math.analysis.UnivariateRealFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.