Skip to content

Instantly share code, notes, and snippets.

View myazdani's full-sized avatar
🏠
ML

Mehrdad Yazdani myazdani

🏠
ML
View GitHub Profile
@myazdani
myazdani / pcaVizDigits
Created May 31, 2014 01:08
PCA visualizations of Digits using Different Features
This file has been truncated, but you can view the full file.
{
"metadata": {
"name": "PCA visualizations of RBMs"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@myazdani
myazdani / RecursiveReadFiles.py
Last active July 26, 2018 16:20
get paths of all files in parent directory
import os
src_path = 'files_path'
file_types = (".jpg", ".png", ".JPG", ".PNG", ".JPEG", ".jpeg",".tif", ".tiff", ".TIFF", '.TIF')
file_paths = []
for root, dirs, files in os.walk(src_path):
file_paths.extend([os.path.join(root, f) for f in files if f.endswith(file_types)])
@myazdani
myazdani / color_hist_benchmark.ipynb
Last active August 29, 2015 14:07
Benchmark for computing color histograms
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@myazdani
myazdani / condition_number_derivatives.ipynb
Last active August 29, 2015 14:08
Condition numbers for different order of derivative matrices
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@myazdani
myazdani / Mode.r
Created November 10, 2014 03:33
computes mode in R
Mode <- function(x) {
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
@myazdani
myazdani / gist:8870a40099ac864a308f
Created December 3, 2014 23:10
resize images given path
{
"metadata": {
"name": "resize_images"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@myazdani
myazdani / get.correct.hour
Last active August 29, 2015 14:16
convert date to POSIXct and correct hour based on time zone
get.correct.hour = function(i){
x = as.POSIXct(strptime(dt$postedTime[i], format = "%Y-%m-%dT%H:%M:%S"), tz = "GMT")
tz.str = cities.gps[which(cities.gps$city == dt$city[i]),"time.zone"]
return(hour(format(x, tz = tz.str)))
}
@myazdani
myazdani / rate_plot.R
Created March 30, 2015 15:35
Temporal plots in R by cut and table (aggregate over weeks, months, etc)
meta.data$updated <- as.POSIXlt(meta.data$updated)
meta.data.one.week = subset(meta.data, meta.data$updated > as.POSIXlt("2013-12-04 12:00:00"))
all.rate <- table(cut(meta.data$updated, breaks = "1 hour"))
#all.rate <- table(cut(meta.data$updated, breaks = "15 mins"))
week.rate = data.frame(table(cut(meta.data.one.week$updated, breaks = "1 hour")))
all.rate.df = data.frame(all.rate)
@myazdani
myazdani / row-normalization.R
Created March 31, 2015 03:32
apply function to multiple columns in data tale
normalized.probs = function(x) {return(x/sum(x))}
res.H = relevant.images[,normalized.probs(.SD), by = filename.path, .SDcols = paste0("H", c(1:180))]
@myazdani
myazdani / chunks.py
Created April 15, 2015 20:28
chunk a list to even sizes
def chunks(l, n):
""" Yield successive n-sized chunks from l.
"""
for i in xrange(0, len(l), n):
yield l[i:i+n]