Skip to content

Commit

Permalink
Slit Stats function and fix Entropy calculation. (#211)
Browse files Browse the repository at this point in the history
* Split Stats function and fix Entropy calculation.

* Update dependencies and bump version.

---------

Co-authored-by: nicolaasuni-vonage <[email protected]>
  • Loading branch information
github-actions[bot] and nicolaasuni-vonage authored Sep 17, 2023
1 parent d7e1d12 commit 41bc493
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 60 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.80.2
1.80.3
8 changes: 4 additions & 4 deletions examples/service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ go 1.21
replace github.com/Vonage/gosrvlib => ../..

require (
github.com/Vonage/gosrvlib v1.80.2
github.com/Vonage/gosrvlib v1.80.3
github.com/golang/mock v1.6.0
github.com/jstemmer/go-junit-report v0.9.1
github.com/prometheus/client_golang v1.16.0
github.com/rakyll/gotest v0.0.6
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
github.com/stretchr/testify v1.8.4
go.uber.org/zap v1.25.0
go.uber.org/zap v1.26.0
)

require (
Expand Down Expand Up @@ -95,12 +95,12 @@ require (
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.140.0 // indirect
google.golang.org/api v0.141.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/grpc v1.58.0 // indirect
google.golang.org/grpc v1.58.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
14 changes: 6 additions & 8 deletions examples/service/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,6 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.21.5 h1:CQBFElb0LS8RojMJlxRSo/HXipvT
github.com/aws/aws-sdk-go-v2/service/sts v1.21.5/go.mod h1:VC7JDqsqiwXukYEDjoHh9U0fOJtNWh04FPQz4ct4GGU=
github.com/aws/smithy-go v1.14.2 h1:MJU9hqBGbvWZdApzpvoF2WAIJDbtjK2NDJSiJP7HblQ=
github.com/aws/smithy-go v1.14.2/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -808,8 +806,8 @@ go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.25.0 h1:4Hvk6GtkucQ790dqmj7l1eEnRdKm3k3ZUrUMS2d5+5c=
go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down Expand Up @@ -1088,8 +1086,8 @@ google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz513
google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg=
google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE=
google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8=
google.golang.org/api v0.140.0 h1:CaXNdYOH5oQQI7l6iKTHHiMTdxZca4/02hRg2U8c2hM=
google.golang.org/api v0.140.0/go.mod h1:aGbCiFgtwb2P6badchFbSBUurV6oR5d50Af4iNJtDdI=
google.golang.org/api v0.141.0 h1:Df6vfMgDoIM6ss0m7H4MPwFwY87WNXHfBIda/Bmfl4E=
google.golang.org/api v0.141.0/go.mod h1:iZqLkdPlXKyG0b90eu6KxVSE4D/ccRF2e/doKD2CnQQ=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
Expand Down Expand Up @@ -1159,8 +1157,8 @@ google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8=
google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o=
google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
google.golang.org/grpc v1.58.1 h1:OL+Vz23DTtrrldqHK49FUOPHyY75rvFqJfXC84NYW58=
google.golang.org/grpc v1.58.1/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/tecnickcom/statsd/v2 v2.0.8
github.com/undefinedlabs/go-mpatch v1.0.7
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.25.0
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.13.0
golang.org/x/text v0.13.0
)
Expand Down Expand Up @@ -120,12 +120,12 @@ require (
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.140.0 // indirect
google.golang.org/api v0.141.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // indirect
google.golang.org/grpc v1.58.0 // indirect
google.golang.org/grpc v1.58.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,6 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.21.5 h1:CQBFElb0LS8RojMJlxRSo/HXipvT
github.com/aws/aws-sdk-go-v2/service/sts v1.21.5/go.mod h1:VC7JDqsqiwXukYEDjoHh9U0fOJtNWh04FPQz4ct4GGU=
github.com/aws/smithy-go v1.14.2 h1:MJU9hqBGbvWZdApzpvoF2WAIJDbtjK2NDJSiJP7HblQ=
github.com/aws/smithy-go v1.14.2/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -889,8 +887,8 @@ go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.25.0 h1:4Hvk6GtkucQ790dqmj7l1eEnRdKm3k3ZUrUMS2d5+5c=
go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
Expand Down Expand Up @@ -1178,8 +1176,8 @@ google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz513
google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg=
google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE=
google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8=
google.golang.org/api v0.140.0 h1:CaXNdYOH5oQQI7l6iKTHHiMTdxZca4/02hRg2U8c2hM=
google.golang.org/api v0.140.0/go.mod h1:aGbCiFgtwb2P6badchFbSBUurV6oR5d50Af4iNJtDdI=
google.golang.org/api v0.141.0 h1:Df6vfMgDoIM6ss0m7H4MPwFwY87WNXHfBIda/Bmfl4E=
google.golang.org/api v0.141.0/go.mod h1:iZqLkdPlXKyG0b90eu6KxVSE4D/ccRF2e/doKD2CnQQ=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
Expand Down Expand Up @@ -1255,8 +1253,8 @@ google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAG
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc v1.58.0 h1:32JY8YpPMSR45K+c3o6b8VL73V+rR8k+DeMIr4vRH8o=
google.golang.org/grpc v1.58.0/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
google.golang.org/grpc v1.58.1 h1:OL+Vz23DTtrrldqHK49FUOPHyY75rvFqJfXC84NYW58=
google.golang.org/grpc v1.58.1/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
Expand Down
2 changes: 1 addition & 1 deletion pkg/sliceutil/example_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func ExampleStats() {

// Output:
// Count: 12
// Entropy: -2277.134
// Entropy: 2.302
// ExKurtosis: -1.910
// Max: 83
// MaxID: 1
Expand Down
76 changes: 47 additions & 29 deletions pkg/sliceutil/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,14 @@ type DescStats[V typeutil.Number] struct {
}

// Stats returns descriptive statistics parameters to summarize the input data set.
//
//nolint:gocognit,gocyclo,cyclop,funlen
func Stats[S ~[]V, V typeutil.Number](s S) (*DescStats[V], error) {
n := len(s)

if n < 1 {
return nil, fmt.Errorf("input slice is empty")
}

ord := slices.Clone(s)
slices.Sort(ord)

ds := &DescStats[V]{
Count: len(s),
Count: n,
Max: s[0],
Median: float64(s[0]),
Min: s[0],
Expand All @@ -98,28 +92,34 @@ func Stats[S ~[]V, V typeutil.Number](s S) (*DescStats[V], error) {
}

nf := float64(n)

ord := slices.Clone(s)
slices.Sort(ord)

statsCenter(ds, s, ord, n, nf)
statsVariability(ds, ord, nf)
statsShape(ds, ord, nf)

return ds, nil
}

// statsCenter calculates Min, Max, Mode, ModeFreq, Range, Mean and Median.
func statsCenter[S ~[]V, V typeutil.Number](ds *DescStats[V], s, ord S, n int, nf float64) {
freq := 1

for i := 1; i < n; i++ {
v := s[i]
vf := float64(s[i])

ds.Sum += v

if v < ds.Min {
ds.Min = v
ds.MinID = i
}

if v > ds.Max {
} else if v > ds.Max {
ds.Max = v
ds.MaxID = i
}

if v != 0 {
ds.Entropy -= vf * math.Log(vf)
}

if ord[i] == ord[i-1] {
freq++
} else {
Expand All @@ -139,41 +139,59 @@ func Stats[S ~[]V, V typeutil.Number](s S) (*DescStats[V], error) {
ds.Range = ds.Max - ds.Min
ds.Mean = float64(ds.Sum) / nf

statsMedian(ds, ord, n)
}

// statsMedian calculates Median.
func statsMedian[S ~[]V, V typeutil.Number](ds *DescStats[V], ord S, n int) {
midpos := n / 2
if n%2 != 0 {
ds.Median = float64(ord[midpos])
} else {
ds.Median = (float64(ord[midpos-1]) + float64(ord[midpos])) / 2
ds.Median = float64(ord[midpos])

if n%2 == 0 {
ds.Median = (float64(ord[midpos-1]) + ds.Median) / 2
}
}

// statsVariability calculates Entropy, MeanDev, Varianceand StdDev. It must be called after statsCenter().
func statsVariability[S ~[]V, V typeutil.Number](ds *DescStats[V], ord S, nf float64) {
sum := float64(ds.Sum)

for i := 0; i < n; i++ {
d := float64(ord[i]) - ds.Mean
for _, v := range ord {
vf := float64(v)
d := vf - ds.Mean
ds.MeanDev += d
ds.Variance += d * d

if v != 0 {
vf /= sum
ds.Entropy -= vf * math.Log(vf)
}
}

ds.MeanDev /= nf
ds.Variance /= (nf - 1)
ds.StdDev = math.Sqrt(ds.Variance)
}

if n < 3 {
return ds, nil
// statsShape calculates Skewness and ExKurtosis. It must be called after statsVariability().
func statsShape[S ~[]V, V typeutil.Number](ds *DescStats[V], ord S, nf float64) {
if nf < 3 {
return
}

for i := 0; i < n; i++ {
d := (float64(ord[i]) - ds.Mean) / ds.StdDev
for _, v := range ord {
d := (float64(v) - ds.Mean) / ds.StdDev
d3 := d * d * d
ds.Skewness += d3
ds.ExKurtosis += d3 * d
}

ds.Skewness *= (nf / ((nf - 1) * (nf - 2))) // adjusted Fisher-Pearson standardized moment coefficient

if n < 4 {
if nf < 4 {
ds.ExKurtosis = 0
} else {
ds.ExKurtosis = (ds.ExKurtosis * (((nf + 1) / (nf - 1)) * (nf / (nf - 2)) * (1 / (nf - 3)))) - (3 * ((nf - 1) / (nf - 2)) * ((nf - 1) / (nf - 3)))
return
}

return ds, nil
ds.ExKurtosis = (ds.ExKurtosis * (((nf + 1) / (nf - 1)) * (nf / (nf - 2)) * (1 / (nf - 3)))) - (3 * ((nf - 1) / (nf - 2)) * ((nf - 1) / (nf - 3)))
}
12 changes: 6 additions & 6 deletions pkg/sliceutil/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,37 @@ func TestStats(t *testing.T) {
{
name: "Two elements",
data: []int{29, 13},
want: &DescStats[int]{Count: 2, Entropy: -33.3443, ExKurtosis: 0, Max: 29, MaxID: 0, Mean: 21, MeanDev: 0, Median: 21, Min: 13, MinID: 1, Mode: 29, ModeFreq: 1, Range: 16, Skewness: 0, StdDev: 11.3137, Sum: 42, Variance: 128},
want: &DescStats[int]{Count: 2, Entropy: 0.6187, ExKurtosis: 0, Max: 29, MaxID: 0, Mean: 21, MeanDev: 0, Median: 21, Min: 13, MinID: 1, Mode: 29, ModeFreq: 1, Range: 16, Skewness: 0, StdDev: 11.3137, Sum: 42, Variance: 128},
wantErr: false,
},
{
name: "Three elements",
data: []int{13, 37, 29},
want: &DescStats[int]{Count: 3, Entropy: -231.2555, ExKurtosis: 0, Max: 37, MaxID: 1, Mean: 26.3333, MeanDev: 1.1842e-15, Median: 29, Min: 13, MinID: 0, Mode: 13, ModeFreq: 1, Range: 24, Skewness: -0.9352, StdDev: 12.2202, Sum: 79, Variance: 149.3333},
want: &DescStats[int]{Count: 3, Entropy: 1.0200, ExKurtosis: 0, Max: 37, MaxID: 1, Mean: 26.3333, MeanDev: 1.1842e-15, Median: 29, Min: 13, MinID: 0, Mode: 13, ModeFreq: 1, Range: 24, Skewness: -0.9352, StdDev: 12.2202, Sum: 79, Variance: 149.3333},
wantErr: false,
},
{
name: "Four elements",
data: []int{53, 13, 37, 29},
want: &DescStats[int]{Count: 4, Entropy: -264.5998, ExKurtosis: 0.3905, Max: 53, MaxID: 0, Mean: 33, MeanDev: 0, Median: 33, Min: 13, MinID: 1, Mode: 53, ModeFreq: 1, Range: 40, Skewness: 0, StdDev: 16.6533, Sum: 132, Variance: 277.3333},
want: &DescStats[int]{Count: 4, Entropy: 1.2841, ExKurtosis: 0.3905, Max: 53, MaxID: 0, Mean: 33, MeanDev: 0, Median: 33, Min: 13, MinID: 1, Mode: 53, ModeFreq: 1, Range: 40, Skewness: 0, StdDev: 16.6533, Sum: 132, Variance: 277.3333},
wantErr: false,
},
{
name: "Five elements",
data: []int{53, 13, 79, 37, 29},
want: &DescStats[int]{Count: 5, Entropy: -609.7862, ExKurtosis: 0.1751, Max: 79, MaxID: 2, Mean: 42.2, MeanDev: -2.8421e-15, Median: 37, Min: 13, MinID: 1, Mode: 53, ModeFreq: 1, Range: 66, Skewness: 0.6242, StdDev: 25.1236, Sum: 211, Variance: 631.2},
want: &DescStats[int]{Count: 5, Entropy: 1.4645, ExKurtosis: 0.1751, Max: 79, MaxID: 2, Mean: 42.2, MeanDev: -2.8421e-15, Median: 37, Min: 13, MinID: 1, Mode: 53, ModeFreq: 1, Range: 66, Skewness: 0.6242, StdDev: 25.1236, Sum: 211, Variance: 631.2},
wantErr: false,
},
{
name: "Six elements",
data: []int{53, 83, 13, 79, 37, 29},
want: &DescStats[int]{Count: 6, Entropy: -976.5500, ExKurtosis: -1.6680, Max: 83, MaxID: 1, Mean: 49, MeanDev: 0, Median: 45, Min: 13, MinID: 2, Mode: 53, ModeFreq: 1, Range: 70, Skewness: 0.1368, StdDev: 27.9714, Sum: 294, Variance: 782.4},
want: &DescStats[int]{Count: 6, Entropy: 1.6462, ExKurtosis: -1.6680, Max: 83, MaxID: 1, Mean: 49, MeanDev: 0, Median: 45, Min: 13, MinID: 2, Mode: 53, ModeFreq: 1, Range: 70, Skewness: 0.1368, StdDev: 27.9714, Sum: 294, Variance: 782.4},
wantErr: false,
},
{
name: "General case",
data: []int{53, 83, 13, 79, 13, 37, 83, 29, 37, 13, 83, 83},
want: &DescStats[int]{Count: 12, Entropy: -2277.1339, ExKurtosis: -1.9100, Max: 83, MaxID: 1, Mean: 50.5, MeanDev: 0, Median: 45, Min: 13, MinID: 2, Mode: 83, ModeFreq: 4, Range: 70, Skewness: -0.0494, StdDev: 30.2850, Sum: 606, Variance: 917.1818},
want: &DescStats[int]{Count: 12, Entropy: 2.3019, ExKurtosis: -1.9100, Max: 83, MaxID: 1, Mean: 50.5, MeanDev: 0, Median: 45, Min: 13, MinID: 2, Mode: 83, ModeFreq: 4, Range: 70, Skewness: -0.0494, StdDev: 30.2850, Sum: 606, Variance: 917.1818},
wantErr: false,
},
}
Expand Down

0 comments on commit 41bc493

Please sign in to comment.