Skip to content

Instantly share code, notes, and snippets.

View stormxuwz's full-sized avatar
🤣
Sleepy?

Wenzhao Xu stormxuwz

🤣
Sleepy?
View GitHub Profile
@stormxuwz
stormxuwz / three_dots.R
Created March 12, 2015 20:00
The three-dots construct in R
test_function_1 <- function(a=1){
cat("a is here",a)
}
test_function_2 <- function(b,...){
test_function_1(...)
}
test <- function(a,b){
test_function_2(b,a)
@stormxuwz
stormxuwz / VAR.py
Created February 25, 2015 06:30
Activity recognition by VAR model (HAR dataset)
import statsmodels.tsa as st
import numpy as np
import numpy.linalg as nl
import statsmodels.tsa as tsa
def solver_leastSquare(A,y):
return nl.lstsq(A,y);
def read_data(filename):
x=[]
@stormxuwz
stormxuwz / dft.py
Created February 2, 2015 05:21
This is a Discrete Fourier Transformation calculation using matrix mutiplication
def omega(N,k,n):
return np.exp(-2*np.pi/N*k*n*1j)
def hanWindow(N):
diag=np.array([np.sin(np.pi*i/(N-1))**2 for i in range(N)])
H=np.diag(diag)
return H
def createF(N):
F=np.zeros((N,N),dtype=complex)
@stormxuwz
stormxuwz / mfcc.py
Created February 2, 2015 05:17
MFCC for signal
from __future__ import division
import numpy as np;
import matplotlib.pyplot as plt
import warnings
# Ref: http://practicalcryptography.com/miscellaneous/machine-learning/guide-mel-frequency-cepstral-coefficients-mfccs/
# Ref2:http://python-speech-features.readthedocs.org/en/latest/. However, I checked the library code and found there might be a mistake when using rfft
def preemphasis(signal,coeff=0.95):
return numpy.append(signal[0],signal[1:]-coeff*signal[:-1])
@stormxuwz
stormxuwz / funcProb1.R
Created February 2, 2015 04:53
Some regression/classification in R
#### LDA,QDA, RDA, naive baye functions ####
lda.model=function(traindata){
lda.result=lda(Y~.,data=traindata)
return(lda.result)
}
lda.pred=function(model,dataSets.X){
predresult=lapply(dataSets.X,function(X) predict(model,X)$class)
errorInfo(predresult,"lda")
@stormxuwz
stormxuwz / GoogleAPI.py
Last active August 29, 2015 14:14
How to use Google Navigation and street view API and extract some features from a image
import urllib2;
import numpy as np;
import json;
from pyproj import Geod;
def decode_line(encoded):
"""copied from https://github.com/jconst/Byway-Server/blob/master/polyline.py
"""
encoded_len = len(encoded)
@stormxuwz
stormxuwz / Josephus_Problem
Created January 9, 2015 06:37
Josephus problem
# include <iostream>
using namespace std;
struct person{
person * previousPerson;
person * nextPerson;
int sword;
int num;
};
@stormxuwz
stormxuwz / boxplot_from_summary.R
Created October 24, 2014 16:41
box plot from summary
# http://stackoverflow.com/questions/10628847/geom-boxplot-with-precomputed-values
library(ggplot2)
DF <- data.frame(x=c("A","B"), min=c(1,2), low=c(2,3), mid=c(3,4), top=c(4,5), max=c(5,6))
ggplot(DF, aes(x=x, ymin = min, lower = low, middle = mid, upper = top, ymax = max)) +
geom_boxplot(stat = "identity")
@stormxuwz
stormxuwz / openMP_whileLoop.c
Last active January 12, 2024 10:21
parallel while loop
// This code is from https://www.cac.cornell.edu/VW/OpenMP/whileloop.aspx
#include <omp.h>
#include <stdio.h>
int main(int argc, char **argv)
{
/* OpenMP does not provide a parallel while loop,
so we're going to have to make one ourselves... */
int sj, sstop, tn, tj, tstop;
int foo(int j);
@stormxuwz
stormxuwz / spectrogram.py
Created September 17, 2014 19:40
Record sound and do spectrogram to the sound signal
import numpy as np
from scipy.io.wavfile import read,write
import matplotlib.pyplot as plt
from matplotlib.pylab import *
def omega(N,k,n):
return np.exp(-2*np.pi/N*k*n*1j)
def hanWindow(N):
diag=np.array([np.sin(np.pi*i/(N-1))**2 for i in range(N)])