Can I calculate a standard deviation as a pyomo variable using ipopt?

161 views
Skip to first unread message

Jaime de la Mota Sanchis

unread,
May 25, 2020, 4:20:38 AM5/25/20
to Pyomo Forum
Hello everyone. I am now trying to make my model stochastic and put some restrictions using the mean and standard deviation assuming a normal random variable.

I have constructed a pyomo code in which I calculate the weighted mean of 3 vectors as

def meanX_definition(model, i):
     
return m.meanX[i] ==(m.x1[i]+4*m.x2[i]+m.x3[i])/6

m
.meanX_const = Constraint(m.N, rule = meanX_definition)

And then, I have calculated the variance as


 
def varX_definition(model, i):
       
return m.varX[i] ==((m.x1[i]-m.meanX[i])**2+ 4*(m.x2[i]-m.meanX[i])**2+(m.x3[i]-m.meanX[i])**2)/6

m
.varX_const = Constraint(m.N, rule = varX_definition)

Since my model is a stochastic one, I want to put restrictions as x1, x2 and x3 have to be localidez between the mean and +-2 standard deviations.

For that, I have attempted to calculate the standard deviation as

def stdX_definition(model, i):
     
return m.desvestX[i] == sqrt(m.varX[i])
m
.stdX_const = Constraint(m.N, rule = stdX_definition)

and


def stdX_definition(model, i):
     
return m.desvestX[i] == m.varX[i]**(0.5)
m
.stdX_const = Constraint(m.N_notinitial_notfinal, rule = stdX_definition)



I have also tried to define the standard deviation at all points but the first and the last in case the error was the standard deviation of 0 at [0] and [n], since the start and endpoints are the same for all 3 vectors.

Unfortunately, an error occurs

ApplicationError: Solver (ipopt) did not exit normally

Can someone please tell me if this issue can be fixed so I can get the standard deviation?
I will attach my code so that if someone is interested can take a look.

Thanks.
Jaime.


caso_sin_acoplo_tf_multiple_restriccion_std_1.py

Erling D. Andersen

unread,
May 28, 2020, 10:52:59 AM5/28/20
to Pyomo Forum
Since the standard dev. includes a 2 norm which is non smooth at 0 (not differentiable), then traditional optimizers like ipopt might have problems with the std. dev.
Whether that this is the issue you are fighting I cannot say.

Alternatively standard deviation can be modeled using a conic quadratic constraint i.e.


but unless you can state the complete model on conic form then that most likely is not useful for you.

Siirola, John D

unread,
May 28, 2020, 11:02:59 AM5/28/20
to pyomo...@googlegroups.com

One additional note (because this comes up frequently):  Erling is correct that the 2-norm as generally written can cause problems at 0.  There is a “standard” reformulation that can have significantly better behavior, for example, instead of:

 

                m.desvestX[i] == sqrt(m.varX[i])

 

try expressing the constraint as

 

                m.desvestX[i]**2 == m.varX[i]

 

John

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/bb75710f-758e-4225-a9bf-f28881b53a90%40googlegroups.com.

Jaime de la Mota Sanchis

unread,
May 28, 2020, 11:25:26 AM5/28/20
to pyomo...@googlegroups.com
Thank you very much to both of you for your answers. I have been able to fix the issue.

Regards.
Jaime.

Libre de virus. www.avast.com


Libre de virus. www.avast.com
Reply all
Reply to author
Forward
0 new messages