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, WritableRaster} | |
import javax.imageio.ImageIO | |
import java.io.File | |
object grayscale extends App { | |
val (imgtype, imagefile, copyfile) = (args(0), args(1), args(2)) | |
val img = ImageIO.read(new File(imagefile)) | |
val mytype = img.getType | |
val raster:WritableRaster = img.getRaster | |
val (w,h) = (img.getWidth, img.getHeight) |
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
def mean(d:Data) = d.sum/d.size |
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
def variance(d:Data) = { | |
val mu = mean(d) | |
mean(d.map(i => (i-mu)*(i-mu))) | |
} | |
def stdev(d:Data) = math.sqrt(variance(d)) |
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
def scale(x:Data) = { | |
val scaler = x.max - x.min | |
val min = x.min | |
(x.map { i => (i-min)/scaler }, min, scaler) | |
} |
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
def normalize(x:Data) = { | |
val mu = OLS.mean(x) | |
val sigma = OLS.stdev(x) | |
(x.map{ i=> (i - mu)/sigma }, mu, sigma) | |
} |
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
def corr(x:Data, y:Data) = mean(x.zip(y).map(xy => xy._1 * xy._2)) |
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
case "qualitative" => | |
val sorted = rows | |
.groupBy(x=>x) | |
.map { xy => (xy._1, xy._2.size) } | |
.toList | |
.sortBy(x=>x._2) | |
.reverse | |
val py = sorted.head._2 | |
val px = rows.distinct.map(w => w.length).max | |
sorted.map { i=> |
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 GSSJob extends App { // A Data Mining job sourcing from General Social Survey (GSS) data. | |
val in = args(0) // input file | |
val task = args(1) // job, histo etc. | |
val data = src | |
val columnHeader = data.head | |
task match { | |
case "job" => job | |
case "histo" => histo |
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
val (x:Data, y:Data) = dataxy.toIndexedSeq.unzip | |
val (scaledx, xmin, xscaler) = scale(x) | |
val (scaledy, ymin, yscaler) = scale(y) | |
val ysq = scaledx.zip(scaledy).map{ xy => val(x,y) = xy; y - x*x } | |
val (normx, mux, sigmax) = normalize(scaledx) | |
val (normy, muy, sigmay) = normalize(ysq) | |
val corr = OLS.corr(normx,normy) |
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
<SCRIPT language="JavaScript"> | |
function fc(form) { | |
var Age = eval(form.age.value); | |
var Freq = (210 * ((Age - 18)/71)*((Age - 18)/71)) - (311*(Age - 18)/71) + 133 | |
form.freq.value = parseInt(Freq) | |
} | |
</script> | |
<FORM METHOD = "post"> | |
Age: <INPUT name= "age" value="18" size="2" type="text"> |
OlderNewer