Skip to content

Instantly share code, notes, and snippets.

View rahulbhadani's full-sized avatar
🎯
Panda boy! 🍫

Rahul Bhadani rahulbhadani

🎯
Panda boy! 🍫
View GitHub Profile
def learn2(optimizee, unroll_train_steps, retain_graph_flag = False, reset_theta = False):
"""retain_graph_flag=False
By default, the dynamic graph is released after each loss_backward
# reset_theta = False
By default, parameters are not initialized randomly before each learning.
"""
if reset_theta == True:
theta_new = torch.empty(dim)
torch.nn.init.uniform_(theta_new, a = -1 , b = 1.0)
theta_init_new = torch.tensor(theta, dtype=torch.float32, requires_grad=True)
## TensorFlow
from tensorflow.python.ops import control_flow_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import state_ops
from tensorflow.python.framework import ops
from tensorflow.contrib import rnn
import tensorflow as tf
class NLayerPerceptron:
from NeuralNetwork import NLayerPerceptron
import sys
import warnings
import tensorflow as tf
#It will download and read in the data automatically
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
@rahulbhadani
rahulbhadani / rosbag_record.py
Created November 7, 2019 11:45 — forked from marco-tranzatto/rosbag_record.py
Rosbag record from python node
#!/usr/bin/env python
import rospy
import subprocess
import os
import signal
class RosbagRecord:
def __init__(self):
material road
{
technique
{
pass
{
ambient 0.1 0.1 0.1 1.0
diffuse 0.8 0.8 0.8 1.0
specular 0.01 0.01 0.01 1.0 2.0
@rahulbhadani
rahulbhadani / NB
Last active March 30, 2020 02:42
Negative Binomial
@tf.function
def tfgamma(z):
g = tf.exp(tf.math.lgamma(z))
return g
@tf.function
def NB(x, mu, phi):
numerator = tfgamma(x + phi)*tf.math.pow(mu,x)*tf.math.pow(phi, phi)
denominator = tfgamma(phi)*tfgamma(x+1) *tf.math.pow((mu + phi),(x+phi))
return (numerator/denominator)
@rahulbhadani
rahulbhadani / MATLAB_FOR_PYTHON.md
Created April 7, 2020 20:32
How to use MATLAB Functionality from within Python

How to use MATLAB Functionality from within Python

Install MATLAB Engine for Python

  • Source your python environment. For me, it is anaconda with the name of virtual environment base.
source activate base
  • Change your directory to where you installed MATLAB
@rahulbhadani
rahulbhadani / MATLAB_FOR_PYTHON.md
Last active April 7, 2020 20:37
How to use MATLAB Functionality from within Python

How to use MATLAB Functionality from within Python

Install MATLAB Engine for Python

  • Source your python environment. For me, it is anaconda with the name of virtual environment base.
source activate base
  • Change your directory to where you installed MATLAB
@rahulbhadani
rahulbhadani / reading_h5_data.py
Created June 16, 2020 17:44
Reading .h5 data to get count matrix
import scanpy
ad = sc.read(filename="Zeisel.h5")
X = ad.X # X is the count matrix
@rahulbhadani
rahulbhadani / bagpy_example.py
Last active June 18, 2020 22:43
Reading and Plotting Bagfiles
# How to install bagpy:
# pip install bagpy
# documentation: https://jmscslgroup.github.io/bagpy/
# Repo: https://github.com/jmscslgroup/bagpy
import bagpy
from bagpy import bagreader
b = bagreader('/home/ivory/Downloads/2020-06-18-17-30-23.bag')
print(b.topic_table)