-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variable time support in create_objective_function. #205
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I assumed any specific integration routine in the manually created objective functions.
No description provided.