Skip to content

Commit

Permalink
Merge pull request #112 from decargroup/add_tutorial
Browse files Browse the repository at this point in the history
Add a short tutorial on CompositeState
  • Loading branch information
CharlesCossette authored Feb 5, 2024
2 parents 8cc2119 + b02d6d1 commit 65fb040
Show file tree
Hide file tree
Showing 6 changed files with 433 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Below is a list of all the modules in the navlie package. Click on any of the l
:recursive:
:template: custom-module-template.rst

navlie.composite
navlie.datagen
navlie.filters
navlie.imm
Expand Down
3 changes: 2 additions & 1 deletion docs/source/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ All the dependencies should get installed by this command and the package should
1. Getting Started <self>
2. Toy Problem - Traditional <./tutorial/traditional.ipynb>
3. Toy Problem - Lie groups <./tutorial/lie_groups.ipynb>
4. Specifying Jacobians <./tutorial/jacobians.ipynb>
4. Specifying Jacobians <./tutorial/jacobians.ipynb>
4. Composite States <./tutorial/composite.ipynb>
406 changes: 406 additions & 0 deletions docs/source/tutorial/composite.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/source/tutorial/lie_groups.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@
" self.Q = input_covariance_matrix\n",
"\n",
" def evaluate(self, x:SE2State, u:nav.lib.VectorInput, dt:float):\n",
" u = np.array([u.value[0], u.value[1], 0])\n",
" vel = np.array([u.value[0], u.value[1], 0])\n",
" x_next = x.copy()\n",
" x_next.value = x.value @ expm(wedge_se2(u * dt))\n",
" x_next.value = x.value @ expm(wedge_se2(vel * dt))\n",
" return x_next\n",
" \n",
" def input_covariance(self, x:SE2State, u:nav.lib.VectorInput, dt:float):\n",
Expand Down
22 changes: 18 additions & 4 deletions navlie/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,15 +527,29 @@ def covariance(
class CompositeMeasurementModel(MeasurementModel):
"""
Wrapper for a standard measurement model that assigns the model to a specific
substate (referenced by `state_id`) inside a CompositeState.
substate (referenced by `state_id`) inside a CompositeState. This class
will take care of extracting the relevant substate from the CompositeState,
and then applying the measurement model to it. It will also take care of
padding the Jacobian with zeros appropriately to match the degrees of freedom
of the larger CompositeState.
"""

def __init__(self, model: MeasurementModel, state_id):
"""
Parameters
----------
model : MeasurementModel
Standard measurement model, which is appropriate only for a single
substate in the CompositeState.
state_id : Any
The unique ID of the relevant substate in the CompositeState, to
assign the measurement model to.
"""
self.model = model
self.state_id = state_id

def __repr__(self):
return f"{self.model}(of substate {self.state_id})"
return f"{self.model} (of substate '{self.state_id}')"

def evaluate(self, x: CompositeState) -> np.ndarray:
return self.model.evaluate(x.get_state_by_id(self.state_id))
Expand All @@ -556,8 +570,8 @@ def covariance(self, x: CompositeState) -> np.ndarray:
class CompositeMeasurement(Measurement):
def __init__(self, y: Measurement, state_id: Any):
"""
Converts a standard Measurement into a CompositeMeasurement, which
replaces the model with a CompositeMeasurementModel.
Converts a standard ``Measurement`` into a CompositeMeasurement, which
simply replaces the model with a CompositeMeasurementModel.
Parameters
----------
Expand Down
7 changes: 4 additions & 3 deletions navlie/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ def correct(
def generate_sigmapoints(
dof: int, method: str
) -> Tuple[np.ndarray, np.ndarray]:
"""Generates unit sigma points from three available
methods.
"""
Generates unit sigma points from three available methods.
Parameters
----------
Expand All @@ -466,7 +466,8 @@ def generate_sigmapoints(
Returns
-------
Tuple[np.ndarray, np.ndarray]
returns the unit sigma points and the weights
returns the unit sigma points and the weights, respectively. For the
sigmapoints, each *column* will represent a sigma point.
"""
if method == "unscented":
kappa = 2
Expand Down

0 comments on commit 65fb040

Please sign in to comment.