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
+---+---+ | |
| x| y| | |
+---+---+ | |
| 1| 0| | |
| 2| 0| | |
| 3| 0| | |
| 4| 0| | |
| 5| 0| | |
| 6| 0| | |
| 7| 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
// Given 2 points in first quadrant | |
// Point p1 (a,b) | |
// Point p2 (c,d) | |
// a,b,c,d > 0 | |
// | |
// Find point X(x,0) on x axis | |
// such that | |
// ||p1-X|| + ||p2-X|| is smallest | |
// |
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
>spark-shell | |
import org.apache.spark.sql.SQLContext | |
val sql = new SQLContext(sc) | |
sql.read.format("orc").load("./test.orc").schema.foreach(println) |
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 |