This file contains 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 org.jfree.chart.{ChartFactory, ChartUtilities} | |
import org.jfree.data.time.{Day, TimeSeries, TimeSeriesCollection} | |
import scala.io.Source | |
import java.io.File | |
val dow = new TimeSeries("dow") | |
Source.fromFile("./DJI.csv").getLines.toStream.tail.foreach{ | |
x:String => | |
val arr = x.split(",") | |
val day = Day.parseDay(arr(0)) |
This file contains 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 multiprocessing as mp | |
import numpy as np | |
import sys | |
def printf(format, *args): | |
sys.stdout.write(format % args) | |
def f(x): | |
sum = 0 | |
for i in np.arange(x, 2*x,1): |
This file contains 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 util.Random | |
object TalebDart extends App { | |
case class Dart(x:Double, y:Double) | |
case class Box(minx:Double, miny:Double) { | |
var count = 0 | |
def inBox(dart:Dart):Boolean = { | |
val isin = dart.x >= minx && dart.x <= minx + 0.25 && |
This file contains 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
#include "factorial.h" | |
int factorial(int x) { | |
if (x==1) | |
return 1; | |
else | |
return x * factorial(x-1); | |
} |
This file contains 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
object ucb1 extends App { | |
printf("Min Bid:") | |
val min = readDouble | |
printf("Max Bid:") | |
val max = readDouble | |
printf("Number of arms:") | |
val arms = readInt | |
printf("Trials (say 1000):") | |
val trials = readInt |
This file contains 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
object variableBid extends App { | |
printf("Min Bid:") | |
val min = readDouble | |
printf("Max Bid:") | |
val max = readDouble | |
printf("Number of arms:") | |
val arms = readInt | |
printf("Trials (say 1000):") | |
val trials = readInt | |
printf("Epsilon (say 0.01):") |
This file contains 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
object epsilongreedy extends App { | |
// cmd-line inits | |
print("Run 10,000 trials with Arm Probabilities (eg. 0.3,0.7): ") | |
val s = readLine | |
val armprob:List[Double] = s.split(",").toList.map{ x => x.toDouble } | |
val arms = armprob.size | |
val trials = 10000 | |
val epsAll = List(0.01,0.1,0.5,0.9,0.99).map{ eps => Eps(eps, arms)} | |
val bestArm:Int = armprob.zipWithIndex.maxBy{ x=> x._1}._2 |
This file contains 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
/* | |
Given an unsorted array/list of integers, write a function that: | |
- returns True iff there are duplicate integers in the list | |
- returns False otherwise | |
[-12, 32, 56, -2] -> False | |
[32, 23, 23, 1, 5 ] -> True | |
*/ | |
// To execute Scala code, please define an object named Solution that extends App |
This file contains 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 selu, the best ever breakthrough activation function since sliced bread | |
import numpy as np | |
def selu(x): | |
alpha = 1.67326 | |
scale = 1.0507 | |
return scale*np.where(x>=0.0, x, alpha*np.exp(x) - alpha) | |
# Plot it in matplot, stare at it for a while | |
# I figure 3 straight lines can do a decent job of interpolating it on unit interval | |
from scipy import stats |
This file contains 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
object foo extends App { | |
case class C(n:String, id:Int, pid:Int) | |
val l = List(C("mh", 3,6), C("sf", 1,0), C("ny", 6,0), C("ba",2,1)) | |
def printChildren(pid:Int, l:List[C]):Unit = | |
l | |
.filter{ x=> x.pid == pid} | |
.sortBy{ x=> x.n} | |
.foreach {x => println(x.n); printChildren(x.id, l)} | |
printChildren(0, l) | |
} |