Posts

, ,

Implementing k-means in Scala

To generate sample data, I selected two points, (10, 20) and (25, 5), then generated a list of normally distributed points around those two – the exact points used are in the code below. This implements Lloyd’s algorithm, which tries to cluster points in iterations in a simple manner: 1. Assume a certain number of […]

Scala zipAll Example

The zip function combines two lists into tuples. If the lists are of differing lengths, the shorter length is used. If you don’t like this behavior, the zipAll function will keep all elements, filling in specified values for the blanks (compare this to the recycling rule in R, which lets you continuously cycle through the […]

Scala Tree Sort Example

This demonstrates basic language features – case classes, iteration, anonymous functions, etc. abstract class Node case class LeafNode(data: String) extends Node; case class FullNode(data: String, left: Node, right: Node) extends Node case class LeftNode(data: String, left: Node) extends Node case class RightNode(data: String, right: Node) extends Node   object test extends App { val words […]

Scala vs. Clojure

LinkedIn shows 42% growth (year over year?) people claiming Clojure as a skill – surprisingly beating out Scala’s 9%, a surprising feat for a lisp-variant. Turns out LinkedIn’s default view is misleading – Scala shows more new adopters (2.4k) vs  1.5k for Clojure. LinkedIn refuses to show counts for Java- but check out the number […]

,

How to find Pitches in Music

Have you ever wanted to find what chords were in a song? A good first step is to read the notes played during a short time interval. If several notes are played simultaneously, in order to figure out the notes, we need to separate the waveform into the individual frequencies. Fortunately there is a well-established […]

How to Write a Wav File in Scala

The following code will play a chord to a Wav file using Scala. This is adapted from sample code and uses the library here to handle the file format. One of the nice things about Scala is the ease of using existing Java code, since it runs on the JVM. I started this project by […]