-
Notifications
You must be signed in to change notification settings - Fork 21
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
method to generate an initial guess. Fixes #354 #365
base: master
Are you sure you want to change the base?
Conversation
Is there a good choice of one of the existing examples to add this to? You can show how it is used to the user. |
You mean in examples-gallery? |
You can include the change to the example here. |
opty/direct_collocation.py
Outdated
|
||
Returns | ||
------- | ||
initial_guess : (n*N + q*N + r + s)-ndarray |
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.
initial_guess : (n*N + q*N + r + s)-ndarray | |
initial_guess : ndarray, shape(n*N + q*N + r + s,) |
ux: (-1.0, 1.0), | ||
y: (-4.0, 4.0), | ||
uy: (-1.0, 1.0), | ||
} |
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.
x.func(t1) - 1.5*b1, | ||
y.func(t1) - 4.0, | ||
ux.func(t1) - 1.0+b2, | ||
uy.func(t1) - 4.5, |
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.
In this case I would expect uy to go from 0.0 to 4.5 to 0.0., but you set it to 4.5 to 4.5 to 4.5.
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.e. if not specified, the guess should be at zero
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.
but maybe this more a design question. if there is only one instance constraint, what assumption to we make about any other values of time?
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.
but maybe this more a design question. if there is only one instance constraint, what assumption to we make about any other values of time?
My assumption was that if there is only one instance constraint for a state variable it will have this value at all times. I thought this was the most reasonable one.
|
||
# A2: np.inf, -np.inf in bounds | ||
bounds[a1] = (-np.inf, 10.0) | ||
bounds[a2] = (-10.0, np.inf) |
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.
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.
a1, a2 are unknown parameters. I set their initial value like this: if there is a bound {a1: (s, t)} I set it at (s + t) /2.
If one of s or t is np.inf I set it to the other (finite) value.
I did not consider bounds which have np.inf on both ends, as they do not make sense in my opinion.
Parameters do not show in the plots.
|
||
x.func(tf) + 1.0, | ||
ux.func(tf) + 5.0, | ||
) |
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.
y: (-4.0, 4.0), | ||
uy: (-1.0, 1.0), | ||
h: (1.0, 2.0), | ||
} |
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.
|
||
# B2: np.inf, -np.inf in bounds | ||
bounds[a1] = (-np.inf, 10.0) | ||
bounds[a2] = (-10.0, np.inf) |
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.
initial_guess = prob.create_linear_initial_guess() | ||
np.testing.assert_allclose(initial_guess, expected_guess) | ||
|
||
# B3: no bounds |
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.
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.
These 'peak' plots happen like this If there is no bound for h, h is assumed to be zero.
So, all times ti = integer * h = 0.
The plots for u1, u2 should have a dot at (0 | 0).
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 guess h should never be zero, right? So maybe we should always assume a value for it...but what value?
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 guess h should never be zero, right? So maybe we should always assume a value for it...but what value?
I have found, that one should always bound h to be non-negative, to avoid senseless 'solutions'.
If there is a bound, say, {h: (0, 0.5)} I set h = 0.25.
So, maybe this would not be a bad default value?
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.
Without the user giving some idea of what the total duration of the simulation might be, it's hard (or impossible) to pick a starting number. If someone is simulating molecular dynamics, maybe their duration is a tenth of a second. I guess we could default to some very small value of h. Or this function could take an extract kwarg: expected_duration=10.0
where the user can give us a bit more info.
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.
The expected duration could default to 1.0 second (just as a simple number).
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.
The expected duration could default to 1.0 second (just as a simple number).
I will do so.
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.
So you like the idea of the kwarg to give a clue on duration?
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.
So you like the idea of the kwarg to give a clue on duration?
I like it! I did not think of it, as you normally do not like them.
Default would be false?
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 dislike kwargs.
Default would be 1.0
.
|
||
x.func(tf0) + 1.0, | ||
ux.func(tf0) + 5.0, | ||
) |
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 added a commit, so pull this branch before you edit more. You can now do:
to quickly plot your guesses. |
Not sure I totally understand (you know my computer skills...or lack thereof...) |
All your do is |
Thanks! |
Just found a MAJOR plunder! Have to go back to the drawing board. |
NB:
|
Is it o.k. to be a method, or should I make it a property?