-1

I have setup an objective function - obj = (x0-u0)^2 + (u0)^2 I am calculating the minima using Scipyoptimizer with SLSQP. I give x0 as input and hence it computes u0 on the fly, simultaneously minimizing the obj also. Now, I am trying to use array of values instead of x0, but it gives error and throws - returns only scalar values.

I have tried function run_model(). Model works perfect. But while running the function - run_driver(), it throws an error.

p.model.add_subsystem('obj_f', ExecComp('obj = (x0-u0)**2 + (u0)**2', u0={'shape': (2, )}, x0={'shape': (2, )}, obj={'shape': (2, )}), promotes=['x0', 'u0'])

for x0 = [1.5, 1.2] It should give result = 0.72 which is optimally value for x0=1.2 at u0=0.6

  • I'm trying to get an idea of what exactly you're trying to do. How do you define minimizing the objective when it is a 2-vector? If you mean to find the minimum magnitude of obj, you need to explicitly calculate that scalar value and use it as the objective. – Rob Falck Feb 07 '19 at 00:43
  • a complete code snippet example would be very helpful. – Justin Gray Feb 07 '19 at 03:01
  • @JustinGray Is there any solution for this. https://gist.github.com/shreyanshmohnot/655152fa479798bf3ab4122255cbabfe – Shreyansh Mohnot Feb 15 '19 at 22:45
  • @RobFalck I want to find minimum magnitude of the 'obj' as well as 'u' at different values of 'x'. – Shreyansh Mohnot Feb 15 '19 at 22:46
  • Most optimizers need a scalar objective function. Since mixed-objective functions are often competing (driving one to a smaller value necessarily drives the others to a larger value), the way we typically handle this is to fix one of the values as a constraint and minimize the other as an objective. This lets you sweep out the pareto frontier. – Rob Falck Feb 21 '19 at 13:41

1 Answers1

0

The error you are getting is due to your objective value being a vector. Gradient based optimizers require a single scalar value as the objective. You could try summing the array to make a scalar.

p.model.add_subsystem('obj_f', ExecComp('obj = sum((x0-u0)**2 + (u0)**2)', u0={'shape': (2, )}, 
                                                                           x0={'shape': (2, )}, 
                                                                           obj={'shape': (1, )}), 
                                        promotes=['x0', 'u0'])
Justin Gray
  • 5,605
  • 1
  • 11
  • 16