0

I am trying to learn tensorflow optimization as I code mostly in Matlab.

My matlab code is:

fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
x0 = [0.5,0];
A = [1,2];
b = 1;
Aeq = [2,1];
beq = 1;
x = fmincon(fun,x0,A,b,Aeq,beq)

I want to implement above optimization using tensorflow. Is there a way to replicate it ?

I came across this solution but it accounts only for equality constraint not inequality.

Zanam
  • 4,607
  • 13
  • 67
  • 143
  • You can use scipy minimize and TensorFlow-ScipyOptimizer bridge -- https://www.tensorflow.org/api_docs/python/tf/contrib/opt/ScipyOptimizerInterface – Yaroslav Bulatov Aug 13 '17 at 19:29
  • scipy optimizers are notorious for not converging compared to Matlab .. so I was hoping that tensorflow guys would have created their own algorithm comparable to Matlab – Zanam Aug 14 '17 at 00:20
  • 2
    TensorFlow people are not magicians, just getting to scipy feature parity in native TF would be impressive this year. Numerical optimization is hard! – Yaroslav Bulatov Aug 14 '17 at 06:45

1 Answers1

-1

Here is one tutorial on how to wrap the Tensorflow optimizer into something more like the optimizer you expect:

https://pcess.github.io/tensorflow/

The key thing to note is that Tensorflow does not have an optimizer that functions similar to how Matlab's optimizers work. This is because the Tensorflow optimizers are essentially all designed to solve the stochastic gradient descent problem... that is, how to optimize a function when evaluating the whole function is too computationally expensive. Hence you would not only have to set up your own stopping conditions for Tensorflow, you would also have to tell it how to deal with equality constraints.

You could certainly incorporate equality constraints by introducing Lagrange multipliers, but you would have to manually do that.

If you are just interested in performing the optimization outside of Matlab, then you should try one of the methods in scipy.optimize.minimize. If you absolutely must have it in Tensorflow, then you have a LOT of work ahead of you.

bremen_matt
  • 6,902
  • 7
  • 42
  • 90