Skip to content

Instantly share code, notes, and snippets.

View cohnt's full-sized avatar

Thomas Cohn cohnt

View GitHub Profile
@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],
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)
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

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].

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) {
@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>