-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from ErikQQY/qqy/params
Add global trajectory parameters
- Loading branch information
Showing
5 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# # Add params in NamedTrajectory | ||
|
||
# NamedTrajectory.jl support passing parameters as a Tuple when construct a `NamedTrajectory`. | ||
|
||
using NamedTrajectories | ||
|
||
# First we need to define number of timesteps and timestep | ||
T = 10 | ||
dt = 0.1 | ||
|
||
# then build named tuple of components and data matrices. | ||
components = ( | ||
x = rand(3, T), | ||
u = rand(2, T), | ||
Δt = fill(dt, 1, T), | ||
) | ||
|
||
# we must specify a timestep and control variable for the trajectory. | ||
|
||
timestep = 0.1 | ||
control = :u | ||
|
||
# some global params as a NamedTuple | ||
params = ( | ||
α = rand(1), | ||
β = rand(1) | ||
) | ||
|
||
# we can now create a `NamedTrajectory` object with parameters specification. | ||
traj = NamedTrajectory(components; timestep=timestep, controls=control, params=params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
```@meta | ||
EditURL = "../../../literate/man/params_in_struct.jl" | ||
``` | ||
|
||
# Add params in NamedTrajectory | ||
|
||
NamedTrajectory.jl support passing parameters as a Tuple when construct a `NamedTrajectory`. | ||
|
||
````@example params_in_struct | ||
using NamedTrajectories | ||
```` | ||
|
||
First we need to define number of timesteps and timestep | ||
|
||
````@example params_in_struct | ||
T = 10 | ||
dt = 0.1 | ||
```` | ||
|
||
then build named tuple of components and data matrices. | ||
|
||
````@example params_in_struct | ||
components = ( | ||
x = rand(3, T), | ||
u = rand(2, T), | ||
Δt = fill(dt, 1, T), | ||
) | ||
```` | ||
|
||
we must specify a timestep and control variable for the trajectory. | ||
|
||
````@example params_in_struct | ||
timestep = 0.1 | ||
control = :u | ||
```` | ||
|
||
some global params as a NamedTuple | ||
|
||
````@example params_in_struct | ||
params = ( | ||
α = rand(1), | ||
β = rand(1) | ||
) | ||
```` | ||
|
||
we can now create a `NamedTrajectory` object with parameters specification. | ||
|
||
````@example params_in_struct | ||
traj = NamedTrajectory(components; timestep=timestep, controls=control, params=params) | ||
```` | ||
|
||
--- | ||
|
||
*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
test: struct_named_trajectory.jl | ||
""" | ||
|
||
@testset "testing constructor" begin | ||
# define number of timesteps and timestep | ||
T = 10 | ||
dt = 0.1 | ||
|
||
components = ( | ||
x = rand(3, T), | ||
u = rand(2, T), | ||
Δt = fill(dt, 1, T), | ||
) | ||
|
||
timestep = 0.1 | ||
control = :u | ||
|
||
# some global params as a NamedTuple | ||
params = ( | ||
α = rand(1), | ||
β = rand(1) | ||
) | ||
|
||
traj = NamedTrajectory(components; timestep=timestep, controls=control, params=params) | ||
|
||
@test traj.params == params | ||
end |