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
abstract class Exp { | |
def evaluate(x: Double): Double | |
def derivative(): Exp | |
def toStringCanonical(): String | |
} | |
object Exp { | |
def main(args: Array[String]): Unit = { | |
println(parse("2*x^2").derivative().toStringCanonical()) | |
} |
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
// https://github.com/shashir/cs7641/blob/master/lessons/ml_p1_lesson_01_decision_trees.md#id3-algorithm | |
import scala.collection.mutable.{Set => MSet} | |
case class Tree[T]( | |
value: T, | |
children: MSet[Tree[T]] = MSet.empty[Tree[T]] | |
) { | |
override def toString(): String = { | |
value + |
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 ArgMinMax { | |
import scala.reflect.ClassTag | |
def argmin[X: ClassTag, Y <% Ordered[Y] : ClassTag](n: Iterable[X], f: X => Y): X = { | |
val (argmin: X, min: Y) = n.tail.fold((n.head, f(n.head))) { case ((a: X, m: Y), x: X) => | |
val fOfx: Y = f(x) | |
if (fOfx < m) (x, fOfx) else (a, m) | |
} | |
return argmin | |
} |
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 java.awt.image.BufferedImage | |
import java.io.File | |
import javax.imageio.ImageIO | |
case class Histogram( | |
resolution: Int, | |
pixels: Int, | |
histogram: Array[Array[Array[Int]]] | |
) { | |
def distance(that: Histogram): Double = { |
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 scala.reflect.ClassTag | |
case class Matrix[T : ClassTag]( | |
rows: Int, | |
cols: Int, | |
matrix: Array[Array[T]] | |
)(implicit num: Numeric[T]) { | |
import num._ | |
require(matrix.length == rows, "Row number incorrect.") |
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 numpy as np | |
import random as rand | |
import datetime | |
class QLearner(object): | |
def __init__(self, \ | |
num_states=100, \ | |
num_actions = 4, \ | |
alpha = 0.2, \ | |
gamma = 0.9, \ |
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 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 java.sql.Connection | |
import java.sql.DriverManager | |
import java.sql.ResultSet | |
import java.sql.Statement | |
import scala.annotation.tailrec | |
import com.typesafe.scalalogging.slf4j.Logger | |
import org.slf4j.LoggerFactory |
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
#!/bin/bash | |
SERVERS=( | |
# list of servers | |
) | |
# USER= | |
# SSH_KEY= | |
echo "Command to run is: $1" | |
for server in ${SERVERS[@]}; do |
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 java.util.Scanner; | |
public class TicTacToe { | |
public static char X = 'X'; | |
public static char O = 'O'; | |
public static char B = ' '; | |
public static void main(String[] args) { | |
/* | |
* Squares are associated with following variables. |
NewerOlder