Skip to content

Instantly share code, notes, and snippets.

@superjax
superjax / tolerant_loss.py
Created February 26, 2019 14:34
Plots of several tolerant Loss functions used by ceres
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0.001, 5, 0.001)
def Huber(a, d):
x = np.zeros_like(a)
x[a<d] = 0.5 * a[a<d]**2
x[a>=d] = d * (np.abs(a[a>=d]) - 0.5 * d)
@superjax
superjax / personaltypes.py
Last active June 21, 2021 01:49
My QtCreator Debug Helpers (Eigen::Map, quat::Quat, xform::Xform)
## Add the path to this file to Tools -> Options -> Debugger -> Locals & Expressions -> Extra Debugging Helpers
## Based on the `misctypes.py` which ships with QtCreator, and extended to add support for Maps and my geometry library
from dumper import *
# Similar to Matrix, but you have to dive into the pointer
def qdump__Eigen__Map(d, value):
@superjax
superjax / inverted_pendulum.py
Last active March 28, 2018 02:34
MPC of an Inverted Pendulum on a Cart
import matplotlib.pyplot as plt
import numpy as np
import math
import time
import cvxpy
l = 1.5 # length of bar
M = 1.0 # [kg]
m = 0.1 # [kg]
g = 9.8 # [m/s^2]
import numpy as np
def skew(v):
return np.array([[0, -v[2,0], v[1,0]],
[v[2,0], 0, -v[0,0]],
[-v[1,0], v[0,0], 0]])
for i in range(1000):
w0 = np.random.rand(3, 1)
v = np.ones((3, 1))
@superjax
superjax / pomdp.py
Created December 14, 2017 04:29
POMDP Solution implementation for 2-state problem described in Probabilistic Robotics by Thrun et al.
from sets import Set
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
p_z_gx = np.array([[0.7, 0.3],
[0.3, 0.7]])
p_x_g_u_z = np.zeros((2,3,2))
p_x_g_u_z[:,2,:] = np.array([[0.2, 0.8],
[0.8, 0.2]])
@superjax
superjax / myGRU.py
Created November 10, 2017 03:47
my implementation of a Gated Recurrent Unit in Tensorflow
from tensorflow.python.ops.rnn_cell import RNNCell
from tensorflow.python.ops import math_ops
import tensorflow as tf
class myGRU(RNNCell):
def __init__(self, num_units, forget_bias=1.0,
state_is_tuple=True, activation=None, reuse=None):
super(RNNCell, self).__init__(_reuse=reuse)
self._num_units = num_units
self._forget_bias = forget_bias
@superjax
superjax / EKF_SLAM.py
Created November 6, 2017 04:01
EKF_SLAM implementation from Probabilistic Robotics by Sebastian Thrun et al. (look for the plot helper gist for covariance plotting)
import numpy as np
import scipy.linalg
import scipy.stats
import matplotlib.pyplot as plt
import scipy.io
import scipy.sparse
from plot_helper import plot_cov_ellipse
from tqdm import tqdm
def R(theta):
@superjax
superjax / plot_helper.py
Created November 6, 2017 03:59
Python plot helpers
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
import numpy as np
def plot_point_cov(points, nstd=2, ax=None, **kwargs):
"""
Plots an `nstd` sigma ellipse based on the mean and covariance of a point
"cloud" (points, an Nx2 array).
Parameters
@superjax
superjax / occupancy_grid_mapping_example.py
Last active November 18, 2024 01:29
An occupancy grid mapping example
# This is an implementation of Occupancy Grid Mapping as Presented
# in Chapter 9 of "Probabilistic Robotics" By Sebastian Thrun et al.
# In particular, this is an implementation of Table 9.1 and 9.2
import scipy.io
import scipy.stats
import numpy as np
import matplotlib.pyplot as plt
from tqdm import tqdm
@superjax
superjax / lqr.py
Created April 13, 2017 16:41
LQR Controller for Python
def lqr(A,B,Q,R):
#first, try to solve the ricatti equation
X = np.matrix(solve_continuous_are(A, B, Q, R))
#compute the LQR gain
K = np.matrix(inv(R)*(B.T*X))
eigVals, eigVecs = eig(A-B*K)
return K, X, eigVals