This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_steps(n): | |
"""Determine how many ways there are to walk n steps, if you can jump over 1, 2 or 3 steps at the time | |
f(-1) = 0 | |
f(0) = 1 # just stand? | |
f(1) = 1 | |
f(2) = 2 | |
f(3) = 4 | |
f(4) = f(n-1)+f(n-2)+f(n-3) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
def check_path(grid, i=0, j=0, failed_points=None, current_path=None): | |
""" Find a route between upper-left and lower right corner of the grid, | |
if you are only allowed to walk right and down. | |
Input: | |
1 1 1 | |
0 0 1 | |
0 0 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
%matplotlib inline | |
def plot2d(fig_lst, labels=None, figsize=(10, 10), savepath=None): | |
"""Plots a set of 2d shapes represented as 2d point arrays | |
Parameters | |
---------- | |
fig_lst: list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import h5py | |
import os | |
def save_h5(savepath, arr_dict): | |
if os.path.exists(savepath): | |
os.remove(savepath) | |
h5ds = h5py.File(savepath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import scipy.stats as stats | |
def plot_gauss_pdf(mu, sigma, gt): | |
''' plots Guassian density together with some ground truth value gt | |
''' | |
x = np.linspace(mu - 5*sigma, mu + 5*sigma, 100) | |
plt.plot(x, stats.norm.pdf(x, mu, sigma)) | |
plt.axvline(mu, c='blue', label='prediction mean') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from keras.layers import Input, Dense, Flatten, Reshape, Dropout | |
from keras.models import Model, Sequential | |
from keras.optimizers import Adam | |
from keras.objectives import binary_crossentropy | |
from keras.layers.merge import concatenate | |
from keras.losses import mean_squared_error | |
def variational_autoencoder(n_input_features, latent_space_size=64, hlayer_size=256, | |
lr=1.0e-3, kl_weight=0.1): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import open3d as o3d | |
import trimesh | |
import numpy as np | |
def ball_pivoting_reconstruction(xyz, radii=None): | |
"""Given a 3D point cloud, get unstructured mesh using ball pivoting algorithm | |
Based on this stack overflow code snippet: | |
https://stackoverflow.com/questions/56965268/how-do-i-convert-a-3d-point-cloud-ply-into-a-mesh-with-faces-and-vertices |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Simple point cloud visualization with pyntcloud library | |
""" | |
import pyntcloud as pynt | |
import pandas as pd | |
import numpy as np | |
def show_cloud(xyz, rgb=None, initial_point_size=0.01): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# details: | |
# https://stackoverflow.com/questions/11367736/matplotlib-consistent-font-using-latex/27697390 | |
from matplotlib import rc | |
import matplotlib | |
matplotlib.rcParams['mathtext.fontset'] = 'stix' | |
matplotlib.rcParams['font.family'] = 'STIXGeneral' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.neighbors import NearestNeighbors | |
def chamfer_distance(x, y, metric='l2', direction='bi'): | |
"""Chamfer distance between two point clouds | |
Parameters | |
---------- | |
x: numpy array [n_points_x, n_dims] |