This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How to call the gradient-based algorithm when the objective function and the gradient's formulas are obtained?

0 votes

I use the fenics to solve an optimization problem. The problem is like:

objective function: x^2+y^2.

Then, I can obtain the gradient of objective function corresponding to the variables x and y,

Gradient formulas: 2x and 2y

The problem is: how to call the gradient-based algorithm when the objective function and the gradient's formulas are obtained in fenics?

In fact, the optimization problem I face is far more difficult than this problem. Moreover, I am familiar with optimization process as follows

# Solve the Navier-Stokes equations
solve(F == 0, s, bcs=bcu+bcp)

# Define the optimisation proble,
alpha = Constant(1e-4)
J = Functional(inner(grad(u), grad(u))*dx + alpha*inner(f,f)*dx)
m = InitialConditionParameter(f)
rf = ReducedFunctional(J, m)

# Solve the optimisation problem
m_opt = minimize(rf, method="Newton-CG", tol=1e-8)

# Plot the optimised results
f.assign(m_opt)
solve(F == 0, s, bcs=bcu+bcp)

But, this case is different from my question because the gradient formula is given by "ReducedFunctional" while I can obtain the gradient formula by other computations.

asked Jun 25, 2017 by chen1124da FEniCS Novice (120 points)

You can try to use the minimize function in scipy in stead, see e.g here: https://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html

...