Skip to content

Instantly share code, notes, and snippets.

View akashgit's full-sized avatar

Akash Srivastava akashgit

  • MIT, IBM, University of Edinburgh, previously Microsoft Research and Microsoft
  • Cambridge, US | Edinburgh | Reading | Sheffield, UK
View GitHub Profile
@akashgit
akashgit / plot_softmax.py
Last active March 14, 2017 12:12
Effect of input normalisation on the softmax function and its gradients.
import autograd.numpy as np
from autograd import grad,elementwise_grad
def softmax(z):
return (np.exp((z))) / np.sum(np.exp((z)))
nb_of_zs = 200
zs = np.linspace(-10, 10, num=nb_of_zs) # input
zs_1, zs_2 = np.meshgrid(zs, zs) # generate grid
y = np.zeros((nb_of_zs, nb_of_zs, 2)) # initialize output
def ring(batchsize, num_cluster=8, scale=1, std=.01,**kwargs):
pi_= tf.constant(np.pi)
rand_indices = tf.random_uniform([batchsize], minval=0, maxval=num_cluster, dtype=tf.int32)
base_angle = pi_ * 2 / num_cluster
angle = (base_angle * tf.cast(rand_indices,dtype=float32)) - (pi_ / 2)
mean_0 = tf.expand_dims(scale*tf.cos(angle),1)
mean_1 = tf.expand_dims(scale*tf.sin(angle),1)
mean = tf.concat([mean_0, mean_1], 1)
return ds.Normal(mean, (std**2)*tf.ones_like(mean))
def grid(batch_size, num_components, num_features,**kwargs):
shape=(batch_size,num_features)
shape_cat=(batch_size,num_components)
cat = ds.Categorical(logits=np.log(0.04*np.ones(shape_cat, dtype=float32)))
mus = np.array([np.array([i, j])*np.ones(shape, dtype=float32) for i, j in itertools.product(range(-4, 5, 2),
range(-4, 5, 2))],dtype=float32)
s = 0.05*np.ones(shape, dtype=float32)
sigmas = [s for i in range(num_components)]
components = list((ds.MultivariateNormalDiag(mu, sigma, **kwargs)
for (mu, sigma) in zip(mus, sigmas)))
def highdim_syn_data(batch_size, num_components, num_features,**kwargs):
shape=(num_features)
shape_cat=(batch_size,num_components)
cat = ds.Categorical(tf.zeros(num_components, dtype=float32))
mus = [-1*tf.ones(shape, dtype=float32),-.5*tf.ones(shape, dtype=float32),
0*tf.ones(shape, dtype=float32),.5*tf.ones(shape, dtype=float32),
-2*tf.ones(shape, dtype=float32),-2.5*tf.ones(shape, dtype=float32),
10*tf.ones(shape, dtype=float32),.25*tf.ones(shape, dtype=float32),
-13*tf.ones(shape, dtype=float32),-5.5*tf.ones(shape, dtype=float32)]
Download location:
https://drive.google.com/drive/folders/11Vz0fqHS2rXDb5pprgTjpD7S2BAJhi1P
Clone this:
git clone https://github.com/chentinghao/download_google_drive.git
Run:
python download_gdrive.py 1-LFFkFKNuyBO1sjkM4t_AArIXr3JAOyl ../1024
python download_gdrive.py 1E23HCNL-v9c54Wnzkm9yippBW8IaLUXp ../512
python download_gdrive.py 1O89DVCoWsMhrIF3G8-wMOJ0h7LukmMdP ../256
Follow this (Strictly) to install CUDA stuff: Reference: https://gist.github.com/Mahedi-61/2a2f1579d4271717d421065168ce6a73
Dont forget to (additionally), edit ~/.bashrc to set cuda path.
Then, only on Satori:
wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh
bash https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh -f -p /hdd_c/$(whoami)/anaconda3
source ~/.bashrc
conda config --prepend channels https://public.dhe.ibm.com/ibmdl/export/pub/software/server/ibm-ai/conda/
conda create --name neurips python=3.6
conda activate neurips
conda install powerai