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 io.reactivex.Observable | |
| import io.reactivex.Single | |
| import io.reactivex.subjects.BehaviorSubject | |
| class RefreshTrigger { | |
| private val _refreshEvents = BehaviorSubject.createDefault(Unit).toSerialized() | |
| val refreshEvents: Observable<Unit> = _refreshEvents | |
| fun refresh() = _refreshEvents.onNext(Unit) |
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
| 99.5048419879 | 159.4644145002 | |
|---|---|---|
| 44.6627659498 | 50.5081790885 | |
| 66.6313365164 | 91.6775703113 | |
| 74.6638781433 | 121.2768737608 | |
| 57.5548532699 | 77.6605107301 | |
| 179.5856336758 | 315.783778234 | |
| 35.6445040985 | 43.0664477198 | |
| 86.4089899745 | 140.1552280161 | |
| 152.7882048383 | 266.240528791 | |
| 1.6307540858 | -20.8768252687 |
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 java.net.URL | |
| fun main(args: Array<String>) { | |
| // Fit points to a line conforming to y = mx + b | |
| class Point(val x: Double, val y: Double) | |
| val points = URL("https://tinyurl.com/yaxgfjzt") | |
| .readText().split(Regex("\\r?\\n")) |
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 java.util.concurrent.ThreadLocalRandom | |
| import kotlin.math.pow | |
| import kotlin.math.sqrt | |
| fun main(args: Array<String>) { | |
| (0..1000).map { randomSample() } | |
| .forEach { | |
| println("$it,${2*it}") | |
| } |
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 kotlin.math.pow | |
| fun main(args: Array<String>) { | |
| val xSquare = { x: Double -> x.pow(2) } | |
| val slope = derivativeOf(1.0, xSquare) | |
| println(slope) | |
| } |
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
| fun main(args: Array<String>) { | |
| class Item(val weight: Double, val value: Double) | |
| val items = listOf( | |
| Item(1.0, 2.0), | |
| Item(2.0, 4.0), | |
| Item(3.0, 6.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
| import java.util.concurrent.ThreadLocalRandom | |
| import kotlin.math.pow | |
| fun pdf(x: Double) = 2 * x // y = 2x from 0 to 1 is probability distribution function | |
| fun cdf(x: Double) = x.pow(2) // CDF plots area under PDF curve https://www.wolframalpha.com/input/?i=integral+2x | |
| fun reverseCdf(a: Double) = a.pow(.5) // Reverse CDF to sample the area and the resuling x | |
| fun main() { | |
| (1..1000).asSequence() |
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 kotlin.math.pow | |
| // https://www.desmos.com/calculator/qjxcsxsl6t | |
| // https://www.wolframalpha.com/input/?i=integral+-2(x-1)%5E2+%2B+2 | |
| fun main(args: Array<String>) { | |
| println(f(1.0)) | |
| println(integratedF(0.0,2.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
| import org.ojalgo.random.Binomial | |
| fun main(args: Array<String>) { | |
| // I have a 6-sided fair dice | |
| // what is the probability I will roll 3 sixes out of 10 trials? | |
| val probabilityOfSide = 1.0 / 6.0 | |
| Binomial(10, probabilityOfSide).apply { |
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.application.Application | |
| import javafx.scene.chart.NumberAxis | |
| import org.ojalgo.random.Normal | |
| import tornadofx.* | |
| fun main(args: Array<String>) { | |
| Application.launch(QuickScatterPlotApp::class.java) | |
| } |