mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: updateimport () and []array
This commit is contained in:
@@ -2,21 +2,21 @@ module stats
|
||||
|
||||
import math
|
||||
|
||||
// TODO: Implement all of them with generics
|
||||
// TODO: Implement all of them with generics
|
||||
|
||||
// This module defines the following statistical operations on f64 array
|
||||
// This module defines the following statistical operations on f64 array
|
||||
// ---------------------------
|
||||
// | Summary of Functions |
|
||||
// ---------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// freq - Frequency
|
||||
// mean - Mean
|
||||
// mean - Mean
|
||||
// geometric_mean - Geometric Mean
|
||||
// harmonic_mean - Harmonic Mean
|
||||
// median - Median
|
||||
// mode - Mode
|
||||
// rms - Root Mean Square
|
||||
// population_variance - Population Variance
|
||||
// population_variance - Population Variance
|
||||
// sample_variance - Sample Variance
|
||||
// population_stddev - Population Standard Deviation
|
||||
// sample_stddev - Sample Standard Deviation
|
||||
@@ -29,7 +29,7 @@ import math
|
||||
|
||||
// Measure of Occurance
|
||||
// Frequency of a given number
|
||||
// Based on
|
||||
// Based on
|
||||
// https://www.mathsisfun.com/data/frequency-distribution.html
|
||||
pub fn freq(arr []f64, val f64) int {
|
||||
if arr.len == 0 {
|
||||
@@ -46,7 +46,7 @@ pub fn freq(arr []f64, val f64) int {
|
||||
|
||||
// Measure of Central Tendancy
|
||||
// Mean of the given input array
|
||||
// Based on
|
||||
// Based on
|
||||
// https://www.mathsisfun.com/data/central-measures.html
|
||||
pub fn mean(arr []f64) f64 {
|
||||
if arr.len == 0 {
|
||||
@@ -61,7 +61,7 @@ pub fn mean(arr []f64) f64 {
|
||||
|
||||
// Measure of Central Tendancy
|
||||
// Geometric Mean of the given input array
|
||||
// Based on
|
||||
// Based on
|
||||
// https://www.mathsisfun.com/numbers/geometric-mean.html
|
||||
pub fn geometric_mean(arr []f64) f64 {
|
||||
if arr.len == 0 {
|
||||
@@ -76,7 +76,7 @@ pub fn geometric_mean(arr []f64) f64 {
|
||||
|
||||
// Measure of Central Tendancy
|
||||
// Harmonic Mean of the given input array
|
||||
// Based on
|
||||
// Based on
|
||||
// https://www.mathsisfun.com/numbers/harmonic-mean.html
|
||||
pub fn harmonic_mean(arr []f64) f64 {
|
||||
if arr.len == 0 {
|
||||
@@ -91,7 +91,7 @@ pub fn harmonic_mean(arr []f64) f64 {
|
||||
|
||||
// Measure of Central Tendancy
|
||||
// Median of the given input array ( input array is assumed to be sorted )
|
||||
// Based on
|
||||
// Based on
|
||||
// https://www.mathsisfun.com/data/central-measures.html
|
||||
pub fn median(arr []f64) f64 {
|
||||
if arr.len == 0 {
|
||||
@@ -108,13 +108,13 @@ pub fn median(arr []f64) f64 {
|
||||
|
||||
// Measure of Central Tendancy
|
||||
// Mode of the given input array
|
||||
// Based on
|
||||
// Based on
|
||||
// https://www.mathsisfun.com/data/central-measures.html
|
||||
pub fn mode(arr []f64) f64 {
|
||||
if arr.len == 0 {
|
||||
return f64(0)
|
||||
}
|
||||
mut freqs := []int
|
||||
mut freqs := []int{}
|
||||
for v in arr {
|
||||
freqs<<freq(arr,v)
|
||||
}
|
||||
@@ -128,7 +128,7 @@ pub fn mode(arr []f64) f64 {
|
||||
}
|
||||
|
||||
// Root Mean Square of the given input array
|
||||
// Based on
|
||||
// Based on
|
||||
// https://en.wikipedia.org/wiki/Root_mean_square
|
||||
pub fn rms(arr []f64) f64 {
|
||||
if arr.len == 0 {
|
||||
@@ -143,7 +143,7 @@ pub fn rms(arr []f64) f64 {
|
||||
|
||||
// Measure of Dispersion / Spread
|
||||
// Population Variance of the given input array
|
||||
// Based on
|
||||
// Based on
|
||||
// https://www.mathsisfun.com/data/standard-deviation.html
|
||||
pub fn population_variance(arr []f64) f64 {
|
||||
if arr.len == 0 {
|
||||
@@ -159,7 +159,7 @@ pub fn population_variance(arr []f64) f64 {
|
||||
|
||||
// Measure of Dispersion / Spread
|
||||
// Sample Variance of the given input array
|
||||
// Based on
|
||||
// Based on
|
||||
// https://www.mathsisfun.com/data/standard-deviation.html
|
||||
pub fn sample_variance(arr []f64) f64 {
|
||||
if arr.len == 0 {
|
||||
@@ -175,7 +175,7 @@ pub fn sample_variance(arr []f64) f64 {
|
||||
|
||||
// Measure of Dispersion / Spread
|
||||
// Population Standard Deviation of the given input array
|
||||
// Based on
|
||||
// Based on
|
||||
// https://www.mathsisfun.com/data/standard-deviation.html
|
||||
pub fn population_stddev(arr []f64) f64 {
|
||||
if arr.len == 0 {
|
||||
@@ -186,7 +186,7 @@ pub fn population_stddev(arr []f64) f64 {
|
||||
|
||||
// Measure of Dispersion / Spread
|
||||
// Sample Standard Deviation of the given input array
|
||||
// Based on
|
||||
// Based on
|
||||
// https://www.mathsisfun.com/data/standard-deviation.html
|
||||
pub fn sample_stddev(arr []f64) f64 {
|
||||
if arr.len == 0 {
|
||||
@@ -197,7 +197,7 @@ pub fn sample_stddev(arr []f64) f64 {
|
||||
|
||||
// Measure of Dispersion / Spread
|
||||
// Mean Absolute Deviation of the given input array
|
||||
// Based on
|
||||
// Based on
|
||||
// https://en.wikipedia.org/wiki/Average_absolute_deviation
|
||||
pub fn mean_absdev(arr []f64) f64 {
|
||||
if arr.len == 0 {
|
||||
@@ -241,7 +241,7 @@ pub fn max(arr []f64) f64 {
|
||||
|
||||
// Measure of Dispersion / Spread
|
||||
// Range ( Maximum - Minimum ) of the given input array
|
||||
// Based on
|
||||
// Based on
|
||||
// https://www.mathsisfun.com/data/range.html
|
||||
pub fn range(arr []f64) f64 {
|
||||
if arr.len == 0 {
|
||||
|
||||
Reference in New Issue
Block a user