Skip to content

Instantly share code, notes, and snippets.

View cohnt's full-sized avatar

Thomas Cohn cohnt

View GitHub Profile
@cohnt
cohnt / test.html
Last active January 30, 2018 04:58
HTML/Javascript Swarm Animation
<!DOCTYPE html>
<html>
<head>
<style>
canvas {
border: 1px dotted black;
}
</style>
</head>
<body>
function dist(x, y) {
return Math.sqrt(Math.pow(y[0]-x[0], 2)+Math.pow(y[1]-x[1], 2));
}
function ln(x) {
return Math.log(x);
}
function abs(x) {
return Math.abs(x);
}
function disth(p, q) {

Correct include_dirs in setup.py to be whichever folder contains all of the ROS libraries. For example, [your_include_dir]/ros/ros.h should be the main ros library for C++.

Run python2 setup.py build_ext --inplace to build the program

Run python2 to enter a python environment, and type import node to start it off.

You will probably see an error message that looks something like ImportError: /file/path/to/node.so: undefined symbol: [some mangled symbol name].

import numpy as np
# Single point cloud case
point_cloud = np.random.rand(6,3) # 6 3D points
flattened = point_cloud.reshape(point_cloud.shape[0],-1) # One point in R^18
unflattened = flattened.reshape(-1,3) # 6 3D points
# Check that they're identical
print point_cloud
import numpy as np
import matplotlib.pyplot as plt
mean = np.array([2, 2])
cov = 0.5 * np.array([[1, 0.9], [0.9, 1]])
x, y = np.random.multivariate_normal(mean, cov, 75).T
from sklearn.decomposition import PCA
pca = PCA(n_components=2)
@cohnt
cohnt / k-clustering_comparison.py
Last active June 23, 2022 14:51
Comparison of k-means, k-medians, and k-medoids clustering on a toy dataset with 2 clusters and an outlier.
import numpy as np
from pyclustering.cluster.kmeans import kmeans, kmeans_visualizer
from pyclustering.cluster.kmedians import kmedians
from pyclustering.cluster.kmedoids import kmedoids
from pyclustering.cluster import cluster_visualizer
sample = np.array([
[0, 0],
# Experimenting with alphashapes to generate 2D worlds with randomly sized and shaped obstacles.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
from descartes import PolygonPatch
import alphashape
n_points = 200
alpha = 25.
@cohnt
cohnt / user.bazelrc
Created April 21, 2023 17:47
user.bazelrc File for My Drake Installation
# Use proprietary solvers
build --config gurobi
build --config mosek
build --config snopt
@cohnt
cohnt / break.py
Last active April 26, 2023 23:57
Terrible Linear System
# Built off of commit hash 8ddd6672b1
import numpy as np
from pydrake.all import ContinuousAlgebraicRiccatiEquation
A = np.fromstring("0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 1.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.000000000000000000e+00 0.0000000000