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 / 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 / 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 / rf_python.py
Created July 18, 2017 00:00
random forest in python
# gist only to keep record from https://www.jiqizhixin.com/articles/bb59b879-e030-400d-abbc-d9c0708266ff
# Random Forest Algorithm on Sonar Dataset
from random import seed
from random import randrange
from csv import reader
from math import sqrt
# Load a CSV file
def load_csv(filename):
@stormxuwz
stormxuwz / coverIntervals.py
Last active May 22, 2017 22:20
coverIntervals.py
# list_forecasts = [[1,3],[2,5]]
## cover(1pm, 7pm, [[1,3], [5,7]])
## return [[3,5]]
def cover(startTime, endTime, list_forecasts):
n = len(list_forecasts)
@stormxuwz
stormxuwz / plot_gly_on_map.R
Created April 28, 2017 23:49
customized glyph-maps
plot_gly_on_map <- function(newDF, global = FALSE, trend = FALSE, outputFile = "test.png"){
# newDF$value <- newDF$summerSum_UHY - newDF$springSum_UHY
longRange <- range(newDF$Long)
latRange <- range(newDF$Lat)
bbox <- make_bbox(longRange,latRange,f = 0.3)
# myMap <- get_map(location=bbox, source="stamn",crop=TRUE,color="bw",maptype="terrain")
myMap <- get_map(location = bbox, maptype="toner-lite", source="stamen",zoom=7,color = "bw",crop=TRUE)
# ggmap(myMap)
SU_locations <- unique(newDF[,c("Station","Lat","Long")])
-- LaunchBar Action Script
-- apple script to append launchbar input to the last line of omnioutliner
on handle_string(_string)
tell application "OmniOutliner 4.6.1"
set theDocument to the front document
set newRow to make new row at last row of front document
set topic of newRow to _string
outdent newRow
# 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)))
@stormxuwz
stormxuwz / classfication_method.R
Created September 22, 2016 03:12
Music information retrieve for music classification
## Classification starts now
library(MASS)
library(e1071)
library(rda)
####################################
qda.model=function(traindata){
qda.result=qda(Y~.,data=traindata)
return(qda.result)
}
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)
from __future__ import division
import numpy as np
import chainer # only for import the data at this script
def softmax(z):
# z is a vector
return np.exp(z) / np.sum(np.exp(z))
def sigmoid(x):