-
Notifications
You must be signed in to change notification settings - Fork 0
/
Statistics.cs
76 lines (58 loc) · 1.71 KB
/
Statistics.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
namespace MathHelper {
public class Statistics {
public Statistics (double[] data) {
Data = data;
}
public double[] Data;
public double Sum {
get {
double sum = 0.0;
foreach (var item in Data) {
sum += item;
}
return sum;
}
}
public double Mean {
get {
return Sum / Data.Length;
}
}
public double StandardDeviation {
get {
return Math.Sqrt(Variance);
}
}
public double Variance {
get {
var mean = Mean;
double a = 0;
foreach (var item in Data) {
a += Math.Pow(item - mean, 2);
}
return a / Data.Length;
}
}
public double StandardizedScore (double value) {
return (value - Mean) / StandardDeviation;
}
public string PrintAll {
get {
var a = "";
a += $"Data: {String.Join(", ",Data)}\n";
a += new string('-',50) + "\n";
a += $"Sum: {Sum}\n";
a += $"Mean: {Mean}\n";
a += $"Standard deviation: {StandardDeviation}\n";
a += $"Variance: {Variance}\n";
a += $"Standardized score for: \n";
for (int i = 0; i < Data.Length; i++) {
a += $"\t-{Data[i]}: {StandardizedScore(Data[i])}\n";
}
return a;
}
}
}
}