Last active
September 1, 2024 10:15
-
-
Save dacr/8691088404d627dc2d1c7b8429a4087d to your computer and use it in GitHub Desktop.
smile visualization histograms / published by https://github.com/dacr/code-examples-manager #25fb6f11-ace3-4e58-bc17-16e1e2287da2/4078c4d2ba070d934f6723c50fb11abae0daf987
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
// summary : smile visualization histograms | |
// keywords : smile, chart, visualization | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 25fb6f11-ace3-4e58-bc17-16e1e2287da2 | |
// created-on : 2021-03-05T09:23:01Z | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.4.2" | |
//> using dep "com.github.pathikrit::better-files:3.9.2" | |
//> using dep "com.github.haifengl::smile-scala:3.1.1" | |
//> using dep "org.bytedeco:javacpp-platform:1.5.10" | |
//> using dep "org.bytedeco:javacpp:1.5.10,classifier=linux-x86_64" | |
//> using dep "org.bytedeco:arpack-ng:3.9.1-1.5.10,classifier=linux-x86_64" | |
//> using dep "org.bytedeco:openblas:0.3.26-1.5.10,classifier=linux-x86_64" | |
//> using dep "org.slf4j:slf4j-nop:2.0.13" | |
//> using dep "com.lihaoyi::requests:0.9.0" | |
// --------------------- | |
import better.files.* | |
import smile.stat.distribution.* | |
import smile.math.matrix.* | |
import smile.plot.swing.* | |
import smile.plot.show | |
//import smile.plot.Render.* | |
// examples coming from http://haifengl.github.io/visualization.html | |
// -------------------------------------------------------------------- | |
val inputFileName = "cow.txt" | |
val inputFile = inputFileName.toFile | |
if (inputFile.notExists) { | |
val url = "https://gist.githubusercontent.com/dacr/90501dc71a302d1c2b41ffbc17383540/raw/f2531da9031e297943c4b438569f7f60e5348852/cow.txt" | |
for {out <- inputFile.newOutputStream.autoClosed} {requests.get(url).writeBytesTo(out)} | |
} | |
val cowdf = smile.read.csv(inputFileName, header=false) | |
println(cowdf.summary()) | |
val cow = cowdf("V1").toDoubleArray | |
// -------------------------------------------------------------------- | |
implicit val renderer:Canvas=>Unit = JWindow.apply | |
{ | |
val canvas = hist(cow, 50) | |
canvas.setAxisLabels("Weight", "Probability") | |
show(canvas) | |
} | |
// -------------------------------------------------------------------- | |
{ | |
val canvas = hist(cow.filter(_ <= 3500), 50) | |
canvas.setAxisLabels("Weight", "Probability") | |
show(canvas) | |
} | |
// -------------------------------------------------------------------- | |
{ | |
val gauss = new MultivariateGaussianDistribution(Array(0.0, 0.0), Matrix.of(Array(Array(1.0, 0.6), Array(0.6, 2.0)))) | |
val data = (0.until(10000)) map { (i: Int) => gauss.rand } | |
show(hist3(data.toArray, 50, 50)) | |
} | |
// -------------------------------------------------------------------- | |
println("enter to exit"); scala.io.StdIn.readLine() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment