Skip to content

Instantly share code, notes, and snippets.

View S0ngyuLi's full-sized avatar

Songyu Li S0ngyuLi

View GitHub Profile
import numpy as np
import scipy.stats as ss
import time
def BinomialTree(type,S0, K, r, sigma, T, N=2000):
#calculate delta T
deltaT = np.divide(float(T), N)
# up and down factor will be constant for the tree so we calculate outside the loop
u = np.exp(sigma * np.sqrt(deltaT))
d = np.divide(1.0, u)
# Initialise our f_{i,j} tree with zeros
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
if (req.method == 'POST') {
console.log("POST");
var body = '';
req.on('data', function (data) {
labels <- read.table("batches.meta.txt")
images.rgb <- list()
images.lab <- list()
num.images = 10000 # Set to 10000 to retrieve all images per file to memory
# Cycle through all 5 binary files
for (f in 1:5) {
to.read <- file(paste("data_batch_", f, ".bin", sep=""), "rb")
for(i in 1:num.images) {
l <- readBin(to.read, integer(), size=1, n=1, endian="big")
@S0ngyuLi
S0ngyuLi / pima.R
Last active February 2, 2018 03:44
Naive Bayes Classifier in R
require(e1071)
pima_data <- read.csv(file = "pima.data", header=TRUE)
#load data into data frame
names(pima_data) <- c(1:9)
# 1. Number of times pregnant
# 2. Plasma glucose concentration a 2 hours in an oral glucose tolerance test
# 3. Diastolic blood pressure (mm Hg)
@S0ngyuLi
S0ngyuLi / example.js
Last active July 30, 2017 06:05
A Simple Tutorial on Callbacks
/*
Example 1
*/
func OkName(param1, param2, newStr, callback) {
callback(newStr)
}
OkName(1,2,"newStr", collectNewStr(param) {
store(param)
<div class="container" id="to-close" style="display:block">
<div class="container" id = "chat-out-box" style="height:300px;width:95%;background-color:#ffffff;overflow: scroll">
<ul class="list-group" id="all-messages" >
</ul>
</div>
<form class="form row" id = "chat-form" style="margin-top:30px;margin-left:15px;margin-bottom:10px;" id = "chat_message" method="POST" action="http://tripubproject.web.engr.illinois.edu/411SP17/frontend/trip/createTrip.php?<?php echo "planid=$the_plan_id"?>">
<input type="text" class="form-control col-10" id="messege_box" placeholder="Instant messeges?" name = "place">
<button type="submit" id="searchBtn" class="btn btn-primary">Send</button>
</form>
@S0ngyuLi
S0ngyuLi / dt.py
Created April 5, 2017 00:29
Decision Tree Generating Function
from pprint import pprint
import numpy as np
grade = np.array([3, 2, 1, 1, 2, 3, 2, 3, 2, 2, 1, 2, 3, 1, 2, 2, 1, 1, 2, 3, 1, 1, 2, 3, 2, 2, 3, 1, 3, 3])
# S=3 J=2 F=1
BMI = np.array([1,2,2,1,1,2,1,1,1,1,1,1,2,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,2])
#N=1 O = 2
y = np.array([0,1,1,1,0,0,0,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,1,1,0,0,1,1,1,0])
#+=1 -=0
trim = 20