How to use the mean function from mathjs

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

129
130
131
132
133
134
135
136
137
138
    ) &&
    benchmarkMetricsCollection[key]
        .length > 0
) {
    const mean = math.round(
        math.mean(
            benchmarkMetricsCollection[
                key
            ]
        ),
fork icon70
star icon24
watch icon16

+ 454 other calls in file

34
35
36
37
38
39
40
41
42
43
    function f(x) { return m.sum(x); }
    return _.map(a, f);
},
// return mean of vector
mean: function(v) {
    return m.mean(v);
},
// composition of mean•sumrow, i.e. mean of column vector of chunk
msr: function(a) {
    return _.compose(fn.mean, fn.sumrow)(a);
fork icon7
star icon16
watch icon0

91
92
93
94
95
96
97
98
99
100

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

164
165
166
167
168
169
170
171
172
173
keys.compilers[results[h].compiler['short-name']] = true
keys.platforms[results[h].platform['short-name']] = true
keys.environments[results[h].environment['short-name']] = true
keys['input-sizes'][results[h].experiment['input-size']] = true

results[h]['mean-time'] = math.mean(results[h].times)
results[h]['std-time'] = math.std(results[h].times)
results[h]['max-time'] = math.max(results[h].times)
results[h]['min-time'] = math.min(results[h].times)
a.push(results[h])
fork icon6
star icon4
watch icon7

+ 5 other calls in file

13
14
15
16
17
18
19
20
21
22
  //console.log(x_target_norm)
  //Calculate MSE between song and target
  e = math.subtract(x_song_norm,x_target_norm);
  //console.log(e)
  se = math.dotPow(e, 2);
  mse = math.mean(se);
  return mse;
}

return {
fork icon0
star icon4
watch icon3

62
63
64
65
66
67
68
69
70
71
// stats
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);
fork icon0
star icon3
watch icon0

+ 6 other calls in file

168
169
170
171
172
173
174
175
176
177
}

let prediction = this.predictCandle() * this.scale;
let currentPrice = candle.close;
log.debug('Price = ' + currentPrice + ', Prediction = ' + prediction);
let meanp = math.mean(prediction, currentPrice);
let meanAlpha = (meanp - currentPrice) / currentPrice * 100;


// sell only if the price is higher than the buying price or if the price drops below the threshold
fork icon140
star icon2
watch icon1

553
554
555
556
557
558
559
560
561
562
get_mean_raw_value(classnumber) {
  let mean_value = 0;
  Object.entries(this.values.xai).forEach(([key, value]) => {
    if (value.hasOwnProperty("target_idx")) {
      if (parseInt(value.target_idx) === classnumber) {
        mean_value = math.mean(csv_to_list(value.raw_string));
      }
    }
  });
  return mean_value;
fork icon0
star icon0
watch icon0

+ 5 other calls in file

68
69
70
71
72
73
74
75
76
77
let randUniforms = [];
responses.forEach((response) => {
  randUniforms.push(response.data);
});

let average = math.mean(randUniforms);
let stddev = math.std(randUniforms);

var result = {results: []};
randUniforms.forEach((randUniform) => {
fork icon0
star icon0
watch icon0

87
88
89
90
91
92
93
94
95
96
                Error(['Unrecognized representation label of polyhedron', toString(i)]);
        }
    }


    let V = S.concat(V);
    let x0 = math.mean(V, 1);
    [U.lcon[[math.range(1, 4, true)]]] = vert2lcon(V, math.reshape[[TOL]]);
    U.vert = qlcon2vert(x0, math.reshape[[U.lcon]], math.reshape[[TOL]]);
}
fork icon0
star icon0
watch icon0

3
4
5
6
7
8
9
10
11
12
// máximo (maior valor)
console.log('máximo:', math.max([2, 1, 3]));
// 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]));
fork icon0
star icon0
watch icon0

+ 2 other calls in file

72
73
74
75
76
77
78
79
80
81
    "signature_name": "serving_default", 
    "instances": records
}).then(response => {
    // return correct results
    let predictions = response.data.predictions;
    predictions = math.mean(predictions, 0);
    let filteredSignals = [];

    // filter results based on passed frequency
    if (filter) {
fork icon0
star icon0
watch icon0

8
9
10
11
12
13
14
15
16
17
18
19
20


function winsor(percentile, arr) {
    let rv = arr.slice();
    const len = rv.length;


    const mean = m.mean(rv);
    const std = m.std(rv);


    rv = rv.map(v => (v - mean) / std);

fork icon0
star icon0
watch icon0

115
116
117
118
119
120
121
122
123
124

		return Sigmoid(v)
	})]
}

avgTendency = mathjs.mean(avgTendency, amountOfLessLost / amountOfMoreLost)
console.log(`Current tokens: "${tokens}"; training for "${validToken}"; it ${iteration}; loss ${loss}; tendency ${amountOfLessLost / amountOfMoreLost}; avgTendency ${avgTendency}`)

iteration += 1
lastLoss = loss
fork icon0
star icon0
watch icon0

537
538
539
540
541
542
543
544
545
546
if (!result.playerCounts) {
  return result;
}

// Get the mean of means for all playsCounts
const expectedMean = mean(
  _.transform(
    result.playerCounts,
    (means, num, playerCount) => {
      means.push(Array(num).fill(playerCountMeans[playerCount]));
fork icon0
star icon0
watch icon0

141
142
143
144
145
146
147
148
149
150
  s.mean = math.mean(
    s.lookback[0].close,
    s.lookback[1].close,
    s.lookback[2].close
  )
  s.meanp = math.mean(s.prediction, oldmean)
  oldmean = s.prediction
}
// NORMAL onPeriod STUFF here
global.meanp = s.meanp
fork icon0
star icon0
watch icon1

+ 3 other calls in file