|
1 |
| -# Pair Adjacent Violators |
| 1 | +# KWeb |
2 | 2 |
|
3 | 3 | ## Overview
|
4 | 4 |
|
5 |
| -An implementation of the [Pair Adjacent Violators](http://gifi.stat.ucla.edu/janspubs/2009/reports/deleeuw_hornik_mair_R_09.pdf) algorithm for [isotonic regression](https://en.wikipedia.org/wiki/Isotonic_regression). Written in [Kotlin](http://kotlinlang.org/) but usable from Java or any [other JVM language](https://en.wikipedia.org/wiki/List_of_JVM_languages). |
6 | 5 |
|
7 |
| -Note this algorithm is also known as "Pool Adjacent Violators". |
8 |
| - |
9 |
| -While not widely known, I've found this algorithm useful in a variety of circumstances, particularly when it comes to [calibration of predictive model outputs](http://scikit-learn.org/stable/modules/calibration.html). |
10 |
| - |
11 |
| -A picture is worth a thousand words: |
12 |
| - |
13 |
| - |
14 | 6 |
|
15 | 7 | ## Features
|
16 | 8 |
|
17 |
| -* Tries to do one thing and do it well with minimal bloat, no external dependencies (other than Kotlin's stdlib) |
18 |
| -* Fairly comprehensive [unit tests](https://github.com/trystacks/pairAdjacentViolators/tree/master/src/test/kotlin/com/github/sanity/pav) (using [Kotlintest](https://github.com/kotlintest/kotlintest)) |
19 |
| -* Employs an isotonic spline algorithm for smooth interpolation |
20 |
| -* Fairly efficient implementation without compromizing code readability |
21 |
| -* While implemented in Kotlin, works nicely from Java and other JVM languages |
22 |
| -* Supports reverse-interpolation |
23 |
| - |
24 | 9 | ## Usage
|
25 | 10 |
|
26 | 11 | ### Adding library dependency
|
27 | 12 |
|
28 | 13 | You can use this library by adding a dependency for Gradle, Maven, SBT, Leiningen or another Maven-compatible dependency management system thanks to Jitpack:
|
29 | 14 |
|
30 |
| -[](https://jitpack.io/#sanity/pairAdjacentViolators) |
| 15 | +[](https://jitpack.io/#sanity/kweb) |
31 | 16 |
|
32 | 17 | ### Basic usage from Kotlin
|
33 | 18 |
|
34 | 19 | ```kotlin
|
35 |
| -import com.github.sanity.pav.PairAdjacentViolators |
36 |
| -import com.github.sanity.pav.PairAdjacentViolators.* |
37 |
| -// ... |
38 |
| -val inputPoints = listOf(Point(3.0, 1.0), Point(4.0, 2.0), Point(5.0, 3.0), Point(8.0, 4.0)) |
39 |
| -val pav = PairAdjacentViolators(inputPoints) |
40 |
| -val interpolator = pav.interpolator() |
41 |
| -println("Interpolated: ${interpolator(6.0)}") |
42 |
| -``` |
43 |
| - |
44 |
| -### Basic usage from Java |
45 |
| -```java |
46 |
| -import com.github.sanity.pav.*; |
47 |
| -import com.github.sanity.pav.PairAdjacentViolators.*; |
48 |
| -import kotlin.jvm.functions.*; |
49 |
| -import java.util.*; |
50 |
| - |
51 |
| -public class PAVTest { |
52 |
| - public static void main(String[] args) { |
53 |
| - List<Point> points = new LinkedList<>(); |
54 |
| - points.add(new Point(0.0, 0.0)); |
55 |
| - points.add(new Point(1.0, 1.0)); |
56 |
| - points.add(new Point(2.0, 3.0)); |
57 |
| - points.add(new Point(3.0, 5.0)); |
58 |
| - PairAdjacentViolators pav = new PairAdjacentViolators(points); |
59 |
| - final Function1<Double, Double> interpolator = pav.interpolator(); |
60 |
| - for (double x=0; x<3; x+=0.1) { |
61 |
| - System.out.println(x+"\t"+interpolator.invoke(x)); |
| 20 | +import com.github.sanity.kweb.clientConduits.WebsocketsClientConduit |
| 21 | +import kotlinx.coroutines.async |
| 22 | +import kotlin.concurrent.thread |
| 23 | + |
| 24 | +fun main(args: Array<String>) { |
| 25 | + WebsocketsClientConduit(8091) { |
| 26 | + thread { |
| 27 | + async { |
| 28 | + var clicks = 0 |
| 29 | + val heading = doc.body.appendChild("h1") |
| 30 | + heading.setInnerHTML("0 clicks") |
| 31 | + heading.addEventListener("click") { |
| 32 | + clicks++ |
| 33 | + heading.setInnerHTML("$clicks clicks") |
| 34 | + false |
| 35 | + } |
| 36 | + } |
62 | 37 | }
|
| 38 | + false |
63 | 39 | }
|
| 40 | + Thread.sleep(10000) |
64 | 41 | }
|
65 |
| -``` |
66 | 42 |
|
67 |
| -### Full API documentation |
68 |
| -* [1.0.0](https://jitpack.io/com/github/sanity/pairAdjacentViolators/1.0.0/javadoc/com.github.sanity.pav/index.html) |
69 |
| -* [SNAPSHOT](https://jitpack.io/com/github/sanity/pairAdjacentViolators/-SNAPSHOT/javadoc/com.github.sanity.pav/index.html) (warning: This may take a while to load as it is rebuilt on-demand) |
| 43 | +``` |
70 | 44 |
|
71 | 45 | ### License
|
72 | 46 | Released under the [LGPL](https://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License) version 3 by [Ian Clarke](http://blog.locut.us/) of [Stacks](http://trystacks.com/).
|
73 |
| - |
74 |
| -### Development |
75 |
| -[](https://travis-ci.org/sanity/pairAdjacentViolators) |
0 commit comments