Skip to content

Instantly share code, notes, and snippets.

Avatar

Nishant Nikhil nishnik

View GitHub Profile
View arxiv_filename_change.user.js
// ==UserScript==
// @name Change filename for arxiv downloads
// @namespace https://arxiv.org/
// @version 1.0
// @description Changes filename for the PDF link, so that once you open it in pdf js it downloads as "paper_name.pdf" instead of "year_month.identifier.pdf"
// @author Nishant Nikhil
// @match https://*.arxiv.org/abs/*
// @grant none
// ==/UserScript==
@nishnik
nishnik / find_max_col
Created Jul 18, 2018
Finds the minimum and maximum value in 3rd column of a text file
View find_max_col
cat crowds_zara01_train.txt | awk -F ' ' '{print $3}' | sort -n | sed -n '1p;$p'
View fill_it_up.js
var val = "3"
var radio_buttons = document.querySelectorAll('input[value="' + val +'"]');
var i = 0;
for (i=0; i<radio_buttons.length ; i++){
radio_buttons[i].checked = true;
}
var radio_buttons = document.querySelectorAll('input[value="5' + val +'"]');
var i = 0;
for (i=0; i<radio_buttons.length ; i++){
radio_buttons[i].checked = true;
@nishnik
nishnik / lstm.py
Created Feb 16, 2018
Load imdb preprocessed dataset and simple lstm over it - PyTorch, Keras
View lstm.py
from keras.preprocessing import sequence
from keras.models import Sequential
from keras.datasets import imdb
import torch
import torch.autograd as autograd
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
@nishnik
nishnik / Pytorch_get2max.py
Created Nov 14, 2017
Gets 2 maximum element form max pooling
View Pytorch_get2max.py
import numpy as np
y = np.array([[1.0, 7.0, 1.0],[3.0, 4.0, 2], [1, 7, 1]])
x = torch.from_numpy(y)
x = Variable(x)
x = x.resize(1, 3, 3)
stride = 2
new_var = Variable(torch.zeros([x.shape[0], x.shape[1]//stride, x.shape[2]//stride]))
new_var2 = Variable(torch.zeros([x.shape[0], x.shape[1]//stride, x.shape[2]//stride]))
for dim1 in range(x.shape[0]):
tmp = Variable(torch.zeros([x.shape[1]//stride, x.shape[2]//stride, 1]))
@nishnik
nishnik / Pytorch_maxpool2d.py
Created Nov 14, 2017
Basic implementation of maxpool2d in pytorch, based on it you can create kmaxpool
View Pytorch_maxpool2d.py
stride = 3
new_var = Variable(torch.zeros([x.shape[0], x.shape[1]//stride, x.shape[2]//stride]))
for dim1 in range(x.shape[0]):
tmp = Variable(torch.zeros([x.shape[1]//stride, x.shape[2]//stride, 1]))
for i in range(0, x.shape[1], stride):
for j in range(0, x.shape[2], stride):
tmp_max = x[dim1][i][j]
for k in range(stride):
for m in range(stride):
tmp_max = torch.max(tmp_max, x[dim1][i+k][j+m])
@nishnik
nishnik / scrape_metaKGP_scores.py
Created Apr 13, 2017
Scrapes scores from MetaKGP's "Contribution Scores" page
View scrape_metaKGP_scores.py
from bs4 import BeautifulSoup
import requests
data_list = []
link = "https://wiki.metakgp.org/w/Special:ContributionScores"
response = requests.get(link)
html = response.content
source = BeautifulSoup(html, "lxml")
trs = source.findAll("tr")
run = False
@nishnik
nishnik / vae.py
Created Feb 1, 2017
Variational Auto-Encoder introduction
View vae.py
# relu activation function
def relu(x):
return T.switch(x<0, 0, x)
class VAE:
"""This class implements the Variational Auto Encoder"""
def __init__(self, continuous, hu_encoder, hu_decoder, n_latent, x_train, b1=0.95, b2=0.999, batch_size=100, learning_rate=0.001, lam=0):
# let us keep the discussion to not continuous
View apriori_genetic_optimization.py
def load_dataset():
"Load the sample dataset. must be numbered from 1"
return [[1, 3, 4], [2, 3, 5], [1, 2, 3, 5], [2, 5]]
def createC1(dataset):
"Create a list of candidate item sets of size one."
c1 = []
for transaction in dataset:
for item in transaction:
View char-rnn.py
"""
Andrej Karpathy's code compatible in python3
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))