AlgebraicMoments is a package for automatically generating code to propagate statistical moments through polynomial expressions (constraints or dynamics).
Statisticial moments are a useful way of characterizing distributions of random variables. Motivated by the problem of chance-constrained motion planning for potentially non-Gaussian systems with nonlinear constraints and dynamics, recent works leverage statistical moments to establish upper bounds on chance-constraints. Doing so, however, often requires the user to either propagate statistical moments through dynamics or compute moments of polynomials applied to random vectors. It turns out that, when working with polynomial dynamics and constraints, it is possible to algorithmically derive closed form expressions for the necessary moments.
At the repo root, enter:
pip3 install -e .
You should then be able to import algebraic_moments
.
Unfortunately, Github currently does not currently render mathematical expressions in Markdown, so the user is advised to render this README.md themselves (for example, using VSCode + the mdmath extension).
Letting
in terms of
To simplify notation, we express moments of the above form with multi-index notation. Letting
Suppose
We can express this problem using AlgebraicMoments as simply as:
# Specify elements of the random vector and dependencies.
x = RandomVariable("x")
y = RandomVariable("y")
dependencies = [(x, y)] # Specify pairwise dependencies between variables
random_vector = RandomVector([x, y], dependencies)
# Specify the deterministic variables.
c = DeterministicVariable("c")
deterministic_variables = [c]
# Specify the moments we care about as a dictionary, with the keys being the name we want to give the moment and the values being the expression in terms of our random and deterministic variables.
expressions = {"g1" : (c * x*y**2 + y)**2, "g2" : (y*x**2 + c*y**2)**3}
And then generating code for our moment expressions is as simple as:
# Generate an instance of "MomentExpressions" and print
moment_expressions = generate_moment_expressions(expressions, random_vector, deterministic_variables)
moment_expressions.print("matlab")
The output to the terminal from executing this code is:
% Parse required inputs.
xPow2 = input_moments.xPow2;
yPow4 = input_moments.yPow4;
xPow1 = input_moments.xPow1;
yPow3 = input_moments.yPow3;
yPow2 = input_moments.yPow2;
xPow6 = input_moments.xPow6;
xPow4 = input_moments.xPow4;
yPow5 = input_moments.yPow5;
yPow6 = input_moments.yPow6;
c = input_deterministic.c;
% Moment expressions.
g1 = c.^2.*xPow2.*yPow4 + 2*c.*xPow1.*yPow3 + yPow2;
g2 = c.^3.*yPow6 + 3*c.^2.*xPow2.*yPow5 + 3*c.*xPow4.*yPow4 + xPow6.*yPow3;
For an uncertain
Given the mean and variance of
- Cantelli
- Vysochanskij-Petunin (VP)
- Gauss
Going back to the example for MomentExpressions, suppose we are interested in bounding:
We can generate the corresponding code with:
concentration_inequality = generate_concentration_inequality((c * x*y**2 + y)**2, random_vec, deterministic_vars, "cantelli")
concentration_inequality.print("python")
Let
In many cases, we want to be able to determine statistical moments of
Moment shooting is analogous to direct shooting in trajectory optimization, we essentially express the statistical moments of
The method of moment state dynamical systems (MSDS) involves finding a closed form system of equations that expresses the dynamics of a set of moments we care about. Instead of expressing the dynamics in terms of the state vector
As a simple example, consider
The idea is that the user can specify a dynamical system and a moment basis (or state) that they care about and then an algorithm called TreeRing (named as such because it is essentially tree search over the ring of polynomials) will search for a higher dimensional moment basis
Above
The currently supported languages are:
- "matlab"
- "python"
- "octave"
- str(variable.string_rep) + str(variable.power)
- No numbers
- No subscripts
- Only continuous letters