Skip to content
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

Huawei wang homotopy direct collocation #40

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
49 changes: 46 additions & 3 deletions opty/direct_collocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,16 @@ class ConstraintCollocator(object):
"""

time_interval_symbol = sym.Symbol('h', real=True)
expeirment_data_symbol = sym.Symbol('e', real=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the check, I will adjust them.

On Thu, May 19, 2016 at 2:20 PM, Jason K. Moore [email protected]
wrote:

In opty/direct_collocation.py
#40 (comment):

@@ -133,10 +133,16 @@ class ConstraintCollocator(object):
"""

 time_interval_symbol = sym.Symbol('h', real=True)
  • expeirment_data_symbol = sym.Symbol('e', real=True)

spelling


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/csu-hmc/opty/pull/40/files/2a129a976a12bdb95e64d7afaecd93fcc78afcaf#r63928902

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What text editor/IDE do you use? You should find one that checks all this stuff for you automatically. I can give recommendations if you tell me what OS you are working on.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working on Ubuntu 14.04. I am struggling in the online editing, please
recommend me a text editor/IDE. Thanks.

On Thu, May 19, 2016 at 2:31 PM, Jason K. Moore [email protected]
wrote:

In opty/direct_collocation.py
#40 (comment):

@@ -133,10 +133,16 @@ class ConstraintCollocator(object):
"""

 time_interval_symbol = sym.Symbol('h', real=True)
  • expeirment_data_symbol = sym.Symbol('e', real=True)

What text editor/IDE do you use? You should find one that checks all this
stuff for you automatically. I can give recommendations if you tell me what
OS you are working on.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/csu-hmc/opty/pull/40/files/2a129a976a12bdb95e64d7afaecd93fcc78afcaf#r63930745

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have time to google hangout for a bit right now?

"""
define symbol of expeirment data
in order to add symbolic extra term in quations of motion
"""

def __init__(self, equations_of_motion, state_symbols,
num_collocation_nodes, node_time_interval,
known_parameter_map={}, known_trajectory_map={},
known_experiment_map={}, Lamda,
instance_constraints=None, time_symbol=None, tmp_dir=None,
integration_method='backward euler'):
"""
Expand Down Expand Up @@ -166,6 +172,13 @@ def __init__(self, equations_of_motion, state_symbols,
ndarrays of floats of shape(N,). Any time varying parameters in
the equations of motion not provided in this dictionary will
become free trajectories optimization variables.
known_experiment_map : dictionary, optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't clear to me what this is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The known_parameter_map already maps numpy arrays and floats to symbols in the equations of motion. Why is a new dictionary needed?

Currently this class isn't aware of the concept of measurement data in a parameter id sense.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This known_experiment_map is the experimental data we need use in the extra term and I want to write a explanation for that. I am not sure how to write this explanation, so I wrote this according to known_trajectory_map. (might be wrong)

A dictionary that maps the state SymPy functions of time to
ndarrays of floats of shape(N,4). Any time varying parameters in
the equations of motion not provided in this dictionary will
become free trajectories optimization variables.
Lamda: float
A parameter in homotopy method that controls the change of motion equations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be careful with the name of this. lambda is a reserved word in python, it is a built in function. And sympy has Lambda which is a symbolic version of the Python lambda and creates a symbolic function. Maybe a variable name like homotopy_control or something similar is better.

integration_method : string, optional
The integration method to use, either `backward euler` or
`midpoint`.
Expand All @@ -188,7 +201,24 @@ def __init__(self, equations_of_motion, state_symbols,
to a directory here.

"""
self.eom = equations_of_motion
Lamda_Matrix = sym.Matrix([[0,0,0,0], [0,0,0,0], [0,0,Lamda,0],[0,0,0,Lamda]])
"""
define matrix Lamda = [0 0 0 0 ]
[0 0 0 0 ]
[0 0 lamda 0 ]
[0 0 0 lamda]
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to follow the Python PEP8 style guide: https://www.python.org/dev/peps/pep-0008/ for all the code. Please read over that to help with consistent formatting.

Also, you can setup your text editor or IDE to automatically detect/fix these kinds of things.


self.eom = (1-Lamada_Matrix)*equations_of_motion + Lamada_Matrix*(xd - (e - x))
"""
add extra term in equations of motion, the goal is to have the following formula:
homotopy motion equations = [1 0 0 0 ] [f1(x, xd, p, r) ] [0 0 0 0 ] [x1_dot] [e1] [x1]
0 1 0 0 * f2(x, xd, p, r) + 0 0 0 0 * ( x2_dot - ( e2 - x2 ) )
0 0 1-la 0 f3(x, xd, p, r) 0 0 la 0 x3_dot e3 x3
[0 0 0 1-la] [f4(x, xd, p, r) ] [0 0 0 la] [x4_dot] [e4] [x4]
"""

# self.eom = equations_of_motion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete this line


if time_symbol is not None:
self.time_symbol = time_symbol
Expand All @@ -205,6 +235,8 @@ def __init__(self, equations_of_motion, state_symbols,

self.known_parameter_map = known_parameter_map
self.known_trajectory_map = known_trajectory_map

self.know_experiment_map = known_experiment_map " get input experiment data into self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the # for single line and short comments.


self.instance_constraints = instance_constraints

Expand Down Expand Up @@ -408,7 +440,14 @@ def _discrete_symbols(self):
self.next_known_discrete_specified_symbols = \
tuple([sym.Symbol(f.__class__.__name__ + 'n', real=True)
for f in self.known_input_trajectories])


# The current and next known experiment data.
self.current_known_discrete_experiment_symbols = \
tuple([sym.Symbol(f.__class__.__name__ + 'i', real=True)
for f in self.known_experiment_map])
self.next_known_discrete_experiment_symbols = \
tuple([sym.Symbol(f.__class__.__name__ + 'n', real=True)
for f in self.known_experiment_map])

# The current and next unknown input trajectories.
self.current_unknown_discrete_specified_symbols = \
Expand Down Expand Up @@ -438,12 +477,15 @@ def _discretize_eom(self):
x = self.state_symbols
xd = self.state_derivative_symbols
u = self.input_trajectories
e = self.know_experiment_map " define experiment data acorrding input trajectories define

xp = self.previous_discrete_state_symbols
xi = self.current_discrete_state_symbols
xn = self.next_discrete_state_symbols
ui = self.current_discrete_specified_symbols
un = self.next_discrete_specified_symbols
ei = self.current_known_discrete_experiment_symbols " define experiment data acorrding input trajectories define
en = self.next_known_discrete_experiment_symbols " define experiment data acorrding input trajectories define

h = self.time_interval_symbol

Expand All @@ -460,7 +502,8 @@ def _discretize_eom(self):
xdot_sub = {d: (n - i) / h for d, i, n in zip(xd, xi, xn)}
x_sub = {d: (i + n) / 2 for d, i, n in zip(x, xi, xn)}
u_sub = {d: (i + n) / 2 for d, i, n in zip(u, ui, un)}
self.discrete_eom = me.msubs(self.eom, xdot_sub, x_sub, u_sub)
e_sub = {d: (i + n) / 2 for d, i, n in zip(e, ei, en)} " define experiment sub for eom
self.discrete_eom = me.msubs(self.eom, xdot_sub, x_sub, u_sub, e_sub) " add experiment data into eom

def _identify_functions_in_instance_constraints(self):
"""Instantiates a set containing all of the instance functions, i.e.
Expand Down