This file contains hidden or 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
implicit class LinearRegression[NA: Numeric, NB: Numeric, M[+_]](pts: (M[NA], M[NB])) { | |
def getVector[A: Numeric](in: M[A]) : Vector[Double] = { | |
val n = implicitly[Numeric[A]] | |
in.asInstanceOf[TraversableLike[A, Traversable[A]]].map(n.toDouble(_)).toVector | |
} | |
def lnfit = { | |
val xpts = getVector(pts._1) | |
val ypts = getVector(pts._2) | |
xpts.isEmpty match { | |
case true => None |
This file contains hidden or 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.collection.generic.CanBuildFrom | |
import scala.collection.TraversableLike | |
implicit class Normalizer[N:Numeric, M[+_]](xs:M[N]) { | |
def normalize(implicit bf: CanBuildFrom[M[N], Double, M[Double]], | |
ev: M[N] => TraversableLike[N, M[N]], | |
eb: M[Double] => TraversableLike[Double, M[Double]]) = { | |
val n = implicitly[Numeric[N]] | |
val mind = n.toDouble(xs.min) | |
val maxd = n.toDouble(xs.max) | |
xs.map(v => (n.toDouble(v) - mind) * (1 / (maxd - mind))) |
This file contains hidden or 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
implicit class Meter(val num: Double) extends AnyVal { | |
def m : Double = num | |
def mm : Double = num / 1e3 | |
def um : Double = num / 1e6 | |
def nm : Double = num / 1e9 | |
} |
This file contains hidden or 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
implicit class Timer[T](f: => T) { | |
def timems = { | |
val before = System.currentTimeMillis | |
val result = f | |
val end = System.currentTimeMillis | |
println(s"Operation elapsed time = ${end - before} ms >>> Result = $result") | |
} | |
def timens = { | |
val before = System.nanoTime | |
val result = f |
This file contains hidden or 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
group = 'com.malmstadt' | |
version = 1.0 | |
apply plugin: 'scala' | |
apply from: 'https://repository-javafx-gradle-plugin.forge.cloudbees.com/release/javafx.plugin' | |
repositories { | |
mavenCentral() | |
} |
This file contains hidden or 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
apply plugin: 'java' | |
sourceCompatibility=1.6 | |
targetCompatibility=1.6 | |
dependencies { | |
compile files("/Users/James/Desktop/GUVJesper/lib/ij.jar", "/Users/James/Desktop/GUVJesper/lib/loci_tools.jar") | |
} | |
mainClass = 'ND2_GUVPlugin' |
This file contains hidden or 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
Show hidden characters
{ | |
// You probably want to configure this to something of your own | |
// ${home}, ${env:<variable>}, ${project_path:} and ${folder:} tokens can be used in the sublimejava_classpath option. | |
// | |
// ${home} is replaced with the value of the HOME environment variable. | |
// | |
// ${env:<variable>} is replaced with the "variable" environment variable. | |
// | |
// ${project_path:} tries to find a file with the given name in all the registered project folders and | |
// returns the first file found, or the original file name if none is found. |
This file contains hidden or 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 Legendre { | |
// Returns all the Legendre Polynomials Up to that l number using For Loop -> Yield - to get the l-th term take .tail (m = 0 for the Legendre Polynomials) | |
// Horner's Rule implemented as a Stream | |
def leg(l : Int, angle : Double) : IndexedSeq[Double] = { | |
val cosAngle = math.cos(angle) | |
lazy val stream : Stream[Double] = { | |
def loop(last:Double, curr:Double, k:Double = 0.0) : Stream[Double] = curr #:: loop(curr, ((2 * k + 1) * cosAngle * curr - k * last) / (k + 1), k + 1) | |
loop(0.0, 1.0) | |
} |
This file contains hidden or 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
{ | |
"cmd": ["/Users/James/Documents/Code/sbt/bin/sbt -no-colors compile run"], | |
"file_regex": "^\\[error\\] ([.a-zA-Z0-9/-]+[.]scala):([0-9]+):", | |
"selector": "source.scala", | |
"working_dir": "${project_path:${folder}}", | |
"shell": "true" | |
} |
This file contains hidden or 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 LinearRegression { | |
def fit(data: List[(Double,Double)]) = { | |
def sqr(in:Double) : Double = in * in | |
val sumx = data.map(_._1).sum | |
val sumx2 = data.map((d:(Double,Double)) => sqr(d._1)).sum | |
val sumy = data.map(_._2).sum | |
val xbar = sumx / data.length | |
val ybar = sumy / data.length | |
val xxbar = data.map(d => sqr(d._1 - xbar)).sum |