Scaled result when simulating sensitivities with enable_variable_scaling:True??

7 posts / 0 new
Last post
niklasa
Offline
Joined: 2009-10-05
Scaled result when simulating sensitivities with enable_variable_scaling:True??

Hi

When simulating sensitivities with enable_variable_scaling set to True, the returned sensitivity, e.g. dx1/dk1 seems to be scaled, but only for the nominal value of x1 and not with the nominal value of k1.

I attach an example where a nominal value for x1 is set to 2 and sensitivities is calculated for parameter k1. Without scaling the sensitivity (dx1/dk1) is -12.34, with scaling it is -6.33 (the ratio is 1.95). It is strange though that nominal values set for k1 does not effect the value.

Is this scaling behaviour intended?

Best regards
Niklas

niklasa
Offline
Joined: 2009-10-05
Something went wrong with the

Something went wrong with the file attachments, I paste them here instead. Note the missing space indents between def and return. Is there anyway to post space indents?

Best regards
Niklas

========== englezos652.py ==============

from jmodelica.jmi import compile_jmu, JMUModel

def simsens(scaleflag):
jmu_name = compile_jmu("Englezos652", "Englezos652.mop",\
compiler_options={"enable_variable_scaling":scaleflag})

# Load a model instance into Python
model = JMUModel(jmu_name)

# Get and set the options
opts = model.simulate_options()
opts['IDA_options']['atol'] = 1.0e-6
opts['IDA_options']['sensitivity'] = True
opts['ncp'] = 400

#Simulate
res = model.simulate(final_time=1697000, options=opts)
return res['dx1/dk1']

dx1dk1_with_scaling = simsens(True)
dx1dk1_no_scaling = simsens(False)

print('no scaling: %f' %(dx1dk1_no_scaling[-1]))
print('with scaling: %f' %(dx1dk1_with_scaling[-1]))

============ Englezos652.mop ================

optimization Englezos652

constant Real K1 = 0.242;
constant Real K2 = 0.428;
Real r1;
Real r2;
Real x1(start=1.0,fixed=true,nominal=2);
Real x2(start=0.0,fixed=true,nominal=2);

parameter Real k1(free=true,nominal=1e-6) = 3.5458883e-6;
parameter Real k2(free=true,nominal=1e-6) = 4.0034558e-6;

equation
r1 = k1*(x1^2 - x2*(2 - 2*x1 - x2)/(3*K1));
r2 = k2*(x1*x2 - (1 - x1 -2*x2)*(2 - 2*x1 - x2)/(9*K2));
der(x1) = -r1 - r2;
der(x2) = r1/2 - r2;

end Englezos652;

chria
Offline
Joined: 2009-07-29
Hi Niklas,   This is not the

Hi Niklas,
 
This is not the intended behaviour and I have created a ticket (https://trac.jmodelica.org/ticket/1359) together with a fix (https://trac.jmodelica.org/changeset/2483). I also added your posted model as test in JModelica, is this ok?
 
Best
/Christian

niklasa
Offline
Joined: 2009-10-05
Thanks for the fix! For me

Thanks for the fix! For me it's absolutely okay to post the model as a test in JModelica. The model is taken from "Applied parameter estimation for chemical engineers" by Englezos/Kalogerakis.

Best regards
Niklas

niklasa
Offline
Joined: 2009-10-05
Hi Christian! I've tested the

Hi Christian!

I've tested the fix and it works great. Thanks!

One thing I noticed now is that there is no initialization before the sensitivity simulations. When simulating without sensitivities the algorithm first initializes with ipopt. Is something changed or has this always been the case?

Best regards
Niklas

chria
Offline
Joined: 2009-07-29
Perfect!   When simulating

Perfect!
 
When simulating sensitivities we have always used Sundials internal calculation of initial conditions, not IPOPT. This will change in the future. The sensitivity implementation is still work in progress and still lacks a few key features.
 
Best
/Christian

niklasa
Offline
Joined: 2009-10-05
Ok, that explains

Ok, that explains why.

Best
Niklas

Login or register to post comments