Variable time support in create_objective_function.#205
Variable time support in create_objective_function.#205moorepants wants to merge 1 commit intocsu-hmc:masterfrom
Conversation
|
Does this mean, that create_objective_function will soon be able to handle variable h? :-) |
|
Only if I can figure it out. |
I feel like you know it already! Surely will avoid these ugly expressions like in my ball/disc simulation. |
|
Just to make sure I understand it correctly:
A necessary condition for a minimum is that grad_(x, u, t_f)(J) = 0. |
|
Yes, I was starting to implement your suggestion but I think it was missing taking the derivative wrt to |
I would expect that you can just add it to the objective_grad computation, the list of symbols w.r.t. which the jacobian is computed. However, I don't remember testing the solution (in depth), but it is nice to see that you have already written some tests. |
| def expected_obj(free): | ||
| f = free[2*self.N:-1] | ||
| return free[-1]*np.sum(f**2) | ||
|
|
||
| def expected_obj_grad(free): | ||
| f = free[2*self.N:-1] | ||
| grad = np.zeros_like(free) | ||
| grad[2*self.N:-1] = 2.0*free[-1]*free[2*self.N:-1] | ||
| grad[-1] = np.sum(f**2) | ||
| return grad |
There was a problem hiding this comment.
You should take into account that this is backward Euler, so the first term falls out, see test_backward_single_input.
If free is [x(t), v(t), f1(t), f2(t), c, k, m, h] then the objective should be (f1_vals[1:]**2 + f2_vals[1:]**2).sum() * h_val.
Similarly, the gradient should be a stack of zeros(2*N+1), 2*h_val*f1_vals[1:], [0] 2*h_val*f2_vals[1:], [0, 0, 0, (f1_vals[1:]**2 + f2_vals[1:]**2).sum()]
P.S. quickly wrote out the equations on my phone so would advise checking them.
There was a problem hiding this comment.
I don't think I assumed any specific integration routine in the manually created objective functions.
There was a problem hiding this comment.
I don't think I assumed any specific integration routine in the manually created objective functions.
I have a basic question:
In the current create_objective_function(...) there is a distinction in forming obj, obj_grad depending on the integration method.
But, for example, in the examples-gallery simulation plot_pendulum_swing_up_variable_duration, the gradient is formed as I would naively expect it to be formed.
Can the gradient always be formed as per the method used in plot_pendulum_swing_up_variable_duration, or is this only valid for midpoint euler or is this a (good) approximation, if I understood #30 #31 correctly?
Thanks for any explanations!
There was a problem hiding this comment.
The examples are a little loose, but it probably doesn't matter too much in the objective calc because both methods have about the same minima.
There was a problem hiding this comment.
Thanks!
This would mean one could calculate obj and obj_grad 'naively' without committing a large error?
There was a problem hiding this comment.
The gradient of the objective has to be the valid gradient within some numerical tolerance. But your choice of solving the integral in the objective does not really matter, as there are numerous integration methods.
There was a problem hiding this comment.
Thanks!
The gradient as calculated in the simulation plot_pendulum_swing_up_variable_duration surely is the valid gradient (?)

No description provided.