commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "roger.ball@creoss.com" <roger.b...@creoss.com>
Subject RE: [MATH] Need help on math libraries for curve generation
Date Fri, 22 Jan 2010 17:59:57 GMT
Luc
     Thanks for your comments. I have taken the 2DCurveExponentialX as a first attempt here.
The basic equation is y = a + b*e^(c*x) (is the math e, natural exponential function). I have
written the following implementation of the of the ParametricRealFunction for this, see below.
Not having any experience with this type a implementation I did the best I could. However,
I am getting this exception:

org.apache.commons.math.optimization.OptimizationException: unable to compute covariances:
singular problem
I unfortunately do not have any idea what this means or how to remedy it. Your help is appreciated

Thanks
Roger

/**
    * implementation of ParametricRealFunction clase for
    *    y = a + be^(cx)
    */
   public static class TwoDCurveNaturalLogX implements ParametricRealFunction
   {
       /*
        *"double[] coeffs = must include at least 1 but not more than 3 coefficients."
        */
        @Override
        public double value(double x, double[] coeffs) throws FunctionEvaluationException
        {
           if(coeffs == null || coeffs.length == 0 || coeffs.length > 3)
           {
                if (coeffs != null)
                {
                    for (int ii=0; ii < coeffs.length; ii++)
                    {
                        //System.out.println("\t coeffs ["+ii+"]"+coeffs[ii]);
                    }
                }
                else
                {
                   //System.out.println("No coeffs were passed in");
                }
                throw new FunctionEvaluationException(coeffs);
           }
           double a = coeffs[0];
           double b = 0;
           double c = 0;
           if(coeffs.length >= 2)
               b = coeffs[1];
           if(coeffs.length >= 3)
               c = coeffs[2];
          double value = a + b*Math.pow(Math.E, (c*x));
          //System.out.println("\t value ["+value+"]");
          return value;
        }
        /*
         * derivative: y = b*c*e^(c*x)
         * double[] coeffs = must include at least 1 but not more than 3 coefficients."
         */
        @Override
        public double[] gradient(double x, double[] coeffs) throws FunctionEvaluationException
{
           if(coeffs == null || coeffs.length ==0 || coeffs.length > 3)
           {
                throw new FunctionEvaluationException(coeffs);
           }
           System.out.println("\t coeffs length = ["+coeffs.length+"]");
           double a = coeffs[0];
           double b = 0;
           double c = 0;
           if(coeffs.length >= 2)
               b = coeffs[1];
           if(coeffs.length >= 3)
               c = coeffs[2];
           double gradient = b*c*Math.pow(Math.E, (c*x));
           double[] gradientVector = new double[3];
           gradientVector[0] = gradient;
           gradientVector[1] = 0;
           gradientVector[2] = 0;
           System.out.println("\t gradient ["+gradient+"]");
           return gradientVector;
        }
   }


Luc
________________________________
From: roger.ball@creoss.com
Sent: Thursday, January 21, 2010 11:46 AM
To: user@commons.apache.org
Subject: [MATH] Need help on math libraries for curve generation


We are evaluating the apache math library (http://commons.apache.org/math/index.html) for
use on one of projects. In this project we need to generate curves based on the following
functions:

2DCurve3rdOrderXPolynomial
2DCurveExponentialX
2DCurveNaturalLogX
2DCurveSquareRootX
2DCurveTimeConstantX
2DCurveExponentialDecayX
2DCurveLogarithmicDecayX
3DCurve4thOrderXPolynomial
3DCurveExponentialX
3DCurveNaturalLogX
3DCurveSquareRootX
3DCurveTimeConstantX
3DCurve3rdOrderZTimes4thOrderX
3DCurveExponentialDecayX
3DCurveLogarithmicDecayX
3DCurveExponentialDecayZ
3DCurveLogarithmicDecayZ
3DCurveHyprebolicDecayX

For each function generated from data we also need:

Coefficient of Determination
Sum of Squares
Standard Error of Regression

Does anyone have experience with this library to direct us to which classes can be used to
handle these requirements?

Thanks
Roger Ball


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message