Skip to content

Instantly share code, notes, and snippets.

@erogol
erogol / zscore_normalize_data.m
Created September 3, 2013 15:06
Z-score Normalization of data
function[X_norm, mu, sigma] = zscore_normalize_data(X, mu, sigma)
X_norm=bsxfun(@minus,X,mu);
X_norm=bsxfun(@rdivide,X_norm,sigma);
@erogol
erogol / crawle_imdb.py
Last active December 22, 2015 10:09
scrap imdb to get non-dublicate movies of given categories
import urllib2
from BeautifulSoup import BeautifulSoup
import pdb
import os
import htmlentitydefs
from BeautifulSoup import BeautifulStoneSoup
import HTMLParser
import cgi
@erogol
erogol / GMM.m
Created September 9, 2013 13:14
Gaussian_mixture_model
function mix = gmm(dim, ncentres, covar_type, ppca_dim)
%GMM Creates a Gaussian mixture model with specified architecture.
%
% Description
% MIX = GMM(DIM, NCENTRES, COVARTYPE) takes the dimension of the space
% DIM, the number of centres in the mixture model and the type of the
% mixture model, and returns a data structure MIX. The mixture model
% type defines the covariance structure of each component Gaussian:
% 'spherical' = single variance parameter for each component: stored as a vector
% 'diag' = diagonal matrix for each component: stored as rows of a matrix
@erogol
erogol / rdir.m
Created September 20, 2013 18:19
discover file paths recursively to the deeps of your computer given the root folder
function [varargout] = rdir(rootdir,varargin)
% Lists the files in a directory and its sub directories.
%
% function [D] = rdir(ROOT,TEST)
%
% Recursive directory listing.
%
% ROOT is the directory starting point and includes the
% wildcard specification.
% The function returns a structure D similar to the one
@erogol
erogol / scrap_bing.py
Last active December 23, 2015 15:59
Crawle and scrap Bing Image seach images
#!/usr/bin/env python
'''
Query on GoogleImageSearch and install resulted images by scraping.
To use this script install mechanize and BeautifulSoup packages as
easy_install mechanize
easy_install Beautiful
@erogol
erogol / neg_samples.m
Created September 24, 2013 13:32
sample negative instances from real folder structure given the root folder the the interest paths
function [] = sample_neg_examples(ROOT_PATH, num_sample, OUTPUT_PATH)
SEARCH_PATH = fullfile(ROOT_PATH,'**','*');
SAVE_PATH = 'neg_examples'
paths = rdir(SEARCH_PATH);
if exist('OUTPUT_PATH','var')
SAVE_PATH = OUTPUT_PATH;
end
@erogol
erogol / 0_reuse_code.js
Created September 25, 2013 19:31
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
if ~exist('vlfeat', 'dir')
from = 'http://www.vlfeat.org/download/vlfeat-0.9.13-bin.tar.gz' ;
fprintf('Downloading vlfeat from %s\n', from) ;
untar(from, 'data') ;
movefile('data/vlfeat-0.9.13', 'vlfeat') ;
end
function [ res ] = ie505_hw1( n,a,b )
%İE505_HW1 Summary of this function goes here
% Detailed explanation goes here
[~,bins]= hist([a,b],1000);
r =unique( round( n*bins));
res = arrayfun(@(x)nchoosek(n,x)*double(1/(2^n)),r);
'''
split a file into two randomly, line by line.
Usage: split.py <input file> <output file 1> <output file 2> [<probability of writing to the first file>] [<random seed>]'
'''
import csv
import sys
import random
input_file = sys.argv[1]