Skip to content

Instantly share code, notes, and snippets.

@keskarnitish
keskarnitish / cg.py
Created March 14, 2016 16:48 — forked from neosatrapahereje/cg.py
Conjugate gradient optimization for Lasagne
from collections import OrderedDict
import numpy as np
import theano
import theano.tensor as T
from theano.ifelse import ifelse
def cg(loss, params, x0=None, max_iters=100, precondition=None, tol=1e-3,
conv_crit='cg'):
"""(Preconditioned) Conjugate Gradient (CG) updates
try
A=[-1 -2; -4 -3; 1 0 ; 0 1];
b = [ -40; -120; 0; 0];
plotregion(A,b);
hold on;
x=1:30;
y = (100 - 4*x)/5;
plot(x,y,'k--','LineWidth',2)
y = (136 - 4*x)/5;
plot(x,y,'k','LineWidth',2)
@keskarnitish
keskarnitish / LineWordCounter
Last active August 29, 2015 13:56
A simple script to count number of words and lines in a document using only map and reduce functions (No Loops). Usage: cat foobar.txt | python LineWordCounter.py
# A simple script to count number of words and lines in a document using only map and reduce functions (No Loops)
# Usage: cat foobar.txt | python LineWordCounter.py
import sys
DataToRead = sys.stdin.read()
print "Document has " + str(sum(map(lambda x: x=='\n',DataToRead))) + " lines"
print "Document has " + str(len(map(len, DataToRead.split()))) + " words"
@keskarnitish
keskarnitish / WhatsAppCleaner.py
Last active January 14, 2017 14:13
Clean WhatsApp Generated Text File for Image Cloud Scripts
#Extremely simple script to cleanup the conversation data that WhatsApp generates
#You can email yourself the conversation from your WhatsApp mobile application, run this script and use any popular word cloud generator like http://www.wordle.net/create.
#TO DO: Include code to create wordcloud as well. Possibly https://github.com/atizo/PyTagCloud or https://github.com/amueller/word_cloud
#Usage: python WhatsAppCleaner.py Foo.txt
from sys import argv
script, filename = argv
f = open(filename,'r')
for line in f:
try: