1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.hipparchus.stat.descriptive.vector;
23
24 import java.io.Serializable;
25 import java.util.Arrays;
26
27 import org.hipparchus.exception.LocalizedCoreFormats;
28 import org.hipparchus.exception.MathIllegalArgumentException;
29 import org.hipparchus.stat.descriptive.StorelessMultivariateStatistic;
30 import org.hipparchus.stat.descriptive.StorelessUnivariateStatistic;
31 import org.hipparchus.util.MathUtils;
32
33
34
35
36
37 public class VectorialStorelessStatistic
38 implements StorelessMultivariateStatistic, Serializable {
39
40
41 private static final long serialVersionUID = 20160413L;
42
43
44 private final StorelessUnivariateStatistic[] stats;
45
46
47
48
49
50
51
52
53
54
55 public VectorialStorelessStatistic(int dimension,
56 StorelessUnivariateStatistic univariateStatistic) {
57 if (dimension < 1) {
58 throw new MathIllegalArgumentException(LocalizedCoreFormats.NUMBER_TOO_SMALL,
59 dimension, 1);
60 }
61 stats = new StorelessUnivariateStatistic[dimension];
62 for (int i = 0; i < dimension; i++) {
63 stats[i] = univariateStatistic.copy();
64 }
65 }
66
67
68 @Override
69 public void increment(double[] d) {
70 MathUtils.checkDimension(d.length, stats.length);
71 for (int i = 0; i < stats.length; i++) {
72 stats[i].increment(d[i]);
73 }
74 }
75
76
77 @Override
78 public double[] getResult() {
79 double[] result = new double[stats.length];
80 for (int i = 0; i < result.length; ++i) {
81 result[i] = stats[i].getResult();
82 }
83 return result;
84 }
85
86
87 @Override
88 public long getN() {
89 return stats[0].getN();
90 }
91
92
93 @Override
94 public void clear() {
95 for (StorelessUnivariateStatistic stat : stats) {
96 stat.clear();
97 }
98 }
99
100
101 @Override
102 public int getDimension() {
103 return stats.length;
104 }
105
106
107 @Override
108 public int hashCode() {
109 final int prime = 31;
110 int result = 1;
111 result = prime * result + Arrays.hashCode(stats);
112 return result;
113 }
114
115
116 @Override
117 public boolean equals(Object obj) {
118 if (this == obj) {
119 return true;
120 }
121 if (!(obj instanceof VectorialStorelessStatistic)) {
122 return false;
123 }
124 VectorialStorelessStatistic other = (VectorialStorelessStatistic) obj;
125 if (!Arrays.equals(stats, other.stats)) {
126 return false;
127 }
128 return true;
129 }
130
131 }