Skip to content

Instantly share code, notes, and snippets.

View bnsh's full-sized avatar

Binesh Bannerjee bnsh

View GitHub Profile
@bnsh
bnsh / decode.py
Last active November 30, 2018 04:15
This program will take a file with words that may be jumbled, and look them up in the "words" file.. and unjumble them...
#! /usr/bin/env python3
import re
from collections import defaultdict
def sort_word(word):
letters = "".join(sorted([w for w in word]))
return letters
def read_dictionary():
@bnsh
bnsh / cloak_class.R
Last active July 15, 2018 17:46
Why does lintr tell me "no visible binding for global variable 'Cloaked'"?
#! /usr/bin/env Rscript
library(R6)
Cloaked <- R6::R6Class("Cloaked",
public = list(
msg = function() {
return(paste(
"this code _works_, but lintr (https://github.com/jimhester/lintr)",
"complains that cloak_class.R:19:8: warning: no visible binding for",
@bnsh
bnsh / gradient_demo.py
Last active March 10, 2018 10:24
Why is gradInput different for my module than for nn.ReLU?
#! /usr/bin/python
"""Why is len(grad_input) == 3 if I use Identity, but
len(grad_input) == 1 if I use ReLU?
I don't know if this is the source of all my woes in my real network.
Run this like so:
python demo.py identity
module=Identity() len(grad_input)=3 len(grad_output)=1
@bnsh
bnsh / BinaryStochastic.py
Created February 12, 2018 16:27
Modification of BinaryStochastic.py for v0.2.0 to v0.3.0. How can I specify to the function that I'm in training mode?
#! /usr/bin/python
"""BinaryStochastic interprets it's input as a probability
between [0,1] and
* with probability p, outputs a 1, and
* with probability (1-p) it outputs a 0.
Practically, this is accomplished simply by taking a random uniform
the size of the input and seeing if the random uniform is less than
the input. If true, we output a 1, if false we output a 0.
@bnsh
bnsh / demo.py
Last active September 23, 2017 15:09
This is a simple util to do timer stuff
#! /usr/bin/python
from timer_util import Timer
def fibonacci(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
@bnsh
bnsh / preprocess.py
Last active September 19, 2017 08:11
This program will preprocess the cats and dogs images into a set of perturbed images (and validation images)
#! /usr/bin/python
"""This will preprocess the cats data.
First, it splits the train data into training and validation.
validation is left unmolested. (Other than scaling and cropping.)
train tho, is further cropped and rotated randomly."""
import os
import re
import math
@bnsh
bnsh / authinfo.json
Last active September 3, 2017 23:08
This is my demo of the Goodreads API. It fails for the call to api/auth_user (and review_list), but seems to succeed for shelf/list.. The authinfo.json does _not_ contain real authentication information, it has to be replaced with something real.
{
"client_key":"knunopkiantijnaGlok1",
"client_secret": "iddyadvufDijSeujowfEbphihythelkekiakphyeg",
"access_token": "yufBeokbytdiVoggUrlEk8",
"access_token_secret": "UtgazatsectyamHadNumpashawsOltirejcickmins"
}
@bnsh
bnsh / BransonMarvin.lua
Created August 28, 2017 01:02
Fixing Branson Marvin's code from gitter.
require 'nn'
require 'optim'
netG = nn.Sequential()
ngf = 32
netG:add(nn.SpatialConvolution(1, ngf, 4,4, 2,2, 1,1))
netG:add(nn.ReLU(true))
netG:add(nn.SpatialConvolution(ngf, ngf * 2, 4,4, 2,2, 1,1))
netG:add(nn.SpatialBatchNormalization(ngf * 2))
@bnsh
bnsh / TempDelhiCriterion.lua
Last active July 6, 2017 15:42
This implements the TempDelhiCriterion (... Really, it's just from what https://github.com/tempdelhi123 asked for)
#! /usr/local/torch/install/bin/th
local TempDelhiCriterion, parent = torch.class('nn.TempDelhiCriterion', 'nn.MSECriterion')
function TempDelhiCriterion:__init()
parent.__init(self)
self.inputcpy = torch.Tensor()
end
function TempDelhiCriterion:forward(input, target)
@bnsh
bnsh / sigmoid_discrepancy.lua
Created July 4, 2017 09:53
This gist demonstrates that Sigmoid computed on cuda differs from cudnn.Sigmoid.
#! /usr/local/torch/install/bin/th
require "nn"
require "cutorch"
require "cunn"
require "cudnn"
function main()
torch.manualSeed(12345)