parent
cb24eea86b
commit
6b4ea88734
1 changed files with 9 additions and 8 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
|
import std/math
|
||||||
import std/stats
|
import std/stats
|
||||||
|
|
||||||
proc `~=`(x, y: float): bool =
|
func `~=`(x, y: float32): bool =
|
||||||
abs(x - y) < 10e-8
|
math.almostEqual(x, y)
|
||||||
|
|
||||||
template main() =
|
template main() =
|
||||||
var rs: RunningStat
|
var rs: RunningStat
|
||||||
|
|
@ -28,21 +29,21 @@ template main() =
|
||||||
doAssert rs1.kurtosis ~= rs.kurtosis
|
doAssert rs1.kurtosis ~= rs.kurtosis
|
||||||
rs1.clear()
|
rs1.clear()
|
||||||
rs1.push(@[1.0, 2.2, 1.4, 4.9])
|
rs1.push(@[1.0, 2.2, 1.4, 4.9])
|
||||||
doAssert(rs1.sum == 9.5)
|
doAssert rs1.sum ~= 9.5
|
||||||
doAssert(rs1.mean() == 2.375)
|
doAssert rs1.mean() ~= 2.375
|
||||||
|
|
||||||
when not defined(cpu32):
|
when not defined(cpu32):
|
||||||
# XXX For some reason on 32bit CPUs these results differ
|
# XXX For some reason on 32bit CPUs these results differ
|
||||||
var rr: RunningRegress
|
var rr: RunningRegress
|
||||||
rr.push(@[0.0, 1.0, 2.8, 3.0, 4.0], @[0.0, 1.0, 2.3, 3.0, 4.0])
|
rr.push(@[0.0, 1.0, 2.8, 3.0, 4.0], @[0.0, 1.0, 2.3, 3.0, 4.0])
|
||||||
doAssert(rr.slope() == 0.9695585996955861)
|
doAssert rr.slope() ~= 0.9695585996955861
|
||||||
doAssert(rr.intercept() == -0.03424657534246611)
|
doAssert rr.intercept() ~= -0.03424657534246611
|
||||||
doAssert(rr.correlation() == 0.9905100362239381)
|
doAssert rr.correlation() ~= 0.9905100362239381
|
||||||
var rr1, rr2: RunningRegress
|
var rr1, rr2: RunningRegress
|
||||||
rr1.push(@[0.0, 1.0], @[0.0, 1.0])
|
rr1.push(@[0.0, 1.0], @[0.0, 1.0])
|
||||||
rr2.push(@[2.8, 3.0, 4.0], @[2.3, 3.0, 4.0])
|
rr2.push(@[2.8, 3.0, 4.0], @[2.3, 3.0, 4.0])
|
||||||
let rr3 = rr1 + rr2
|
let rr3 = rr1 + rr2
|
||||||
doAssert(rr3.correlation() == rr.correlation())
|
doAssert rr3.correlation() ~= rr.correlation()
|
||||||
doAssert rr3.slope() ~= rr.slope()
|
doAssert rr3.slope() ~= rr.slope()
|
||||||
doAssert rr3.intercept() ~= rr.intercept()
|
doAssert rr3.intercept() ~= rr.intercept()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue