Instantly share code, notes, and snippets.

👾
Happy!

# DuaneDuaneNielsen

👾
Happy!
• Sort options
Last active Jul 23, 2020
View orbiter.py
 from vpython import sphere, vector, rate, color, arrow, canvas, cross, triangle, vertex from math import sqrt G = 6.67e-11 # N kg^-2 m^2 au = 1.495978707e11 day = 60 * 60 * 24 year = day * 365.25 earth_mass = 5.972e24 # kg
Created Jan 22, 2020
View modern_gl_minimal.py
 import glfw from OpenGL.GL import * from OpenGL.GL.shaders import compileProgram, compileShader import numpy as np import pyrr def init_window(width, height, title="My OpenGL window"): # initializing glfw library if not glfw.init():
Created Jan 19, 2020
Expectation Max algo Pytorch
View em_algo_2D.py
 import torch from torch import tensor from torch.distributions.multivariate_normal import MultivariateNormal import matplotlib.pyplot as plt from matplotlib.patches import Ellipse import matplotlib.patches as mpatches from math import acos, degrees from matplotlib.pyplot import cm """
Created Jan 16, 2020
Constructing batched distributions from data in pytorch and sampling from them
View batched_normal_distributions.py
 import torch from torch.distributions.normal import Normal from torch.distributions.multivariate_normal import MultivariateNormal """ Example of computing c batched Normal and Multivariate distributions from data and sampling batches from them """
Created Jan 15, 2020
EM algorithm - 1D Uses logprob bayes update for numerical stability
View em_algo.py
 import torch from torch.distributions.normal import Normal import matplotlib.pyplot as plt """ EM algo demo, in pytorch """ n = 40 # must be even number
Created Jan 14, 2020
Hypothesis testing using Bayesian inferance.
View bayesian_update.py
 import torch from torch.distributions.normal import Normal import matplotlib.pyplot as plt """ Using Bayes to estimate the relative probability of 2 Hypotheses given the value of a single data point Both hypothesis given equal prior probability of being correct """
Created Jan 13, 2020
Example of plotting MV Norm distribution in Pytorch
View plot_multivariate_normal.py
 import torch from torch.distributions.normal import Normal from torch.distributions.multivariate_normal import MultivariateNormal import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D d = Normal(0.0, 1.0) x = torch.linspace(-4, 4.0, 50) y = torch.exp(d.log_prob(x)) plt.plot(x, y)
Created Jan 13, 2020
Multiprocessing in python
View mp_scratch.py
 import multiprocessing as mp import os import numpy as np import multiprocessing.spawn def info(title): print(title) print('module name:', __name__) print('parent process:', os.getppid()) print('process id:', os.getpid())
Created Jan 13, 2020
k-means 2D in pytorch
View k_means2D.py
 import torch import matplotlib.pyplot as plt """ K means 2D demo, in pytorch """ n = 30 # must be even number k = 3
Last active Dec 1, 2019
Setting up Jupyter notebook kernels for multiple CUDA versions.
View Short version
 jupyter kernelspec list Available kernels: python2 /home/duane/PycharmProjects/.venv/imm/share/jupyter/kernels/python2 cd /home/duane/PycharmProjects/.venv/imm/share/jupyter/kernels/python2 vi kernel.json {
You can’t perform that action at this time.