This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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=[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import division | |
| import numpy as np | |
| class OnlineClf(object): | |
| def __init__(self,iterNum,R): | |
| self.w=None | |
| self.iterNum=iterNum | |
| self.misNum=[[0,0]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| def slidingWindow(x,max_error): | |
| n=len(x) | |
| leftNode=0 | |
| segmentList=[] | |
| print n | |
| while leftNode<n-1: | |
| print leftNode |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| randomForest_clf <- function(matTrain,trainLabel,matTest,...){ | |
| library(randomForest) | |
| rf_model<-randomForest(matTrain,trainLabel,ntree=500) | |
| rf_predict<-predict(rf_model,matTest) | |
| return(rf_predict) | |
| } | |
| xgboost_clf_1000 <- function(matTrain,trainLabel,matTest,...){ | |
| library(xgboost) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## Classification starts now | |
| library(MASS) | |
| library(e1071) | |
| library(rda) | |
| #################################### | |
| qda.model=function(traindata){ | |
| qda.result=qda(Y~.,data=traindata) | |
| return(qda.result) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This is a pure python K-means implementation | |
| import numpy as np | |
| def calDistance(x,y): | |
| # return the distance of x and y | |
| return np.sum((x-y)**2) | |
| def assignClusters(centers,data): | |
| distance = np.zeros((len(data),len(centers))) |