Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4CE43178DD for ; Fri, 15 May 2015 14:45:41 +0000 (UTC) Received: (qmail 17727 invoked by uid 500); 15 May 2015 14:45:40 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 17603 invoked by uid 500); 15 May 2015 14:45:40 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 17582 invoked by uid 99); 15 May 2015 14:45:39 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 May 2015 14:45:39 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 5D9051A2D04 for ; Fri, 15 May 2015 14:45:39 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.899 X-Spam-Level: ** X-Spam-Status: No, score=2.899 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id 3yux5iDV_WIQ for ; Fri, 15 May 2015 14:45:33 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 8230D24960 for ; Fri, 15 May 2015 14:45:32 +0000 (UTC) Received: by iesa3 with SMTP id a3so27215666ies.2 for ; Fri, 15 May 2015 07:45:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=zWJOZFX0YZpYe7NXtNdjEedKXQ+Ukz+uL56XBBaX8RQ=; b=Hu0O+ax7n6hPf2t6RNtgn8WfOsijxS5d/ytQXHi4jBEZktQyTaKmHBs77a2EtDACst 9chCD9EPLwnNg+8LRRITOj0Lq5Kgbwh1XWmPnafiqlOJWWSkOsM8XOQi9KmY3CCUtlOx FP/SiphHYHc7XGtGBCpEHz66BfKdAM/nxkwYIIxtnSN+lPGCv8q44QPODJ7rB+rhoFnD J0CS+wkQjZlaaqUyLq+2wE8hlPl86OTXwSXth8ZJFs/27/1ktr5Z0ZyUfFogDWTpvmDz vhwQenCCgautnCc7eRzfOVG0xe7nM4Is5JpAojpcjDrVqF6Mt81LwomtGWzThbCs9x1D urxQ== MIME-Version: 1.0 X-Received: by 10.50.136.134 with SMTP id qa6mr26425707igb.26.1431701125057; Fri, 15 May 2015 07:45:25 -0700 (PDT) Received: by 10.79.1.202 with HTTP; Fri, 15 May 2015 07:45:25 -0700 (PDT) In-Reply-To: <5555F485.5040004@spaceroots.org> References: <5555F485.5040004@spaceroots.org> Date: Fri, 15 May 2015 14:45:25 +0000 Message-ID: Subject: Re: [math] ODE with Jacobian in commons math 3.5 From: Bernard GODARD To: Commons Users List Content-Type: multipart/alternative; boundary=089e0141a8dcfbf00705161fe463 --089e0141a8dcfbf00705161fe463 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Luc, Thank you for your detailed answer. JIRA issue MATH-1225 was created. On Fri, May 15, 2015 at 1:28 PM, Luc Maisonobe wrote: > Le 14/05/2015 16:40, Bernard GODARD a =C3=A9crit : > > Dear all, > > Hi Bernard, > > > > > The user guide on ordinary differential equations > > http://commons.apache.org/proper/commons-math/userguide/ode.html > > is very useful to understand how to use ODEWithJacobians and > > ParameterizedODE. > > but not up to date. > > You are right, we need to update this. Thanks for pointing the problem. > Could you open a JIRA issue at > so we don't forget about it? > > > > >>From the latest documentation, it does not seem clear to me how to use > > ParameterizedODE and ParameterJacobianProvider in math 3.5. > > > > Moreover ParameterJacobianProvider-> computeParameterJacobian looks li= ke > > it can only handle one parameter at a time and is computed independentl= y > > from the main dynamic equation. For the use case I am interested in > > (integration of the orbit of a satellite with complex dynamic model of > > several hundred parameters) I prefer to compute together the force mode= l > > and its partial derivatives with respect to all parameters together > > because these computations share a lot of intermediate results. > Otherwise I > > have to either recompute or use a cache mechanism with a test on input > > parameter change (which also may be invalidated by the ODE integrator > > depending on the order of the evaluation calls). This design then seems > > inefficient to me but there might be a good reason for it. I would > > appreciate if someone could explain this choice. > > > > I would rather have a method like: > > > > void computeDerivativesWithJacobian(double t, double[] y, > > parameterList,double[] yDot,double[][] Jacobian ) > > with parameterList an input specifying the ordered list of parameters f= or > > which to compute the Jacobian. > > The rationale for splitting the computation in several parts (mainly the > yDot from the Jacobian) was twofold. First, it allowed design of a > simpler class when Jacobians are not desired, which could then be > extended by subclasses that add Jacobians support. The second reason was > that it allowed the Apache Commons Math library to provide by itself a > generic implementation using finite differences for computing the > Jacobians when the user would still provide only the base differential > equation (this is a case of what Hairer, N=C3=B8rsett and Wanner called > internal differentiation). > > The rationale for splitting the Jacobians itself with one column at a > time for one parameter is also twofold. First it frees the user (who > provides this Jacobian) from worrying about putting the right parameter > in the right column. The matrix is built automatically with proper > columns assignment even if for some runs all parameters were selected > and in other runs only a subset of the known parameters are used for > differentiation, the other parameters being considered fixed. The second > reason is that the providers for the various columns (i.e. for the > various parameters) can be different objects. You can even have one > different class for each parameter if you want. This allows for example > to handle ODE for which some parameters are computed analytically and > some other parameters are computed by finite differences. In such a > case, user would call JacobianMatrices.addParameterJacobianProvider for > the parameters for which he knows how to differentiate, and he would > rather call JacobianMatrices.setParameterStep for the parameters for > which he doesn't know how to differentiate. The use case for these two > aspect was also orbit determination: user can decide at run time which > parameters are estimated and which are fixed, hence increasing or > decreasing the number of columns in the Jacobian, and some force model > may be complex enough that no analytical expression is available, hence > needing finite differences. > > The current design can be used in your case and benefit from already > computed values. This is not clear in the documentation, though and > should be better explained. In fact, the various calls to the > computeParameterJacobian that are used to retrieve all the columns one > at a time are all done in a small loop and without any change to the > state, i.e. they correspond to the same step. The scheduling is as follow= s: > > for each evaluation (i.e. for one value of t and y[]): > - one call to the computeMainStateJacobian method > (which belongs to either the MainStateJacobianProvider interface > or the MainStateJacobianProvider interface, depending on > which JacobianMatrices constructor you use) > - for each selected parameter, iterating in the exact same > order the parameters were specified in JacobianMatrices constructor: > * one call to computeParameterJacobian for the current parameter, > using the proper provider (which may be a finite differences > provider for some parameters and an analytical provider for > other parameters) > - end for > end for > > With the calls sequence above, you can for example perform all the > computation early (say when computeMainStateJacobian is called) and > store the Jacobians columns in an internal array, and then only copy > the column back when the computeParameterJacobian method is called in > the internal loop. Of course, this implies the implementations of > MainStateJacobianProvider and ParameterJacobianProvider know each other. > This is even easier if they correspond to the same object, but it is not > required. > > So in your case, if you already know how to compute the full Jacobian by > yourself, I would suggest to put everything in a top level class that > would implement: > - either MainStateJacobianProvider or MainStateJacobianProvider > - AND ParameterJacobianProvider > > This could be done as follows (note that the computeParameterJacobian > is complete here, it can really be restricted to two lines of code): > > MyClass > implements MainStateJacobianProvider, ParameterJacobianProvider { > > private double [][] jacobian; > private Map nameToIndex; > > public MyClass() { > // set up the nameToIndex map > } > > public void computeDerivatives(double t, double[] y, double[] yDot) { > > // compute yDot > > // compute and store Jacobian > // (beware to store it in transposed form ...) > > } > > void computeParameterJacobian(double t, double[] y, double[] yDot, > String paramName, double[] dFdP) { > // this method is known to be called after computeDerivatives > // we simply pick up the column that was already computed before > // and that was stored transposed > final double[] precomputed =3D jacobian[nameToIndex.get(name)]; > System.arraycopy(precomputed, 0, dFdP, 0, precomputed.length); > } > > } > > > Hope this helps, > Luc > > > > > > > Thank you, > > > > Kind regards, > > > > > > Bernard Godard > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > For additional commands, e-mail: user-help@commons.apache.org > > --089e0141a8dcfbf00705161fe463--