MCPcopy Create free account
hub / github.com/Simple-Robotics/aligator / function_finite_difference

Function function_finite_difference

tests/python/utils.py:113–143  ·  view source on GitHub ↗

Use finite differences to compute Jacobians of a `aligator.StageFunction`.

(
    fun: aligator.StageFunction,
    space: manifolds.ManifoldAbstract,
    x0,
    u0,
    eps=1e-8,
)

Source from the content-addressed store, hash-verified

111
112
113def function_finite_difference(
114 fun: aligator.StageFunction,
115 space: manifolds.ManifoldAbstract,
116 x0,
117 u0,
118 eps=1e-8,
119):
120 """Use finite differences to compute Jacobians
121 of a `aligator.StageFunction`.
122 """
123 data = fun.createData()
124 Jx_nd = np.zeros((fun.nr, fun.ndx1))
125 ei = np.zeros(fun.ndx1)
126 fun.evaluate(x0, u0, data)
127 r0 = data.value.copy()
128 for i in range(fun.ndx1):
129 ei[i] = eps
130 xplus = space.integrate(x0, ei)
131 fun.evaluate(xplus, u0, data)
132 Jx_nd[:, i] = (data.value - r0) / eps
133 ei[i] = 0.0
134
135 ei = np.zeros(fun.nu)
136 Ju_nd = np.zeros((fun.nr, fun.nu))
137 for i in range(fun.nu):
138 ei[i] = eps
139 fun.evaluate(x0, u0 + ei, data)
140 Ju_nd[:, i] = (data.value - r0) / eps
141 ei[i] = 0.0
142
143 return Jx_nd, Ju_nd
144
145
146def set_baumgarte_params(cm: "pin.RigidConstraintModel", Kp: float, Kd: float = None):

Callers

nothing calls this directly

Calls 4

copyMethod · 0.80
integrateMethod · 0.80
createDataMethod · 0.45
evaluateMethod · 0.45

Tested by

no test coverage detected