commit
						5ad426f4a9
					
				
							
								
								
									
										13
									
								
								__tests__/Bandwidth__Test.re
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								__tests__/Bandwidth__Test.re
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| open Jest; | ||||
| open Expect; | ||||
| 
 | ||||
| describe("Bandwidth", () => { | ||||
|   test("nrd0()", () => { | ||||
|     let data = [|1., 4., 3., 2.|]; | ||||
|     expect(Science.nrd0(data)) |> toEqual(0.7635139420854616); | ||||
|   }); | ||||
|   test("nrd()", () => { | ||||
|     let data = [|1., 4., 3., 2.|]; | ||||
|     expect(Science.nrd(data)) |> toEqual(0.899249754011766); | ||||
|   }); | ||||
| }); | ||||
|  | @ -60,7 +60,8 @@ | |||
|     "react-use": "^13.27.0", | ||||
|     "reason-react": ">=0.7.0", | ||||
|     "reschema": "1.3.0", | ||||
|     "tailwindcss": "1.2.0" | ||||
|     "tailwindcss": "1.2.0", | ||||
|     "science": "1.9.3" | ||||
|   }, | ||||
|   "alias": { | ||||
|     "react": "./node_modules/react", | ||||
|  |  | |||
							
								
								
									
										28
									
								
								src/utility/Science.re
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/utility/Science.re
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,28 @@ | |||
| [@bs.val] [@bs.module "science"] [@bs.scope "stats"] | ||||
| external variance: array(float) => float = "variance"; | ||||
| 
 | ||||
| [@bs.val] [@bs.module "science"] [@bs.scope "stats"] | ||||
| external iqr: array(float) => float = "iqr"; | ||||
| 
 | ||||
| let len = x => E.A.length(x) |> float_of_int; | ||||
| 
 | ||||
| let nrd0 = x => { | ||||
|   let hi = Js_math.sqrt(variance(x)); | ||||
|   let lo = Js_math.minMany_float([|hi, iqr(x) /. 1.34|]); | ||||
|   let e = Js_math.abs_float(x[1]); | ||||
|   let lo' = | ||||
|     switch (lo, hi, e) { | ||||
|     | (lo, hi, e) when !Js.Float.isNaN(lo) => lo | ||||
|     | (lo, hi, e) when !Js.Float.isNaN(hi) => hi | ||||
|     | (lo, hi, e) when !Js.Float.isNaN(e) => e | ||||
|     | _ => 1.0 | ||||
|     }; | ||||
|   0.9 *. lo' *. Js_math.pow_float(len(x), -0.2); | ||||
| }; | ||||
| 
 | ||||
| let nrd = x => { | ||||
|   let h = iqr(x) /. 1.34; | ||||
|   1.06 | ||||
|   *. Js_math.min_float(Js_math.sqrt(variance(x)), h) | ||||
|   *. Js_math.pow_float(len(x), (-1.0) /. 5.0); | ||||
| }; | ||||
|  | @ -8579,6 +8579,11 @@ scheduler@^0.19.0: | |||
|     loose-envify "^1.1.0" | ||||
|     object-assign "^4.1.1" | ||||
| 
 | ||||
| science@1.9.3: | ||||
|   version "1.9.3" | ||||
|   resolved "https://registry.yarnpkg.com/science/-/science-1.9.3.tgz#ec89bac44aeff2e5a2d749aa496f377089903dd4" | ||||
|   integrity sha1-7Im6xErv8uWi10mqSW83cImQPdQ= | ||||
| 
 | ||||
| screenfull@^5.0.0: | ||||
|   version "5.0.2" | ||||
|   resolved "https://registry.yarnpkg.com/screenfull/-/screenfull-5.0.2.tgz#b9acdcf1ec676a948674df5cd0ff66b902b0bed7" | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user