3

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 how to fix it so I can get the standard deviation?

slow_learner
  • 337
  • 1
  • 2
  • 15
  • Looks like ipopt is crashing. That is always a bug. Are there any useful messages in the solver log? No idea if this helps but may be do `sqrt(m.varX[i]+0.001)`. Also make sure `m.varX` is a positive variable. – Erwin Kalvelagen May 25 '20 at 11:30
  • I have just tried your solution and now the error is `ValueError: Cannot load a SolverResults object with bad status: error`, so something has been advanced. The iterations have also delivered the following message `Error in an AMPL evaluation. Run with "halt_on_ampl_error yes" to see details. Warning: Cutting back alpha due to evaluation error` – slow_learner May 25 '20 at 13:07
  • This may indicate you are still taking the square root of a negative number. Check the bounds on varX. – Erwin Kalvelagen May 25 '20 at 13:10
  • I have saved the values of varX on a .txt file, the end value is -9.407356729606605e-70 at the endpoint, the rest of the values are possitive; however, some of them are of the order of 10e-10. I am testing now adding 10 instead, and the code is taking long, but hasn't failed yet – slow_learner May 25 '20 at 13:15

0 Answers0