pyrieef.geometry package¶
Submodules¶
pyrieef.geometry.attractors module¶
-
pyrieef.geometry.attractors.
MakeAttractor
(phi, x_goal)¶ Implements |phi(x) - phi(x_g)|, where phi is a DifferentiableMap Note that this is an absolute distance, not the squared distance. Squaring this function (e.g. as part of a penalty function) gives a squared potential.
pyrieef.geometry.charge_simulation module¶
pyrieef.geometry.diffeomorphisms module¶
-
class
pyrieef.geometry.diffeomorphisms.
AnalyticCircle
(origin=[0.1, -0.1], radius=0.1)¶ Bases:
pyrieef.geometry.diffeomorphisms.AnalyticPlaneDiffeomoprhism
-
Deformationforward
(x)¶ squishes points inside the circle
-
Deformationinverse
(y)¶ maps them back outside of the circle
-
distance_before_contraction
(x, d_2)¶
-
forward
(x)¶ squishes points inside the circle
-
inverse
(y)¶ maps them back outside of the circle
-
object
()¶ Access the internal object.
-
radius
(x)¶
-
set_alpha
(a, b)¶ To recover the distance scaling one should pass the alpha and beta inverse functions.
-
-
class
pyrieef.geometry.diffeomorphisms.
AnalyticConvexPolygon
(origin=[0.1, -0.1], polygon=None)¶ Bases:
pyrieef.geometry.diffeomorphisms.AnalyticPlaneDiffeomoprhism
-
Deformationforward
(x)¶ squishes points inside the circle
-
Deformationinverse
(y)¶ maps them back outside of the circle
-
distance_before_contraction
(x, d_2)¶
-
forward
(x)¶ squishes points inside the circle
-
inverse
(y)¶ maps them back outside of the circle
-
object
()¶ Access the internal object.
-
radius
(x)¶
-
set_alpha
(a, b)¶ To recover the distance scaling one should pass the alpha and beta inverse functions.
-
-
class
pyrieef.geometry.diffeomorphisms.
AnalyticEllipse
¶ Bases:
pyrieef.geometry.diffeomorphisms.AnalyticPlaneDiffeomoprhism
-
Deformationforward
(x)¶
-
Deformationinverse
(y)¶
-
forward
(x)¶ Should return an array or single value
-
inverse
(y)¶
-
object
()¶
-
set_alpha
(a, b)¶
-
-
class
pyrieef.geometry.diffeomorphisms.
AnalyticMultiDiffeo
(diffeomorphisms)¶ Bases:
pyrieef.geometry.diffeomorphisms.AnalyticPlaneDiffeomoprhism
-
activations
(x)¶ This activation function is implemented through a softmax function.
-
activations_inv
(y)¶ This activation function is implemented through a softmax function.
-
forward
(x)¶ Should return an array or single value
-
inverse
(y)¶ This is not really the inverse, it is an approximation
-
object
()¶
-
-
class
pyrieef.geometry.diffeomorphisms.
AnalyticPlaneDiffeomoprhism
¶ Bases:
pyrieef.geometry.diffeomorphisms.PlaneDiffeomoprhism
-
abstract
object
()¶
-
abstract
-
class
pyrieef.geometry.diffeomorphisms.
ComposeDiffeo
(f, g)¶ Bases:
pyrieef.geometry.differentiable_geometry.Compose
-
inverse
(y)¶
-
-
class
pyrieef.geometry.diffeomorphisms.
ConvexPolygon
(origin=array([0., 0.]), verticies=[array([0.5, 0.5]), array([-0.5, 0.5]), array([-0.5, -0.5]), array([ 0.5, -0.5])])¶ Bases:
pyrieef.geometry.workspace.Polygon
-
focus
()¶
-
intersection_point
(x)¶ point on the boundary that intersects the line between the focus and a given point TODO : test this function
-
-
class
pyrieef.geometry.diffeomorphisms.
Diffeomoprhism
¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
-
abstract
inverse
(y)¶
-
output_dimension
()¶
-
abstract
-
class
pyrieef.geometry.diffeomorphisms.
ElectricCircle
¶ Bases:
pyrieef.geometry.diffeomorphisms.AnalyticPlaneDiffeomoprhism
-
forward
(x)¶ Should return an array or single value
-
inverse
(y)¶
-
object
()¶
-
-
pyrieef.geometry.diffeomorphisms.
InterpolationGeodescis
(obj, x_1, x_2)¶
-
pyrieef.geometry.diffeomorphisms.
NaturalGradientGeodescis
(obj, x_1, x_2, attractor=True)¶
-
class
pyrieef.geometry.diffeomorphisms.
PlaneDiffeomoprhism
¶ Bases:
pyrieef.geometry.diffeomorphisms.Diffeomoprhism
-
input_dimension
()¶
-
-
class
pyrieef.geometry.diffeomorphisms.
PolarCoordinateSystem
¶ Bases:
pyrieef.geometry.diffeomorphisms.AnalyticPlaneDiffeomoprhism
-
forward
(p)¶ Should return an array or single value
-
inverse
(p)¶
-
object
()¶
-
-
class
pyrieef.geometry.diffeomorphisms.
SoftmaxWithInverse
(gamma)¶ Bases:
pyrieef.geometry.diffeomorphisms.Diffeomoprhism
Maps a vector to the softmax value:
f_i (x) = exp(x_i) / sum_j exp(x_j)
-
forward
(x)¶ Compute the softmax of vector x.
-
inverse
(y)¶ Inverse of softmax for vector y.
-
-
pyrieef.geometry.diffeomorphisms.
alpha2_f
(eta, r, gamma, x)¶
-
pyrieef.geometry.diffeomorphisms.
alpha3_f
(eta, r, gamma, x)¶
-
pyrieef.geometry.diffeomorphisms.
alpha_f
(eta, r, gamma, x)¶
-
pyrieef.geometry.diffeomorphisms.
beta2_f
(eta, r, gamma, x)¶
-
pyrieef.geometry.diffeomorphisms.
beta2_inv_f
(eta, r, gamma, y)¶
-
pyrieef.geometry.diffeomorphisms.
beta3_f
(eta, r, gamma, x)¶
-
pyrieef.geometry.diffeomorphisms.
beta3_inv_f
(eta, r, gamma, y)¶
-
pyrieef.geometry.diffeomorphisms.
beta_f
(eta, r, gamma, x)¶
-
pyrieef.geometry.diffeomorphisms.
beta_inv_f
(eta, r, gamma, y)¶
-
pyrieef.geometry.diffeomorphisms.
ellipse_polygon
(a, b, focus=[0.0, 0.0], translation=[0.0, 0.0], orientation=0.0)¶
pyrieef.geometry.differentiable_geometry module¶
-
class
pyrieef.geometry.differentiable_geometry.
AffineMap
(a, b)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Simple map of the form: f(x)=ax + b
-
a
()¶
-
forward
(x)¶ Should return an array or single value
-
hessian
(x)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
input_dimension
()¶
-
jacobian
(x)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
Arccos
¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
f(x) = arccos(x)
-
forward
(x)¶ Should return an array or single value
-
hessian
(x)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
input_dimension
()¶
-
jacobian
(x)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
CombinedOutputMap
(maps)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
creates a combination of the maps phi(x) = [phi1(x); phi2(x); …; phiN(x)] TODO : Test
-
forward
(q)¶ Should return an array or single value
-
input_dimension
()¶
-
jacobian
(q)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
Compose
(f, g)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
-
evaluate
(q)¶ d/dq f(g(q)), applies chain rule.
-
forward
(q)¶ Should return an array or single value
-
hessian
(q)¶ d^2/dq^2 f(g(q)), applies chain rule.
J_g’ H_f J_g + H_g J_f,
so far only works if f and g are functions, not maps. https://en.wikipedia.org/wiki/Chain_rule (Higher derivatives) WARNING: J_f is assumed to be a jacobian np.matrix object
-
input_dimension
()¶
-
jacobian
(q)¶ d/dq f(g(q)), applies chain rule.
J_f(g(q)) J_g
- If J is the jacobian of a function f(x), J_f = d/dx f(x)
then the jacobian of the “pullback” of f defined on the range space of a map g, f(g(q)) is
d/dq f(g(q)) = J_f(g(q)) J_g
This method computes and returns this “pullback gradient” J_f (g(q)) J_g(q). WARNING: J_f is assumed to be a jacobian np.matrix object
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
DifferentiableMap
¶ Bases:
object
-
evaluate
(q)¶ Evaluates the map and jacobian simultaneously. The default implementation simply calls both forward and Getjacobian() separately but overriding this method can make the evaluation more efficient
-
abstract
forward
(q)¶ Should return an array or single value
-
gradient
(q)¶ - Should return an array or single value
n : input dimension
Convienience function to get numpy gradients in the same shape as the input vector for addition and substraction, of course gradients are only availables if the output dimension is one.
-
hessian
(q)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
abstract
input_dimension
()¶
-
jacobian
(q)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
abstract
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
ExpTestFunction
¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Test function that can be evaluated on a grid
-
forward
(p)¶ Should return an array or single value
-
input_dimension
()¶
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
IdentityMap
(n)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Simple identity map : f(x)=x
-
forward
(q)¶ Should return an array or single value
-
hessian
(x)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
input_dimension
()¶
-
jacobian
(q)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
LogSumExp
(n, gamma)¶ Bases:
pyrieef.geometry.differentiable_geometry.SoftMax
Log of softmax (smooth max)
f(x) = (1 / gamma) * log[ sum_j exp(gamma * x_j) ]
A normalized version can be defined when all the monoids are positive f(x) = log( sum(z) - (1-n))
-
forward
(x)¶ Should return an array or single value
-
hessian
(x)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
jacobian
(x)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
MakeDifferentiableMap
(f, g, m, n)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Make a function a differentiable map
-
forward
(x)¶ Should return an array or single value
-
input_dimension
()¶
-
jacobian
(x)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
Norm
(x_0=None)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Simple norm f(x) = |x - x_0|
-
forward
(x)¶ Should return an array or single value
-
gradient
(x)¶ - Should return an array or single value
n : input dimension
Convienience function to get numpy gradients in the same shape as the input vector for addition and substraction, of course gradients are only availables if the output dimension is one.
-
hessian
(x)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
input_dimension
()¶
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
Normalize
(n)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
f(x) = x / |x|
-
forward
(x)¶ Should return an array or single value
-
input_dimension
()¶
-
jacobian
(x)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
ProductFunction
(g, h)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Take the product of functions
-
forward
(x)¶ Should return an array or single value
-
hessian
(x)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
input_dimension
()¶
-
jacobian
(x)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
Pullback
(f, g)¶ Bases:
pyrieef.geometry.differentiable_geometry.Compose
-
hessian
(q)¶ d^2/dq^2 f(g(q)), applies chain rule.
J_g’ H_f J_g + H_g J_f,
here we dropout the higher order term of g this cooresponds to the full hessian when H_g = 0 WARNING: f still has to be a function for now.
-
-
class
pyrieef.geometry.differentiable_geometry.
QuadricFunction
(a, b, c)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Here we implement a quadric funciton of the form: f(x) = 1/2 x^T A x + bx + c
-
forward
(x)¶ Should return an array or single value
-
hessian
(x)¶ when the matrix is positive this can be simplified see matrix cookbook
-
input_dimension
()¶
-
jacobian
(x)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
RadialBasisFunction
(x0, H)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Implements an unnormalized Gaussian
f(x) = exp( -1/2 |x - x0|^2_H )
- phi(x) = 1/2 (x - x0)^T H (x - x0)
= 1/2 [ x^T H (x - x0) - x0^T H (x - x0) ] = 1/2 [ x^T H x - x^T H x0 - x0^T H x + x0^T H x0 ] = 1/2 [ x^T H x - 2 x0^T H x - x0^T H x0 ]
Create a Gaussian function centered at x0 with Hessian (inverse covariance) H
- TODO:
implement as pullback for derivatives…
tod check the math…
-
forward
(x)¶ Should return an array or single value
-
input_dimension
()¶
-
output_dimension
()¶
-
class
pyrieef.geometry.differentiable_geometry.
RangeSubspaceMap
(n, indices)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Takes only some outputs
-
forward
(q)¶ Should return an array or single value
-
hessian
(q)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
input_dimension
()¶
-
jacobian
(q)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
Scale
(f, alpha)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Scales a function by a constant
-
forward
(q)¶ Should return an array or single value
-
hessian
(q)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
input_dimension
()¶
-
jacobian
(q)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
Sigmoid
(n)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
f(x) = 1 / (1 + e^-x)
-
forward
(x)¶ Should return an array or single value
-
hessian
(x)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
input_dimension
()¶
-
jacobian
(x)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
SoftMax
(n, gamma)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Softmax
f(x) = exp(x_i) / sum_j exp(x_j)
-
forward
(x)¶ Should return an array or single value
-
input_dimension
()¶
-
jacobian
(q)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
SquaredNorm
(x_0)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Simple squared norm : f(x)= | x - x_0 | ^2
-
forward
(x)¶ Should return an array or single value
-
hessian
(x)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
input_dimension
()¶
-
jacobian
(x)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
SumOfTerms
(functions)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Sums n differentiable maps
-
forward
(q)¶ Should return an array or single value
-
hessian
(q)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
input_dimension
()¶
-
jacobian
(q)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
Tanh
(n)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
f(x) = (1 - e^-2x) / (1 + e^-2x)
-
forward
(x)¶ Should return an array or single value
-
hessian
(x)¶ TODO
-
input_dimension
()¶
-
jacobian
(x)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.differentiable_geometry.
ZeroMap
(m, n)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Simple zero map : f(x)=0
-
forward
(q)¶ Should return an array or single value
-
hessian
(x)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
input_dimension
()¶
-
jacobian
(q)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
pyrieef.geometry.differentiable_geometry.
check_hessian_against_finite_difference
(phi, verbose=True, tolerance=0.0001)¶ Makes sure the hessuaian is close to the finite difference
-
pyrieef.geometry.differentiable_geometry.
check_is_close
(a, b, tolerance=1e-10)¶ Returns True of all variable are close.
-
pyrieef.geometry.differentiable_geometry.
check_jacobian_against_finite_difference
(phi, verbose=True, tolerance=0.0001)¶ Makes sure the jacobian is close to the finite difference
-
pyrieef.geometry.differentiable_geometry.
finite_difference_hessian
(f, q)¶ Takes an object f that has a forward method returning a numpy array when querried.
-
pyrieef.geometry.differentiable_geometry.
finite_difference_jacobian
(f, q)¶ Takes an object f that has a forward method returning a numpy array when querried.
pyrieef.geometry.geodesics module¶
-
pyrieef.geometry.geodesics.
ComputeGeodesic
(simulation, x_1, x_2)¶
-
pyrieef.geometry.geodesics.
ComputeInitialVelocityGeodescis
(simulation, x, x_dot)¶
-
pyrieef.geometry.geodesics.
ComputeInterpolationGeodescis
(simulation, x_1, x_2)¶
-
pyrieef.geometry.geodesics.
ComputeNaturalGradient
(simulation, x_1, x_2)¶
-
pyrieef.geometry.geodesics.
ComputeTensor
(simulation, p, delta=0.001)¶
pyrieef.geometry.heat_diffusion module¶
-
pyrieef.geometry.heat_diffusion.
compare_with_kernel
(u_t, t, workspace)¶
-
pyrieef.geometry.heat_diffusion.
crank_nicholson_2d
(dt, h, source_grid, iterations, occupancy)¶ Crank-Nicholson algorithm with matrix inversion we use a row major representation of the matrix
h : space discretization t : time discretization
- U(i,j,m+1) = U(i,j,m) + k*Discrete-2D-Laplacian(U)(i,j,m)
k
- = (1 - 4* —) * U(i,j,m) +
h^2
k
— * (U(i-1,j,m) + U(i+1,j,m) + U(i,j-1,m) + U(i,j+1,m)) h^2
-
pyrieef.geometry.heat_diffusion.
discrete_2d_gradient
(M, N, axis=0)¶ Efficient allocation of the Discrete-2D-Gradient
-
pyrieef.geometry.heat_diffusion.
discrete_2d_laplacian
(M, N, matrix_form=False)¶ Efficient allocation of the Discrete-2D-Laplacian
- TODOs
change allocation in crank_nicholson_2d
can do better with range instead of for loop!
-
pyrieef.geometry.heat_diffusion.
distance
(U, V, D, dh)¶ Find the distance of a gradient on a 2d grid
[U, V] : gradient is given as two matrices D : divergence
we use a row major convention A = [a11, a12, a13, a21, a22, a23, …, aMN]
# D = divergence(gradient) # Dc = D.copy() # D[source[1], source[0]] = 1000 # D[np.where(occupancy.T > 0)] = np.Inf D = D.flatten() # idxs_o = np.where(D == np.Inf) # idxs_i = np.where(D < np.Inf) # A = np.delete(A, idxs_o, axis=0) # A = np.delete(A, idxs_o, axis=1) # D = np.delete(D, idxs_o) # phi = D # phi -= phi.min() # dist = np.empty(M * N) # for i in range(len(idxs_i[0])): # dist[idxs_i[0][i]] = phi[i] # dist[idxs_o] = 10
-
pyrieef.geometry.heat_diffusion.
distance_from_gradient
(U, V, dh, f=None)¶ Get a scalar field from gradients
-
pyrieef.geometry.heat_diffusion.
divergence
(f)¶ Compute the discrete divergence of a vector field
-
pyrieef.geometry.heat_diffusion.
forward_euler_2d
(dt, h, source_grid, iterations, occupancy)¶ Forward Euler Integration of the heat equation
h : space discretization t : time discretization
-
pyrieef.geometry.heat_diffusion.
heat_diffusion
(workspace, source, iterations)¶ Diffuses heat from a source point on a 2D grid defined over a workspace populated by obstacles.
The function was implemented by following https://people.eecs.berkeley.edu/~demmel/ cs267/lecture17/lecture17.html#link_1.5
TODO test it agains the heat kernel
-
pyrieef.geometry.heat_diffusion.
kernel
(t, d, dim=2)¶
-
pyrieef.geometry.heat_diffusion.
normalized_gradient
(field)¶ Compute the discrete normalized gradient from scalar field
-
pyrieef.geometry.heat_diffusion.
poisson_equation
(D, dh)¶ Find the distance of a gradient on a 2d grid
https://en.wikipedia.org/wiki/Discrete_Poisson_equation
D : divergence
we use a row major convention A = [a11, a12, a13, a21, a22, a23, …, aMN]
pyrieef.geometry.interpolation module¶
-
class
pyrieef.geometry.interpolation.
LWR
(m, n)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Embeds the Locally Weighted Regressor
This allows it to be used for interpolation of derivatives on multi-dimensional output
-
forward
(p)¶ Should return an array or single value
-
input_dimension
()¶
-
output_dimension
()¶
-
-
pyrieef.geometry.interpolation.
distance_at_weight_threshold
(weight_threshold)¶
-
pyrieef.geometry.interpolation.
linear_regression
(X, Y, w_t, lambda_1, lambda_2)¶ linear regression with proximal regularization
X : matrix of input Y : vector of targets lambda_1 : L2 regularizer lambda_2 : proximal regularizer
-
pyrieef.geometry.interpolation.
locally_weighted_regression
(x_query, X, Y, D, ridge_lambda)¶ Vector x_query Matrix X Vector Y Matrix D Sacalar ridge_lambda
- Calculates the locally weighted regression at the query point.
- Parameters:
x_query is a column vector with the query point. X’s rows contain domain points. Y’s entries contain corresponding targets. D gives the Mahalanobis metric as: dist(x_query, x) = sqrt( (x_query - x)’D(x_query - x) ) ridge_lambda is the regression regularizer, denoted lambda in the calculation below
- Calculates:
beta^* = argmin 1/2 |Y - X beta|_W^2 + lambda/2 |w|^2
- with W a diagonal matrix with elements
w_i = exp{ -1/2 |x_query - x_i|_D^2
Solution: beta^* = inv(X’WX + lambda I)X’WY. Final returned value: beta^*’x_query.
Note that all points are augmented with an extra
constant feature to handle the bias.
-
pyrieef.geometry.interpolation.
lwr_weight
(x, x_data, D)¶
-
pyrieef.geometry.interpolation.
lwr_weight_from_dist
(square_distance)¶
-
pyrieef.geometry.interpolation.
mahalanobis_distance
(x1, x2, D)¶
-
pyrieef.geometry.interpolation.
mahalanobis_square_distance
(x1, x2, D)¶
-
pyrieef.geometry.interpolation.
rescale_mahalanobis_metric
(distance_threshold, corresponding_weight_threshold, D)¶ Rescale the Mahalanobis metric so that the weight at the specified distance is the given threshold. D is both an input parameter specifying the Mahalanobis metric and an output parameter storing the scaled matrix. It’s assumed that distance_threshold is in units given by the Mahalanobis metric.
Algebra: exp{ -s d^2/2} = w, solve for s (d is the distance threshold, w is the corresponding weight threshold). Solution: s = -2/d^2 log(w)
pyrieef.geometry.pixel_map module¶
-
class
pyrieef.geometry.pixel_map.
PixelMap
(resolution, extent=<pyrieef.geometry.pixel_map.Extent object>)¶ Bases:
object
Implements an axis aligned regular pixel-grid map. It follows the convention that we use on the C++ version of the class. which means that the min and max extent are the origin of the world coordinates.
-
grid_to_world
(p)¶ world coorindates of the center of a grid cell
-
world_to_grid
(x)¶ grid coordinates of a point in world coordinates.
-
world_to_matrix
(x)¶ matrix coordinates allow to visualy compare with world on a flat screen these are the coordinates used for representing 2D environments
-
-
class
pyrieef.geometry.pixel_map.
RegressedPixelGridSpline
(matrix, resolution, extent=<pyrieef.geometry.pixel_map.Extent object>)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
Lightweight wrapper around the Analytical grid to implement the NDimZerothOrderFunction interface. Upon construction can decide whether the to use the finite-differenced Hessian or to replace it with the identity matrix.
-
extent
()¶
-
forward
(p)¶ Should return an array or single value
-
input_dimension
()¶
-
jacobian
(p)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
pyrieef.geometry.pixel_map.
costmap_from_matrix
(extent, matrix)¶ Creates a costmap wich is continuously defined given a matrix
-
pyrieef.geometry.pixel_map.
edt
(image)¶
-
pyrieef.geometry.pixel_map.
sample_uniform
(extent)¶ Sample uniformly point in extend
-
pyrieef.geometry.pixel_map.
sdf
(image)¶
-
pyrieef.geometry.pixel_map.
two_dimension_function_evaluation
(X, Y, phi)¶ Evaluates a function at X Y test points given by meshgrid
x = y = np.linspace(min, max, n) X, Y = np.meshgrid(x, y)
X : numpy array (n, n) Y : numpy array (n, n) phi : function
pyrieef.geometry.rotations module¶
-
pyrieef.geometry.rotations.
rand_rotation_3d_matrix
(deflection=1.0, randnums=None)¶ Creates a random rotation matrix.
- deflectionfloat
the magnitude of the rotation. For 0, no rotation; for 1, competely random rotation. Small deflection => small perturbation. randnums: 3 random numbers in the range [0, 1]. If None, they will be auto-generated.
-
pyrieef.geometry.rotations.
rotation_matrix_2d
(degree)¶ Compose a rotation matrix using using a conversion from degrees
- degreefloat
angle in degree
-
pyrieef.geometry.rotations.
rotation_matrix_2d_radian
(theta)¶ Compose a rotation matrix using radians
- thetafloat
angle of rotation
-
pyrieef.geometry.rotations.
vectors_angle
(v1, v2)¶ Computes an angle between two vectors the angle is restricted to the range [0, 2pi]
- v1array like (n, )
vector 1
- v1array like (n, )
vector 2
pyrieef.geometry.utils module¶
-
pyrieef.geometry.utils.
interpolate
(p_1, p_2, d_param, dist)¶ interpolate between points
-
pyrieef.geometry.utils.
line_line_intersection
(p1, p2, p3, p4)¶ Determines the intersection point between two lines L1 and L2
This function is degenerated when the slope can not be computed (i.e, vertical line)
p1, p2 : points on L1 p3, p4 : points on L2
see https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
-
pyrieef.geometry.utils.
line_line_intersection_det
(p1, p2, p3, p4)¶ Determines the intersection point between two lines L1 and L2
p1, p2 : points on L1 p3, p4 : points on L2
see https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection
-
pyrieef.geometry.utils.
line_parameters
(p1, p2)¶ - Extract 2D line parameters from two points
where the line equation is y = ax + b
p1, p2 : 2d arrays
-
pyrieef.geometry.utils.
lw
(x)¶ Lambert W function, for real x >= 0.
-
pyrieef.geometry.utils.
make_transformation
(translation, rotation)¶ Create a homogeneous matrix
-
pyrieef.geometry.utils.
normalize
(v)¶
pyrieef.geometry.workspace module¶
-
class
pyrieef.geometry.workspace.
AxisAlignedBox
(origin=array([0., 0.]), dim=array([1., 1.]))¶ Bases:
pyrieef.geometry.workspace.Box
- An axis aligned box (hypercube) defined by
origin : its center
dim : its extent
-
dist_from_border
(x)¶ Returns the sign distance at x.
x : numpy array
-
dist_gradient
(x)¶ Returns the gradient of the distance function.
Note that for the first order, the signed distance function of any shape is fully expressed by the closet point to the border. The gradient is simply the normalized vecor pointing towards or away from that point depending on whether we are outside or inside of the shape. This does not hold for higher order quatities (i.e. the Hessian of the potential field).
Warning: not parraleized but should work from 3D This works for shapes with no volumes such as segments
x : numpy array
-
dist_hessian
(x)¶ Returns the hessian of the distance function.
x : numpy array
-
find_zone
(x_center)¶ 1 | 5 | 2 ___|_____|___ 8 | 9 | 6 ___|_____|___ 4 | 7 | 3
-
is_inside
(x)¶ Returns false if any of the component of the vector is smaller or bigger than the lower and top corner of the box respectively
Warning : This is only valid for AxisAligned Box
- xnumpy array with
arbitrary dimensions, 2d and 3d or meshgrid data shape = (2 or 3, n, n)
-
class
pyrieef.geometry.workspace.
Box
(origin=array([0., 0.]), dim=array([1., 1.]))¶ Bases:
pyrieef.geometry.workspace.Shape
An axis aligned box (hypercube) defined by center and exent
- originnumpy array
its center
- dimnumpy array
its extent
- TODO 1) define distance
class should work for 2D and 3D boxes
test this function
make callable using stack
-
closest_point
(x)¶ Returns the closest point from x on the contour.
x : numpy array
-
closest_segment
(x)¶
-
diag
()¶
-
dist_from_border
(x)¶ Returns the sign distance at x.
x : numpy array
-
dist_hessian
(x)¶ Returns the hessian of the distance function.
x : numpy array
-
is_inside
(x)¶ Returns false if any of the component of the vector is smaller or bigger than the lower and top corner of the box respectively
Warning : This is only valid for AxisAligned Box
- xnumpy array with
arbitrary dimensions, 2d and 3d or meshgrid data shape = (2 or 3, n, n)
-
lower_corner
()¶
-
sampled_points
()¶
-
segments
()¶
-
upper_corner
()¶
-
verticies
()¶ TODO test
-
class
pyrieef.geometry.workspace.
Circle
(origin=array([0., 0.]), radius=0.2)¶ Bases:
pyrieef.geometry.workspace.Shape
An Circle
- originnumpy array
center
- radiusFloat
radius
-
closest_point
(x)¶ Returns the closest point from x on the contour.
x : numpy array
-
dist_from_border
(x)¶ Returns the signed distance (SD) to a circle shape; negative inside and positive outside.
This function is paralleized, meanning that if called on an array (2 or 3, n, n) it will return a matrix of SDField.
x : numpy array
-
dist_gradient
(x)¶ Warning: not parraleized but should work from 3D
-
dist_hessian
(x)¶ Warning: not parraleized but should work from 3D
-
is_inside
(x)¶ Returns true if x is inside the shape
-
sampled_points
()¶ TODO make this generic (3D) and parallelizable… Tough.
-
class
pyrieef.geometry.workspace.
Complex
(origin=array([0., 0.]), shapes=None)¶ Bases:
pyrieef.geometry.workspace.Shape
-
dist_from_border
(x)¶ Returns the sign distance at x.
x : numpy array
-
is_inside
(x)¶ Returns true if x is inside the shape
-
-
class
pyrieef.geometry.workspace.
Ellipse
(a, b)¶ Bases:
pyrieef.geometry.workspace.Shape
Define a ellipse shape using a and b parameters. (a, b) are the size of the great nd small radii.
-
dist_from_border
(x)¶ Iterative method described, Signed distance http://www.am.ub.edu/~robert/Documents/ellipse.pdf
-
is_inside
(x)¶ Returns true if x is inside the shape
-
sampled_points
()¶
-
-
class
pyrieef.geometry.workspace.
EnvBox
(origin=array([0., 0.]), dim=array([1., 1.]))¶ Bases:
pyrieef.geometry.workspace.Box
Specializes a box to defined an environment
- originnumpy array
the center of the box
- dimnumpy array
size of the box
-
box_extent
()¶
-
extent
()¶
-
meshgrid
(nb_points=100)¶ - Mesh grid definition matches the one in the PixelMap class
Note that it is only defined for squared boxes. simply takes as input the number of points which corresponds to the number of cells for the PixelMap
-
meshgrid_points
(nb_points=100)¶ TODO check what reshape is really doing
-
sample_uniform
()¶ Sample uniformly point in extend
-
stacked_meshgrid
(nb_points=100)¶
-
class
pyrieef.geometry.workspace.
Polygon
(origin=array([0., 0.]), verticies=[array([1., 1.]), array([0., 1.]), array([0., 0.]), array([1., 0.])])¶ Bases:
pyrieef.geometry.workspace.Shape
- A Polygon class
origin : its center
verticies : stored and passed in a counter-clockwise order
TODO: TEST
-
closest_edge
(x)¶
-
closest_point
(x)¶ Returns the closest point from x on the contour.
x : numpy array
-
create_segments
()¶
-
dist_from_border
(x)¶ Returns the sign distance at x.
x : numpy array
-
dist_hessian
(x)¶ Returns the hessian of the distance function.
x : numpy array
-
is_inside
(x)¶ Returns false if x is outside of the polygon
- xnumpy array with
arbitrary dimensions, 2d and 3d or meshgrid data shape = (2 or 3, n, n)
Computes inside by checking that the point is on the “right side” of all edges of the polygon
-
perimeter
()¶
-
point_along_perimieter
(s)¶ The trajectory is indexed by s in [0, 1]
-
sampled_points
()¶
-
verticies
()¶
-
class
pyrieef.geometry.workspace.
Segment
(origin=array([0., 0.]), orientation=0.0, length=0.8)¶ Bases:
pyrieef.geometry.workspace.Shape
A segment defined with an origin, length and orientaiton TODO :
define distance
test distance
-
closest_point
(x)¶ Compute the closest point by projecting to the infite line and then checking if the point lines on the segment.
-
dist_from_border
(q)¶ Returns the sign distance at x.
x : numpy array
-
dist_hessian
(x)¶ Returns the hessian of the distance function.
x : numpy array
-
end_points
()¶
-
length
()¶
-
p1
()¶
-
p2
()¶
-
sampled_points
()¶
-
class
pyrieef.geometry.workspace.
Shape
¶ Bases:
object
Shape represents workspace objects in 2D or 3D.
The contour, distance and gradient and hessian of the distance function are represented as analytical or other type of functions. The implementations should return a set of points on the contour, to allow easy drawing.
- nb_pointsint
How do discretize the contour/surface
-
abstract
closest_point
(x)¶ Returns the closest point from x on the contour.
x : numpy array
-
abstract
dist_from_border
(x)¶ Returns the sign distance at x.
x : numpy array
-
dist_gradient
(x)¶ Returns the gradient of the distance function.
Note that for the first order, the signed distance function of any shape is fully expressed by the closet point to the border. The gradient is simply the normalized vecor pointing towards or away from that point depending on whether we are outside or inside of the shape. This does not hold for higher order quatities (i.e. the Hessian of the potential field).
Warning: not parraleized but should work from 3D This works for shapes with no volumes such as segments
x : numpy array
-
dist_hessian
(x)¶ Returns the hessian of the distance function.
x : numpy array
-
is_inside
(x)¶ Returns true if x is inside the shape
-
abstract
sampled_points
()¶
-
class
pyrieef.geometry.workspace.
SignedDistance2DMap
(shape)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
This class of wraps the shape class in a differentiable map
-
forward
(x)¶ Should return an array or single value
-
hessian
(x)¶ - Should return the hessian matrix
n x n : input x input (dimensions)
by default the method returns the finite difference hessian that relies on the jacobian function. This method would be a third order tensor in the case of multiple output, we exclude this case for now. WARNING the object returned by this function is a numpy matrix.
-
input_dimension
()¶
-
jacobian
(x)¶ - Should return a matrix or single value of
m x n : ouput x input (dimensions)
by default the method returns the finite difference jacobian. WARNING the object returned by this function is a numpy matrix.
-
output_dimension
()¶
-
-
class
pyrieef.geometry.workspace.
SignedDistanceWorkspaceMap
(workspace)¶ Bases:
pyrieef.geometry.differentiable_geometry.DifferentiableMap
This class of wraps the workspace class in a differentiable map
-
evaluate
(x)¶ Warning: this gradient is ill defined it has a kink when two objects are at the same distance
-
forward
(x)¶ Should return an array or single value
-
hessian
(x)¶ Warning: this hessian is ill defined it has a kink when two objects are at the same distance
-
input_dimension
()¶
-
jacobian
(x)¶ Warning: this gradient is ill defined it has a kink when two objects are at the same distance
-
output_dimension
()¶
-
-
class
pyrieef.geometry.workspace.
Workspace
(box=<pyrieef.geometry.workspace.EnvBox object>)¶ Bases:
object
Contains obstacles.
- boxEnvBox
a specialized box to defined an environment
- obstacleslist
a list of Shape objects (ex: Circle, Box, …)
-
add_circle
(origin=None, radius=None)¶
-
add_segment
(origin=None, length=None)¶
-
all_points
()¶
-
in_collision
(pt)¶
-
min_dist
(pt)¶
-
min_dist_gradient
(pt)¶ Warning: this gradient is ill defined it has a kink when two objects are at the same distance
-
pixel_map
(nb_points=100)¶
-
pyrieef.geometry.workspace.
box_from_limits
(x_min, x_max, y_min, y_max)¶
-
pyrieef.geometry.workspace.
hexagon
(scale=1.0, translate=[0.0, 0.0])¶
-
pyrieef.geometry.workspace.
line_side
(a, b, p)¶ Compute the side of a line AB that the point P is on
True if the point p is on the left side of the line when the observer travels along the line from a -> b.
- Parameters
a : numpy array 2d (origin of line segment) b : numpy array 2d (end of line segment) p : numpy array 2d (point that should be right or left)
TODO can this function be done for higher dimensions
- m = np.array([[b[0] - a[0], b[1] - a[1]],
[p[0] - a[0], p[1] - a[1]]])
return np.linalg.det(m) > 0
-
pyrieef.geometry.workspace.
occupancy_map
(nb_points, workspace)¶ Returns an occupancy map in the form of a square matrix using the signed distance field associated to a workspace object
-
pyrieef.geometry.workspace.
pixelmap_from_box
(nb_points, box)¶
-
pyrieef.geometry.workspace.
point_distance_gradient
(x, origin)¶ Returns the gradient of the distance function to a point
x : numpy array origin : numpy array
-
pyrieef.geometry.workspace.
point_distance_hessian
(x, origin)¶ Returns the hessian of the distance function to a point
- Note: that it balances two sumands
euclidean metric : identity
pullback metric : the outer product of gradient
x : numpy array origin : numpy array
-
pyrieef.geometry.workspace.
sample_box_workspaces
(nb_boxes, height=0.2, width=0.2)¶ Samples a workspace randomly composed of nb_boxes the height and width parameters specify the max fraction of workspace diagonal used for a box.
-
pyrieef.geometry.workspace.
sample_circle_workspaces
(nb_circles, radius_parameter=0.15)¶ Samples a workspace randomly composed of nb_circles the radius parameter specifies the max fraction of workspace diagonal used for a circle radius.
-
pyrieef.geometry.workspace.
sample_circles
(nb_circles)¶ Samples circles in [0, 1]^2 with radii in [0, 1]
-
pyrieef.geometry.workspace.
sample_collision_free
(workspace, margin=0.0)¶ Samples a collision free point
-
pyrieef.geometry.workspace.
sample_line
(p_1, p_2, nb_points)¶
-
pyrieef.geometry.workspace.
segment_from_end_points
(p1, p2)¶
-
pyrieef.geometry.workspace.
vector_norm
(x)¶