Skip to content

Latest commit

 

History

History
234 lines (191 loc) · 5.89 KB

list_mean.md

File metadata and controls

234 lines (191 loc) · 5.89 KB

Math on lists - mean

defined in file

banded/list.scad
|
+--> banded/list_mean.scad

<-- file overview
<-- table of contents

Contents

Calculating mean ^

  • Calculates mean of a list of numeric values
  • Optional with weight list
  • weight list can to get normalised,
    • option normalize
      • true - (standard) sum of all values of weight list will be scaled to 1

List of mean functions ^

mean_arithmetic, mean ^

Calculates the arithmetic mean (or mean or average) of a list.
=> Wikipedia - Arithmetic mean

Arguments:

mean_arithmetic (list, weight, normalize)

There is a shortcut to function mean_arithmetic():

  • mean (list, weight, normalize)

Example:

l = [3, 5, 8, 4];
echo ( mean_arithmetic (l) ); // echo 5

mean_geometric ^

Calculates the geometic mean of a list.
=> Wikipedia - Geometric mean

Arguments:

mean_geometric (list, weight, normalize)

Example:

l = [3, 5, 8, 4];
echo ( mean_geometric (l) ); // echo 4.68069

mean_harmonic ^

Calculates the harmonic mean of a list.
=> Wikipedia - Harmonic mean

Arguments:

mean_harmonic (list, weight, normalize)

Example:

l = [3, 5, 8, 4];
echo ( mean_harmonic (l) ); // echo 4.40367

root_mean_square ^

Calculates the root mean square of a list.
=> Wikipedia - Root mean square

Arguments:

root_mean_square (list, weight, normalize)

Example:

l = [3, 5, 8, 4];
echo ( root_mean_square (l) ); // echo 5.33854

mean_cubic ^

Calculates the cubic mean of a list.
=> Wikipedia - Cubic mean

Arguments:

mean_cubic (list, weight, normalize)

Example:

l = [3, 5, 8, 4];
echo ( mean_cubic (l) ); // echo 5.66705

mean_generalized ^

Calculates the generalized mean (or power mean, or Hölder mean) of a list.
=> Wikipedia - Generalized mean

Arguments:

mean_generalized (p, list, weight, normalize)
  • p
    • a number, set the type of the calculated mean, e.g.
      • -1 - harmonic mean
      • 0 - arithmetic mean
      • 1 - geometic mean
      • 2 - root mean square
      • 3 - cubic mean

Example:

l = [3, 5, 8, 4];
echo ( mean_generalized (4, l) ); // echo 5.9632

Other mean functions ^

median ^

Calculates the median of a list.
=> Wikipedia - Median

Arguments:

median (list)

mid_range ^

Calculates the mid-range or mid-extreme of a list.
=> Wikipedia - Mid-range

Arguments:

mid_range (list)

truncate_outlier ^

Removes outliers from a data list.

  • Sort a list and remove a given ratio of elements from the ends. This is useful for mean functions to truncate outliers from a data list.
  • Leaves always at minimum 1 element if odd size of list or at minimum 2 element if even size of list.

Arguments:

truncate_outlier (list, ratio)
  • ratio
    • standard ratio = 0.5, = removes less or equal 50% from the ends
      (25% from begin and 25% from end)

Sample:

include <banded.scad>

data  = [1,9,4,2,15];
trunc = truncate_outlier (data, 0.5);
mean  = mean_arithmetic  (trunc);

echo (trunc); // [2,4,6]
echo (mean);  // 5

truncate ^

Removes same elements from the ends like truncate_outlier() without previous sorting the list.

Arguments:

truncate (list, ratio)

variance ^

Calculates the variance of the mean from a list.
Variance is the expected value of the squared deviation from the mean of a random variable. The standard deviation is obtained as the square root of the variance. Variance is a measure of dispersion, meaning it is a measure of how far a set of numbers is spread out from their average value.
=> Wikipedia - Variance

Arguments:

variance (list, biased, mean)
  • biased
    • false - default, calculates the mean variance
    • true - calculates n / (n-1) with the mean variance, gives an unbiased estimator of the variance
    • undef - summarize all variances
  • mean
    • optional
    • If mean was already calculated (e.g. with function mean()), you can set the value here. Then the function must not calculate this value again.