commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luc Maisonobe <Luc.Maison...@free.fr>
Subject Re: [math] help writing a solver for equation
Date Wed, 17 Sep 2008 19:03:58 GMT
mickeydog@TaosNet.com a écrit :
> I have an equation like so:
> z = Sum of a = 1 to n [ e**(y - x(a))/ e**(x(a)]
> I want to solve for y.
> I have z and x(a).
> 
> I have created a class EquationSolver which has these methods and inner
> class:
> 
> private EstimatedParameter xa;
> 
> public VintageQualityFitter() {
> 
>   xa = new EstimatedParameter("xa", 0.0);

If you want to solve for y and know all x(a), your parameter should be y.

> 
>   // provide the parameters to the base class which
>   // implements the getAllParameters and getUnboundParameters methods
>   addParameter(xa);
> }
> 
> public double theoreticalValue(double z) {
>   double summand = ( Math.exp(y * xa.getEstimate()) /
> Math.exp(xa.getEstimate());
>   return summand;
> }

the name "z" is confusing there, I don't understand if you have several
x(a) and only one value z which is a sum (as seemed to be implied by the
start of your message) or if you have one z for each x(a) as seemed to
be implied by the previous method.

If you have only one z, then the estimation algorithm is not what you
need. You need either to rewrite your equation to solve it (has Ted
proposed) or you need to use a UnivariateRealSolver from package
analysis, and use a simple loop to compute your function for the set of
x(a) you know.

> 
> public void addPoint(double xa) {
>   addMeasurement(new LocalMeasurement(xa, 1.0)); // all weights same
> }
> 
> public double getXa() {
>   return xa.getEstimate();
> }
> 
> private class LocalMeasurement extends WeightedMeasurement {
> 
>   private final double z;
> 
>   // constructor
>   public LocalMeasurement(double xa, double weight) {

  This xa seems strange to me, isn't it rather a "z", or is it linked to
a "z" ?

Luc

>      super(xa, weight);
>      this.z = xa;
>   }
> 
>   public double getTheoreticalValue() {
>     // the value is provided by the model for the local xa
>     return theoreticalValue(z);
>   }
> 
> // don't need this i think
>   public double getPartial(EstimatedParameter parameter) {
>     return 0.0;
>   }
> }
> 
> I use this like so:
> 
> EquationFitter equationFitter = new EquationFitter();
> 
> for (int a = 0; a <= numberOfAs; a++) {
>   double xa = <get x(a)>
>   equationFitter.addPoint(xa.doubleValue());
>  }
> 
> try {
>     // solve the problem, using a Levenberg-Marquardt algorithm with
> default settings
> 	LevenbergMarquardtEstimator estimator = new LevenbergMarquardtEstimator();
>     estimator.estimate(equationFitter);
> } catch (EstimationException e) {
> 	e.printStackTrace();
> }
> 
> // fitter.theoreticalValue() is alpha
> <get some z>
> y = equationFitter.theoreticalValue(z);
> 
> but something in all this isn't right, especially with theoreticalValue(),
> i think.
> Can anyone help?
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message