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
def leg(mode: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) | |
} | |
stream.take(mode + 1).toIndexedSeq | |
} |
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
package CLEAN | |
import scalala.tensor.dense.{DenseMatrix => Image} | |
import collection.mutable.ArrayBuffer | |
/** | |
* Clean class implemented in Scala | |
* Author: James R. Thompson, D.Phil | |
* Date: 7/16/12 | |
* Time: 9:31 AM |
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
package Spots | |
import collection.mutable.ArrayBuffer | |
/** | |
* Track class | |
* Author: James R. Thompson, D.Phil | |
* Date: 7/16/12 | |
* Time: 9:31 AM | |
* USC Mork Family Dept. of Chem. Eng. & Mat. Sci. |
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 javafx.scene.image.Image; | |
import javax.imageio.ImageIO; | |
import java.awt.image.*; | |
import java.io.ByteArrayInputStream; | |
import java.io.ByteArrayOutputStream; | |
public Image getJavaFXImage(byte[] rawPixels, int width, int height) { | |
ByteArrayOutputStream out = new ByteArrayOutputStream(); | |
try { | |
ImageIO.write((RenderedImage) createBufferedImage(rawPixels, width, height), "png", out); |
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.math._ | |
case class Complex(re: Double, im: Double = 0.0) { | |
def +(x: Complex): Complex = Complex((this.re+x.re), (this.im+x.im)) | |
def -(x: Complex): Complex = Complex((this.re-x.re), (this.im-x.im)) | |
def *(x: Complex): Complex = Complex(this.re*x.re-this.im*x.im, this.re*x.im+this.im*x.re) | |
} | |
def transformReal(input:IndexedSeq[Double]) = { | |
val data = padder(input.map(i => Complex(i)).toList) |
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 javafx.scene.image.Image | |
import javax.imageio.ImageIO | |
import java.awt.image._ | |
import java.io.{ByteArrayInputStream, ByteArrayOutputStream, IOException} | |
import java.util.logging.{Level, Logger} | |
object JFXImageUtil { | |
def getJavaFXImage(rawPixels:Array[Byte], width:Int, height:Int) = { | |
val out = new ByteArrayOutputStream |
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
def calcStDev(in: List[Double]) = { | |
def squaredDifference(v1:Double, v2:Double) = math.pow(v1 - v2,2.0) | |
val mean = in.sum / in.length | |
val squared = in.foldLeft(0.0)(_ + squaredDifference(_, mean)) | |
math.sqrt(squared / in.length.toDouble) | |
} | |
def ckf(in:List[Double], windowSize:Int) : List[Double] = { | |
val out = for(i <- windowSize until in.length - windowSize) yield { | |
val forward = calcStDev(in.slice(i, i + windowSize + 1)) |
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 |
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
{ | |
"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 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) | |
} |
OlderNewer