How to use the median function from mathjs

Find comprehensive JavaScript mathjs.median code examples handpicked from public code repositorys.

153
154
155
156
157
158
159
160
161
162
        ]
    ),
    3
);
const median = math.round(
    math.median(
        benchmarkMetricsCollection[
            key
        ]
    ),
fork icon70
star icon24
watch icon16

+ 454 other calls in file

92
93
94
95
96
97
98
99
100
101
  return {
    codeSize: rs[0].codeSize,
    memorySize: rs[0].memorySize,
    stddev: math.std(values),
    mean: math.mean(values),
    median: math.median(values),
    '95%-tile': stats.percentile(95),
    '99%-tile': stats.percentile(99)
  };
});
fork icon6
star icon32
watch icon3

+ 11 other calls in file

63
64
65
66
67
68
69
70
71
72
math.max(numbers);
math.min(numbers);
math.quantileSeq([1, 2, 3, 4, 5], .5) // value at quantile

math.mean(numbers);
math.median(numbers);
math.mode(numbers)
math.std(numbers);
math.variance(numbers);
math.sum(numbers);
fork icon0
star icon3
watch icon0

+ 6 other calls in file

4
5
6
7
8
9
10
11
12
13
14
15
module.exports = { ellipseMad, dbscan }


// points should be in format, f.ex: [[1,2],[3,4],[5,6],..]
function ellipseMad (points, _sigma) {
  const sigma = _sigma || 3.5
  const medianPoint = [median(points.map(p => p[0])), median(points.map(p => p[1]))]


  // remove outliers with Median Absolute Deviation (MAD)
  const madValue = [mad(points.map(p => p[0])), mad(points.map(p => p[1]))]

fork icon0
star icon3
watch icon0

5
6
7
8
9
10
11
12
13
14
// soma (retorna 6)
console.log('soma:', math.sum([2, 1, 3]));
// média (retorna 2)
console.log('média:', math.mean([2, 1, 3]));
// mediana (número entre o maior e o menor -> 2)
console.log('mediana:', math.median([2, 1, 3]));
// produto (multiplicação)
console.log('produto:', math.prod([2, 1, 3]));
// quadrado (eleva cada elemento)
console.log('quadrado:', math.square([2, 1, 3]));
fork icon0
star icon0
watch icon0

+ 2 other calls in file

468
469
470
471
472
473
474
475
476
477
// Put old outliers back in so we don't mess with the STD too much
const scoresAndOutliers = combineScores(result.scores, result.outlierScores);

const explodedScores = getExplodedScores(scoresAndOutliers);

const medianVal = median(explodedScores);
const madCutoff = 8;

const leftHalf = _.filter(explodedScores, (score) => score <= medianVal);
const rightHalf = _.filter(explodedScores, (score) => score >= medianVal);
fork icon0
star icon0
watch icon0