Coder Social home page Coder Social logo

kestrelquantum / trajectoryindexingutils.jl Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 111 KB

Utility functions for indexing and slicing trajectory data vectors

License: MIT License

Julia 100.00%
julia trajectories trajectory-optimization utility-functions

trajectoryindexingutils.jl's Introduction

TrajectoryIndexingUtils.jl

Stable Dev Build Status Coverage

This is a super lightweight package that exports two functions: index and slice. These functions have helped to ease the burden of handling messy indexing into trajectory data vectors of the form

$$\vec Z = \text{vec}\left(z_1, z_2, \ldots, z_T\right) \in \mathbf{R}^{T \cdot d}$$

where each element $z_t$ is referred to as a knot point and normally contains state variables and control variables. In a simple situation we might have $z_t = \text{vec} (x_t, u_t) \in \mathbf{R}^{d = n+m}$, for the state $x_t \in \mathbf{R}^n$ and control $u_t \in \mathbf{R}^m$. In this case, with dim = n + m, we can use slice and index, to extract what we want from $\vec Z$ in the following way:

  • extract $z_t$:
    zₜ = Z⃗[slice(t, dim)]
  • extract $x_t$:
    xₜ = Z⃗[slice(t, 1:n, dim)]
  • extract $u_t$:
    uₜ = Z⃗[slice(t, (1:m) .+ n, dim)]
  • extract $i$-th component of $x_t$:
    xₜⁱ = Z⃗[index(t, i, dim)]
  • extract $j$-th component of $u_t$:
    uₜʲ = Z⃗[index(t, j + n, dim)]

With this, the user is still responsible for keeping track of the component indices for $x$ and $u$, and possibly other variables. To alleviate this nuisance, the package NamedTrajectories.jl provides a richer alternative for handling trajectory data with arbitrarily named components, please check it out!

Installation

This package is not yet registered. To install, use the following command:

using Pkg
Pkg.add(url="https://github.com/aarontrowbridge/TrajectoryIndexingUtils.jl", rev="main")

Methods

The index function

index(t::Int, dim::Int) -> zₜ[dim]
index(t::Int, pos::Int, dim::Int) -> zₜ[pos]

The slice function

slice(t::Int, dim::Int; stretch=0) -> zₜ[1:dim + stretch] # can be used to extract, e.g., [xₜ; xₜ₊₁], with stretch = dim
slice(t::Int, pos::Int, dim::Int) -> zₜ[1:pos]
slice(t::Int, pos1::Int, pos2::Int, dim::Int) -> zₜ[pos1:pos2]
slice(t::Int, indices::AbstractVector{Int}, dim::Int) -> zₜ[indices]
slice(ts::UnitRange{Int}, dim::Int) -> vec(zₜ for t  ts)

TODO

  • Add tests
  • Add examples
  • Add documentation
  • Add methods that take in trajectory vector as the first argument
  • Add block function for accessing blocks of matrices with trajectory structure, e.g. jacobians & hessians

trajectoryindexingutils.jl's People

Contributors

aarontrowbridge avatar

Stargazers

xiangze avatar

Watchers

 avatar

Forkers

makzator

trajectoryindexingutils.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.