Re: [math] Struggling with least squares
I figured it out. The issue was with my derivative calculation. I was using (a - b) / DELTA * 2. Changing this to (b - a) / DELTA * 2 fixes this problem. a = morton3pTime(cp - DELTA, wPrime, pmax, p); b = morton3pTime(cp + DELTA, wPrime, pmax, p); jacobian.setEntry(i, 0, (b - a) / (DELTA * 2)); Thanks On Fri, Dec 28, 2018 at 8:33 PM Gilles wrote: > Hello. > > On Thu, 27 Dec 2018 07:32:30 -0600 (CST), David Tinker wrote: > > Hi Guys. I am struggling to use the least squares optimizer to fit a > > 2 > > variable non-linear function to a curve of observed data points. I am > > pretty > > sure I am doing something stupid because I don't know the maths. My > > MultivariateJacobianFunction moves away from my starting values on > > the first > > iteration but then converges back to the starting values. My > > variables are > > CP and W' and this is what happens: > > > > cp 250.0 W' 24000.0 (starting values) > > cp 197.17292724155843 W' 5627.212534968825 > > cp 233.7927945744999 W' 18662.916420529345 > > cp 245.72618039512386 W' 22592.92114117481 > > cp 248.91747806252718 W' 23643.613738664597 > > cp 249.9974080222 W' 23999.146684 > > ... > > cp 249.9993520052 W' 23999.7866709 > > optimum {250; 24,000} > > > > Any ideas? > > What happens when different starting points? > > Gilles > > > Here is the code: > > > > public class LeastSquaresExample { > > > > private static final double DELTA = 0.01; // for calculating > > derivatives > > > > public static void main(String[] args) { > > Vector2D[] observedPoints = new Vector2D[3]; > > observedPoints[0] = new Vector2D(388, 250); // maps power in > > watts > > to time in seconds > > observedPoints[1] = new Vector2D(368, 450); > > observedPoints[2] = new Vector2D(321, 780); > > > > int pmax = 961; > > > > MultivariateJacobianFunction fn = point -> { > > double cp = point.getEntry(0); > > double wPrime = point.getEntry(1); > > System.out.println("cp " + cp + " W' " + wPrime); > > > > RealVector value = new > > ArrayRealVector(observedPoints.length); > > RealMatrix jacobian = new > > Array2DRowRealMatrix(observedPoints.length, 2); > > for (int i = 0; i < observedPoints.length; i++) { > > double p = observedPoints[i].getX(); > > value.setEntry(i, morton3pTime(cp, wPrime, pmax, p)); > > > > // each row in the jacobian is a measurement and cols > > are > > partial derivatives wrt cp(0) and wPrime(1) > > double a, b; > > a = morton3pTime(cp - DELTA, wPrime, pmax, p); > > b = morton3pTime(cp + DELTA, wPrime, pmax, p); > > jacobian.setEntry(i, 0, (a - b) / (DELTA * 2)); > > > > a = morton3pTime(cp, wPrime - DELTA, pmax, p); > > b = morton3pTime(cp, wPrime + DELTA, pmax, p); > > jacobian.setEntry(i, 1, (a - b) / (DELTA * 2)); > > } > > return new Pair<>(value, jacobian); > > }; > > > > double[] target = new double[observedPoints.length]; > > for (int i = 0; i < observedPoints.length; i++) target[i] = > > observedPoints[i].getY(); > > > > LeastSquaresProblem problem = new LeastSquaresBuilder() > > .start(new double[]{250.0, 24000.0}) > > .model(fn) > > .target(target) > > .maxEvaluations(1000) > > .maxIterations(1000) > > .build(); > > LeastSquaresOptimizer.Optimum optimum = new > > LevenbergMarquardtOptimizer().optimize(problem); > > RealVector pt = optimum.getPoint(); > > System.out.println("optimum " + pt); > > } > > > > private static double morton3pTime(double cp, double wPrime, > > double > > pmax, double p) { > > return wPrime / (p - cp) + wPrime / (cp - pmax); > > } > > } > > > > > - > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org > For additional commands, e-mail: user-h...@commons.apache.org > >
Re: [math] Struggling with least squares
The same. Example: cp 300.0 W' 12000.0 cp 333.74051281161115 W' -12839.244450996564 cp 298.7156407940922 W' 7487.731100602964 cp 298.9550329672171 W' 11242.142876024549 cp 299.7463658640514 W' 11824.469512284873 cp 299.9341647360811 W' 11954.82219199176 ... cp 299.9974568135 W' 11999.999825967237 cp 299.9993642035 W' 11999.56491805 optimum {300; 12,000} On Fri, Dec 28, 2018 at 8:33 PM Gilles wrote: > Hello. > > On Thu, 27 Dec 2018 07:32:30 -0600 (CST), David Tinker wrote: > > Hi Guys. I am struggling to use the least squares optimizer to fit a > > 2 > > variable non-linear function to a curve of observed data points. I am > > pretty > > sure I am doing something stupid because I don't know the maths. My > > MultivariateJacobianFunction moves away from my starting values on > > the first > > iteration but then converges back to the starting values. My > > variables are > > CP and W' and this is what happens: > > > > cp 250.0 W' 24000.0 (starting values) > > cp 197.17292724155843 W' 5627.212534968825 > > cp 233.7927945744999 W' 18662.916420529345 > > cp 245.72618039512386 W' 22592.92114117481 > > cp 248.91747806252718 W' 23643.613738664597 > > cp 249.9974080222 W' 23999.146684 > > ... > > cp 249.9993520052 W' 23999.7866709 > > optimum {250; 24,000} > > > > Any ideas? > > What happens when different starting points? > > Gilles > > > Here is the code: > > > > public class LeastSquaresExample { > > > > private static final double DELTA = 0.01; // for calculating > > derivatives > > > > public static void main(String[] args) { > > Vector2D[] observedPoints = new Vector2D[3]; > > observedPoints[0] = new Vector2D(388, 250); // maps power in > > watts > > to time in seconds > > observedPoints[1] = new Vector2D(368, 450); > > observedPoints[2] = new Vector2D(321, 780); > > > > int pmax = 961; > > > > MultivariateJacobianFunction fn = point -> { > > double cp = point.getEntry(0); > > double wPrime = point.getEntry(1); > > System.out.println("cp " + cp + " W' " + wPrime); > > > > RealVector value = new > > ArrayRealVector(observedPoints.length); > > RealMatrix jacobian = new > > Array2DRowRealMatrix(observedPoints.length, 2); > > for (int i = 0; i < observedPoints.length; i++) { > > double p = observedPoints[i].getX(); > > value.setEntry(i, morton3pTime(cp, wPrime, pmax, p)); > > > > // each row in the jacobian is a measurement and cols > > are > > partial derivatives wrt cp(0) and wPrime(1) > > double a, b; > > a = morton3pTime(cp - DELTA, wPrime, pmax, p); > > b = morton3pTime(cp + DELTA, wPrime, pmax, p); > > jacobian.setEntry(i, 0, (a - b) / (DELTA * 2)); > > > > a = morton3pTime(cp, wPrime - DELTA, pmax, p); > > b = morton3pTime(cp, wPrime + DELTA, pmax, p); > > jacobian.setEntry(i, 1, (a - b) / (DELTA * 2)); > > } > > return new Pair<>(value, jacobian); > > }; > > > > double[] target = new double[observedPoints.length]; > > for (int i = 0; i < observedPoints.length; i++) target[i] = > > observedPoints[i].getY(); > > > > LeastSquaresProblem problem = new LeastSquaresBuilder() > > .start(new double[]{250.0, 24000.0}) > > .model(fn) > > .target(target) > > .maxEvaluations(1000) > > .maxIterations(1000) > > .build(); > > LeastSquaresOptimizer.Optimum optimum = new > > LevenbergMarquardtOptimizer().optimize(problem); > > RealVector pt = optimum.getPoint(); > > System.out.println("optimum " + pt); > > } > > > > private static double morton3pTime(double cp, double wPrime, > > double > > pmax, double p) { > > return wPrime / (p - cp) + wPrime / (cp - pmax); > > } > > } > > > > > - > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org > For additional commands, e-mail: user-h...@commons.apache.org > >
Re: [math] Struggling with least squares
Hello. On Thu, 27 Dec 2018 07:32:30 -0600 (CST), David Tinker wrote: Hi Guys. I am struggling to use the least squares optimizer to fit a 2 variable non-linear function to a curve of observed data points. I am pretty sure I am doing something stupid because I don't know the maths. My MultivariateJacobianFunction moves away from my starting values on the first iteration but then converges back to the starting values. My variables are CP and W' and this is what happens: cp 250.0 W' 24000.0 (starting values) cp 197.17292724155843 W' 5627.212534968825 cp 233.7927945744999 W' 18662.916420529345 cp 245.72618039512386 W' 22592.92114117481 cp 248.91747806252718 W' 23643.613738664597 cp 249.9974080222 W' 23999.146684 ... cp 249.9993520052 W' 23999.7866709 optimum {250; 24,000} Any ideas? What happens when different starting points? Gilles Here is the code: public class LeastSquaresExample { private static final double DELTA = 0.01; // for calculating derivatives public static void main(String[] args) { Vector2D[] observedPoints = new Vector2D[3]; observedPoints[0] = new Vector2D(388, 250); // maps power in watts to time in seconds observedPoints[1] = new Vector2D(368, 450); observedPoints[2] = new Vector2D(321, 780); int pmax = 961; MultivariateJacobianFunction fn = point -> { double cp = point.getEntry(0); double wPrime = point.getEntry(1); System.out.println("cp " + cp + " W' " + wPrime); RealVector value = new ArrayRealVector(observedPoints.length); RealMatrix jacobian = new Array2DRowRealMatrix(observedPoints.length, 2); for (int i = 0; i < observedPoints.length; i++) { double p = observedPoints[i].getX(); value.setEntry(i, morton3pTime(cp, wPrime, pmax, p)); // each row in the jacobian is a measurement and cols are partial derivatives wrt cp(0) and wPrime(1) double a, b; a = morton3pTime(cp - DELTA, wPrime, pmax, p); b = morton3pTime(cp + DELTA, wPrime, pmax, p); jacobian.setEntry(i, 0, (a - b) / (DELTA * 2)); a = morton3pTime(cp, wPrime - DELTA, pmax, p); b = morton3pTime(cp, wPrime + DELTA, pmax, p); jacobian.setEntry(i, 1, (a - b) / (DELTA * 2)); } return new Pair<>(value, jacobian); }; double[] target = new double[observedPoints.length]; for (int i = 0; i < observedPoints.length; i++) target[i] = observedPoints[i].getY(); LeastSquaresProblem problem = new LeastSquaresBuilder() .start(new double[]{250.0, 24000.0}) .model(fn) .target(target) .maxEvaluations(1000) .maxIterations(1000) .build(); LeastSquaresOptimizer.Optimum optimum = new LevenbergMarquardtOptimizer().optimize(problem); RealVector pt = optimum.getPoint(); System.out.println("optimum " + pt); } private static double morton3pTime(double cp, double wPrime, double pmax, double p) { return wPrime / (p - cp) + wPrime / (cp - pmax); } } - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
[math] Struggling with least squares
Hi Guys. I am struggling to use the least squares optimizer to fit a 2 variable non-linear function to a curve of observed data points. I am pretty sure I am doing something stupid because I don't know the maths. My MultivariateJacobianFunction moves away from my starting values on the first iteration but then converges back to the starting values. My variables are CP and W' and this is what happens: cp 250.0 W' 24000.0 (starting values) cp 197.17292724155843 W' 5627.212534968825 cp 233.7927945744999 W' 18662.916420529345 cp 245.72618039512386 W' 22592.92114117481 cp 248.91747806252718 W' 23643.613738664597 cp 249.9974080222 W' 23999.146684 ... cp 249.9993520052 W' 23999.7866709 optimum {250; 24,000} Any ideas? Here is the code: public class LeastSquaresExample { private static final double DELTA = 0.01; // for calculating derivatives public static void main(String[] args) { Vector2D[] observedPoints = new Vector2D[3]; observedPoints[0] = new Vector2D(388, 250); // maps power in watts to time in seconds observedPoints[1] = new Vector2D(368, 450); observedPoints[2] = new Vector2D(321, 780); int pmax = 961; MultivariateJacobianFunction fn = point -> { double cp = point.getEntry(0); double wPrime = point.getEntry(1); System.out.println("cp " + cp + " W' " + wPrime); RealVector value = new ArrayRealVector(observedPoints.length); RealMatrix jacobian = new Array2DRowRealMatrix(observedPoints.length, 2); for (int i = 0; i < observedPoints.length; i++) { double p = observedPoints[i].getX(); value.setEntry(i, morton3pTime(cp, wPrime, pmax, p)); // each row in the jacobian is a measurement and cols are partial derivatives wrt cp(0) and wPrime(1) double a, b; a = morton3pTime(cp - DELTA, wPrime, pmax, p); b = morton3pTime(cp + DELTA, wPrime, pmax, p); jacobian.setEntry(i, 0, (a - b) / (DELTA * 2)); a = morton3pTime(cp, wPrime - DELTA, pmax, p); b = morton3pTime(cp, wPrime + DELTA, pmax, p); jacobian.setEntry(i, 1, (a - b) / (DELTA * 2)); } return new Pair<>(value, jacobian); }; double[] target = new double[observedPoints.length]; for (int i = 0; i < observedPoints.length; i++) target[i] = observedPoints[i].getY(); LeastSquaresProblem problem = new LeastSquaresBuilder() .start(new double[]{250.0, 24000.0}) .model(fn) .target(target) .maxEvaluations(1000) .maxIterations(1000) .build(); LeastSquaresOptimizer.Optimum optimum = new LevenbergMarquardtOptimizer().optimize(problem); RealVector pt = optimum.getPoint(); System.out.println("optimum " + pt); } private static double morton3pTime(double cp, double wPrime, double pmax, double p) { return wPrime / (p - cp) + wPrime / (cp - pmax); } } -- Sent from: http://apache-commons.680414.n4.nabble.com/Commons-User-f735979.html - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
[daemon] Problem when using Procrun with Java 11
Hello, I try to start a Windows service (on Windows 8.1) with Procrun 1.1.0 and Java 11. I've installed the jdk 11 built by AdoptOpenJDK When I install the service with the option -StartMode jvm, Procrun seems not to find Java. I read in the logs : [info] [55436] Starting service... [error] [55436] Failed creating java [error] [55436] ServiceStart returned 1 [info] [22768] Run service finished. When I install the service with the option --StartMode Java and the option --Jvm pointing to the bin folder of my JAVA_HOME, the service starts correctly. But stopping it is very long (2 minutes). This service works well with a JRE 8 and the option -StartMode jvm. Problems only occur when starting and stopping with Java 11. How can I handle this ? Thank you in advance for your answer. Joel Gaspard Developer Ce message et toutes les pi?ces jointes qu'il contient sont uniquement destin?s aux personnes auxquelles ils sont adress?s et sont strictement confidentiels. A moins qu'il en ait ?t? explicitement convenu autrement, son contenu ne refl?te que la pens?e personnelle de son auteur et ne saurait donc repr?senter la vision officielle de l'Entreprise. Si vous avez re?u ce message par erreur, nous vous remercions de bien vouloir en informer l'exp?diteur imm?diatement par retour d'email et supprimer d?finitivement le message de vos r?pertoires. Toute utilisation de ce message non conforme ? sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. L'internet ne permettant pas d'assurer l'int?grit? de ce message, l'Entreprise d?cline toute responsabilit? au titre de ce message, dans l'hypoth?se o? il aurait ?t? modifi?. This message including any attachments is confidential and intended solely for the addressees. Unless explicitly mentioned, its content reflects only the personal thoughts of the author, and therefore cannot represent the official view of the Company. If received by error, please inform immediately the sender by return e-mail and delete definitely the message from any and all directories. Any use, dissemination or disclosure not in conformity with the intended purposes is strictly prohibited. The integrity of messages via Internet cannot be guaranteed and the Company accepts no liability for any changes which may occur.