nlptoolkit-classification 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (178) hide show
  1. package/dist/Attribute/Attribute.js +6 -16
  2. package/dist/Attribute/Attribute.js.map +1 -1
  3. package/dist/Attribute/AttributeType.js +22 -32
  4. package/dist/Attribute/AttributeType.js.map +1 -1
  5. package/dist/Attribute/BinaryAttribute.js +14 -24
  6. package/dist/Attribute/BinaryAttribute.js.map +1 -1
  7. package/dist/Attribute/ContinuousAttribute.js +46 -55
  8. package/dist/Attribute/ContinuousAttribute.js.map +1 -1
  9. package/dist/Attribute/DiscreteAttribute.js +38 -48
  10. package/dist/Attribute/DiscreteAttribute.js.map +1 -1
  11. package/dist/Attribute/DiscreteIndexedAttribute.js +47 -55
  12. package/dist/Attribute/DiscreteIndexedAttribute.js.map +1 -1
  13. package/dist/DataSet/DataDefinition.js +115 -123
  14. package/dist/DataSet/DataDefinition.js.map +1 -1
  15. package/dist/DataSet/DataSet.js +268 -245
  16. package/dist/DataSet/DataSet.js.map +1 -1
  17. package/dist/DistanceMetric/DistanceMetric.js +2 -12
  18. package/dist/DistanceMetric/EuclidianDistance.js +27 -37
  19. package/dist/DistanceMetric/EuclidianDistance.js.map +1 -1
  20. package/dist/DistanceMetric/MahalanobisDistance.js +27 -36
  21. package/dist/DistanceMetric/MahalanobisDistance.js.map +1 -1
  22. package/dist/Experiment/BootstrapRun.js +31 -40
  23. package/dist/Experiment/BootstrapRun.js.map +1 -1
  24. package/dist/Experiment/Experiment.js +46 -53
  25. package/dist/Experiment/Experiment.js.map +1 -1
  26. package/dist/Experiment/KFoldRun.js +45 -54
  27. package/dist/Experiment/KFoldRun.js.map +1 -1
  28. package/dist/Experiment/KFoldRunSeparateTest.js +48 -58
  29. package/dist/Experiment/KFoldRunSeparateTest.js.map +1 -1
  30. package/dist/Experiment/MultipleRun.js +2 -12
  31. package/dist/Experiment/MxKFoldRun.js +31 -40
  32. package/dist/Experiment/MxKFoldRun.js.map +1 -1
  33. package/dist/Experiment/MxKFoldRunSeparateTest.js +35 -44
  34. package/dist/Experiment/MxKFoldRunSeparateTest.js.map +1 -1
  35. package/dist/Experiment/SingleRun.js +2 -12
  36. package/dist/Experiment/SingleRunWithK.js +39 -48
  37. package/dist/Experiment/SingleRunWithK.js.map +1 -1
  38. package/dist/Experiment/StratifiedKFoldRun.js +26 -36
  39. package/dist/Experiment/StratifiedKFoldRun.js.map +1 -1
  40. package/dist/Experiment/StratifiedKFoldRunSeparateTest.js +30 -40
  41. package/dist/Experiment/StratifiedKFoldRunSeparateTest.js.map +1 -1
  42. package/dist/Experiment/StratifiedMxKFoldRun.js +29 -39
  43. package/dist/Experiment/StratifiedMxKFoldRun.js.map +1 -1
  44. package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js +34 -43
  45. package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js.map +1 -1
  46. package/dist/Experiment/StratifiedSingleRunWithK.js +27 -36
  47. package/dist/Experiment/StratifiedSingleRunWithK.js.map +1 -1
  48. package/dist/FeatureSelection/BackwardSelection.js +26 -36
  49. package/dist/FeatureSelection/BackwardSelection.js.map +1 -1
  50. package/dist/FeatureSelection/FeatureSubSet.js +72 -82
  51. package/dist/FeatureSelection/FeatureSubSet.js.map +1 -1
  52. package/dist/FeatureSelection/FloatingSelection.js +25 -35
  53. package/dist/FeatureSelection/FloatingSelection.js.map +1 -1
  54. package/dist/FeatureSelection/ForwardSelection.js +25 -35
  55. package/dist/FeatureSelection/ForwardSelection.js.map +1 -1
  56. package/dist/FeatureSelection/SubSetSelection.js +69 -78
  57. package/dist/FeatureSelection/SubSetSelection.js.map +1 -1
  58. package/dist/Filter/DiscreteToContinuous.js +50 -60
  59. package/dist/Filter/DiscreteToContinuous.js.map +1 -1
  60. package/dist/Filter/DiscreteToIndexed.js +40 -50
  61. package/dist/Filter/DiscreteToIndexed.js.map +1 -1
  62. package/dist/Filter/FeatureFilter.js +23 -32
  63. package/dist/Filter/FeatureFilter.js.map +1 -1
  64. package/dist/Filter/LaryFilter.js +46 -55
  65. package/dist/Filter/LaryFilter.js.map +1 -1
  66. package/dist/Filter/LaryToBinary.js +48 -58
  67. package/dist/Filter/LaryToBinary.js.map +1 -1
  68. package/dist/Filter/Normalize.js +33 -41
  69. package/dist/Filter/Normalize.js.map +1 -1
  70. package/dist/Filter/Pca.js +86 -96
  71. package/dist/Filter/Pca.js.map +1 -1
  72. package/dist/Filter/TrainedFeatureFilter.js +14 -24
  73. package/dist/Filter/TrainedFeatureFilter.js.map +1 -1
  74. package/dist/Instance/CompositeInstance.js +46 -56
  75. package/dist/Instance/CompositeInstance.js.map +1 -1
  76. package/dist/Instance/Instance.js +145 -154
  77. package/dist/Instance/Instance.js.map +1 -1
  78. package/dist/InstanceList/InstanceList.js +466 -443
  79. package/dist/InstanceList/InstanceList.js.map +1 -1
  80. package/dist/InstanceList/InstanceListOfSameClass.js +23 -32
  81. package/dist/InstanceList/InstanceListOfSameClass.js.map +1 -1
  82. package/dist/InstanceList/Partition.js +167 -177
  83. package/dist/InstanceList/Partition.js.map +1 -1
  84. package/dist/Model/DecisionTree/DecisionCondition.js +71 -80
  85. package/dist/Model/DecisionTree/DecisionCondition.js.map +1 -1
  86. package/dist/Model/DecisionTree/DecisionNode.js +302 -311
  87. package/dist/Model/DecisionTree/DecisionNode.js.map +1 -1
  88. package/dist/Model/DecisionTree/DecisionStump.js +22 -32
  89. package/dist/Model/DecisionTree/DecisionStump.js.map +1 -1
  90. package/dist/Model/DecisionTree/DecisionTree.js +89 -98
  91. package/dist/Model/DecisionTree/DecisionTree.js.map +1 -1
  92. package/dist/Model/DummyModel.js +64 -73
  93. package/dist/Model/DummyModel.js.map +1 -1
  94. package/dist/Model/Ensemble/BaggingModel.js +34 -44
  95. package/dist/Model/Ensemble/BaggingModel.js.map +1 -1
  96. package/dist/Model/Ensemble/RandomForestModel.js +31 -41
  97. package/dist/Model/Ensemble/RandomForestModel.js.map +1 -1
  98. package/dist/Model/Ensemble/TreeEnsembleModel.js +55 -64
  99. package/dist/Model/Ensemble/TreeEnsembleModel.js.map +1 -1
  100. package/dist/Model/Model.js +130 -140
  101. package/dist/Model/Model.js.map +1 -1
  102. package/dist/Model/NeuralNetwork/DeepNetworkModel.js +162 -169
  103. package/dist/Model/NeuralNetwork/DeepNetworkModel.js.map +1 -1
  104. package/dist/Model/NeuralNetwork/LinearPerceptronModel.js +69 -78
  105. package/dist/Model/NeuralNetwork/LinearPerceptronModel.js.map +1 -1
  106. package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.js +112 -120
  107. package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.js.map +1 -1
  108. package/dist/Model/NeuralNetwork/NeuralNetworkModel.js +197 -201
  109. package/dist/Model/NeuralNetwork/NeuralNetworkModel.js.map +1 -1
  110. package/dist/Model/NonParametric/KnnInstance.js +21 -29
  111. package/dist/Model/NonParametric/KnnInstance.js.map +1 -1
  112. package/dist/Model/NonParametric/KnnModel.js +101 -108
  113. package/dist/Model/NonParametric/KnnModel.js.map +1 -1
  114. package/dist/Model/Parametric/GaussianModel.js +82 -91
  115. package/dist/Model/Parametric/GaussianModel.js.map +1 -1
  116. package/dist/Model/Parametric/KMeansModel.js +59 -67
  117. package/dist/Model/Parametric/KMeansModel.js.map +1 -1
  118. package/dist/Model/Parametric/LdaModel.js +83 -91
  119. package/dist/Model/Parametric/LdaModel.js.map +1 -1
  120. package/dist/Model/Parametric/NaiveBayesModel.js +119 -132
  121. package/dist/Model/Parametric/NaiveBayesModel.js.map +1 -1
  122. package/dist/Model/Parametric/QdaModel.js +70 -79
  123. package/dist/Model/Parametric/QdaModel.js.map +1 -1
  124. package/dist/Model/RandomModel.js +85 -92
  125. package/dist/Model/RandomModel.js.map +1 -1
  126. package/dist/Model/ValidatedModel.js +21 -31
  127. package/dist/Model/ValidatedModel.js.map +1 -1
  128. package/dist/Parameter/ActivationFunction.js +9 -19
  129. package/dist/Parameter/ActivationFunction.js.map +1 -1
  130. package/dist/Parameter/BaggingParameter.js +24 -33
  131. package/dist/Parameter/BaggingParameter.js.map +1 -1
  132. package/dist/Parameter/C45Parameter.js +34 -42
  133. package/dist/Parameter/C45Parameter.js.map +1 -1
  134. package/dist/Parameter/DeepNetworkParameter.js +48 -56
  135. package/dist/Parameter/DeepNetworkParameter.js.map +1 -1
  136. package/dist/Parameter/KMeansParameter.js +29 -38
  137. package/dist/Parameter/KMeansParameter.js.map +1 -1
  138. package/dist/Parameter/KnnParameter.js +25 -34
  139. package/dist/Parameter/KnnParameter.js.map +1 -1
  140. package/dist/Parameter/LinearPerceptronParameter.js +56 -62
  141. package/dist/Parameter/LinearPerceptronParameter.js.map +1 -1
  142. package/dist/Parameter/MultiLayerPerceptronParameter.js +38 -46
  143. package/dist/Parameter/MultiLayerPerceptronParameter.js.map +1 -1
  144. package/dist/Parameter/Parameter.js +21 -30
  145. package/dist/Parameter/Parameter.js.map +1 -1
  146. package/dist/Parameter/RandomForestParameter.js +25 -34
  147. package/dist/Parameter/RandomForestParameter.js.map +1 -1
  148. package/dist/Performance/ClassificationPerformance.js +24 -33
  149. package/dist/Performance/ClassificationPerformance.js.map +1 -1
  150. package/dist/Performance/ConfusionMatrix.js +149 -158
  151. package/dist/Performance/ConfusionMatrix.js.map +1 -1
  152. package/dist/Performance/DetailedClassificationPerformance.js +23 -32
  153. package/dist/Performance/DetailedClassificationPerformance.js.map +1 -1
  154. package/dist/Performance/ExperimentPerformance.js +184 -161
  155. package/dist/Performance/ExperimentPerformance.js.map +1 -1
  156. package/dist/Performance/Performance.js +21 -30
  157. package/dist/Performance/Performance.js.map +1 -1
  158. package/dist/StatisticalTest/Combined5x2F.js +41 -51
  159. package/dist/StatisticalTest/Combined5x2F.js.map +1 -1
  160. package/dist/StatisticalTest/Combined5x2t.js +42 -52
  161. package/dist/StatisticalTest/Combined5x2t.js.map +1 -1
  162. package/dist/StatisticalTest/Paired5x2t.js +40 -50
  163. package/dist/StatisticalTest/Paired5x2t.js.map +1 -1
  164. package/dist/StatisticalTest/PairedTest.js +31 -41
  165. package/dist/StatisticalTest/PairedTest.js.map +1 -1
  166. package/dist/StatisticalTest/Pairedt.js +38 -48
  167. package/dist/StatisticalTest/Pairedt.js.map +1 -1
  168. package/dist/StatisticalTest/Sign.js +50 -60
  169. package/dist/StatisticalTest/Sign.js.map +1 -1
  170. package/dist/StatisticalTest/StatisticalTestResult.js +65 -73
  171. package/dist/StatisticalTest/StatisticalTestResult.js.map +1 -1
  172. package/dist/StatisticalTest/StatisticalTestResultType.js +11 -21
  173. package/dist/StatisticalTest/StatisticalTestResultType.js.map +1 -1
  174. package/dist/index.js +95 -101
  175. package/dist/index.js.map +1 -1
  176. package/package.json +7 -6
  177. package/tsconfig.json +4 -3
  178. package/source/tsconfig.json +0 -13
@@ -1,232 +1,301 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
5
7
  }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "../Instance/Instance", "../DataSet/DataDefinition", "fs", "../Attribute/BinaryAttribute", "../Attribute/DiscreteAttribute", "../Attribute/ContinuousAttribute", "../Attribute/AttributeType", "nlptoolkit-sampling/dist/Bootstrap", "../Instance/CompositeInstance", "../Model/Model", "../Attribute/DiscreteIndexedAttribute", "nlptoolkit-math/dist/DiscreteDistribution", "nlptoolkit-math/dist/Matrix"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.InstanceList = void 0;
13
- const Instance_1 = require("../Instance/Instance");
14
- const DataDefinition_1 = require("../DataSet/DataDefinition");
15
- const fs = require("fs");
16
- const BinaryAttribute_1 = require("../Attribute/BinaryAttribute");
17
- const DiscreteAttribute_1 = require("../Attribute/DiscreteAttribute");
18
- const ContinuousAttribute_1 = require("../Attribute/ContinuousAttribute");
19
- const AttributeType_1 = require("../Attribute/AttributeType");
20
- const Bootstrap_1 = require("nlptoolkit-sampling/dist/Bootstrap");
21
- const CompositeInstance_1 = require("../Instance/CompositeInstance");
22
- const Model_1 = require("../Model/Model");
23
- const DiscreteIndexedAttribute_1 = require("../Attribute/DiscreteIndexedAttribute");
24
- const DiscreteDistribution_1 = require("nlptoolkit-math/dist/DiscreteDistribution");
25
- const Matrix_1 = require("nlptoolkit-math/dist/Matrix");
26
- class InstanceList {
27
- /**
28
- * Constructor for an instance list with a given data definition, data file and a separator character. Each instance
29
- * must be stored in a separate line separated with the character separator. The last item must be the class label.
30
- * The function reads the file line by line and for each line; depending on the data definition, that is, type of
31
- * the attributes, adds discrete and continuous attributes to a new instance. For example, given the data set file
32
- * <p>
33
- * red;1;0.4;true
34
- * green;-1;0.8;true
35
- * blue;3;1.3;false
36
- * <p>
37
- * where the first attribute is a discrete attribute, second and third attributes are continuous attributes, the
38
- * fourth item is the class label.
39
- *
40
- * @param definition Data definition of the data set.
41
- * @param separator Separator character which separates the attribute values in the data file.
42
- * @param fileName Name of the data set file.
43
- */
44
- constructor(definition, separator, fileName) {
45
- this.list = new Array();
46
- if (definition != undefined) {
47
- if (definition instanceof DataDefinition_1.DataDefinition) {
48
- let data = fs.readFileSync(fileName, 'utf8');
49
- let lines = data.split("\n");
50
- for (let line of lines) {
51
- let attributeList = line.split(separator);
52
- if (attributeList.length == definition.attributeCount() + 1) {
53
- let current = new Instance_1.Instance(attributeList[attributeList.length - 1]);
54
- for (let i = 0; i < attributeList.length - 1; i++) {
55
- switch (definition.getAttributeType(i)) {
56
- case AttributeType_1.AttributeType.DISCRETE:
57
- current.addAttribute(new DiscreteAttribute_1.DiscreteAttribute(attributeList[i]));
58
- break;
59
- case AttributeType_1.AttributeType.DISCRETE_INDEXED:
60
- current.addAttribute(new DiscreteIndexedAttribute_1.DiscreteIndexedAttribute(attributeList[i], definition.featureValueIndex(i, attributeList[i]), definition.numberOfValues(i)));
61
- break;
62
- case AttributeType_1.AttributeType.BINARY:
63
- if (attributeList[i].toLowerCase() == "yes" || attributeList[i] == "1") {
64
- current.addAttribute(new BinaryAttribute_1.BinaryAttribute(true));
65
- }
66
- else {
67
- current.addAttribute(new BinaryAttribute_1.BinaryAttribute(false));
68
- }
69
- break;
70
- case AttributeType_1.AttributeType.CONTINUOUS:
71
- current.addAttribute(new ContinuousAttribute_1.ContinuousAttribute(Number.parseFloat(attributeList[i])));
72
- break;
73
- }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.InstanceList = void 0;
37
+ const Instance_1 = require("../Instance/Instance");
38
+ const DataDefinition_1 = require("../DataSet/DataDefinition");
39
+ const fs = __importStar(require("fs"));
40
+ const BinaryAttribute_1 = require("../Attribute/BinaryAttribute");
41
+ const DiscreteAttribute_1 = require("../Attribute/DiscreteAttribute");
42
+ const ContinuousAttribute_1 = require("../Attribute/ContinuousAttribute");
43
+ const AttributeType_1 = require("../Attribute/AttributeType");
44
+ const Bootstrap_1 = require("nlptoolkit-sampling/dist/Bootstrap");
45
+ const CompositeInstance_1 = require("../Instance/CompositeInstance");
46
+ const Model_1 = require("../Model/Model");
47
+ const DiscreteIndexedAttribute_1 = require("../Attribute/DiscreteIndexedAttribute");
48
+ const DiscreteDistribution_1 = require("nlptoolkit-math/dist/DiscreteDistribution");
49
+ const Matrix_1 = require("nlptoolkit-math/dist/Matrix");
50
+ class InstanceList {
51
+ list = new Array();
52
+ /**
53
+ * Constructor for an instance list with a given data definition, data file and a separator character. Each instance
54
+ * must be stored in a separate line separated with the character separator. The last item must be the class label.
55
+ * The function reads the file line by line and for each line; depending on the data definition, that is, type of
56
+ * the attributes, adds discrete and continuous attributes to a new instance. For example, given the data set file
57
+ * <p>
58
+ * red;1;0.4;true
59
+ * green;-1;0.8;true
60
+ * blue;3;1.3;false
61
+ * <p>
62
+ * where the first attribute is a discrete attribute, second and third attributes are continuous attributes, the
63
+ * fourth item is the class label.
64
+ *
65
+ * @param definition Data definition of the data set.
66
+ * @param separator Separator character which separates the attribute values in the data file.
67
+ * @param fileName Name of the data set file.
68
+ */
69
+ constructor(definition, separator, fileName) {
70
+ if (definition != undefined) {
71
+ if (definition instanceof DataDefinition_1.DataDefinition) {
72
+ let data = fs.readFileSync(fileName, 'utf8');
73
+ let lines = data.split("\n");
74
+ for (let line of lines) {
75
+ let attributeList = line.split(separator);
76
+ if (attributeList.length == definition.attributeCount() + 1) {
77
+ let current = new Instance_1.Instance(attributeList[attributeList.length - 1]);
78
+ for (let i = 0; i < attributeList.length - 1; i++) {
79
+ switch (definition.getAttributeType(i)) {
80
+ case AttributeType_1.AttributeType.DISCRETE:
81
+ current.addAttribute(new DiscreteAttribute_1.DiscreteAttribute(attributeList[i]));
82
+ break;
83
+ case AttributeType_1.AttributeType.DISCRETE_INDEXED:
84
+ current.addAttribute(new DiscreteIndexedAttribute_1.DiscreteIndexedAttribute(attributeList[i], definition.featureValueIndex(i, attributeList[i]), definition.numberOfValues(i)));
85
+ break;
86
+ case AttributeType_1.AttributeType.BINARY:
87
+ if (attributeList[i].toLowerCase() == "yes" || attributeList[i] == "1") {
88
+ current.addAttribute(new BinaryAttribute_1.BinaryAttribute(true));
89
+ }
90
+ else {
91
+ current.addAttribute(new BinaryAttribute_1.BinaryAttribute(false));
92
+ }
93
+ break;
94
+ case AttributeType_1.AttributeType.CONTINUOUS:
95
+ current.addAttribute(new ContinuousAttribute_1.ContinuousAttribute(Number.parseFloat(attributeList[i])));
96
+ break;
74
97
  }
75
- this.list.push(current);
76
98
  }
99
+ this.list.push(current);
77
100
  }
78
101
  }
79
- else {
80
- this.list = definition;
81
- }
102
+ }
103
+ else {
104
+ this.list = definition;
82
105
  }
83
106
  }
84
- /**
85
- * Adds instance to the instance list.
86
- *
87
- * @param instance Instance to be added.
88
- */
89
- add(instance) {
107
+ }
108
+ /**
109
+ * Adds instance to the instance list.
110
+ *
111
+ * @param instance Instance to be added.
112
+ */
113
+ add(instance) {
114
+ this.list.push(instance);
115
+ }
116
+ /**
117
+ * Adds a list of instances to the current instance list.
118
+ *
119
+ * @param instanceList List of instances to be added.
120
+ */
121
+ addAll(instanceList) {
122
+ for (let instance of instanceList) {
90
123
  this.list.push(instance);
91
124
  }
92
- /**
93
- * Adds a list of instances to the current instance list.
94
- *
95
- * @param instanceList List of instances to be added.
96
- */
97
- addAll(instanceList) {
98
- for (let instance of instanceList) {
99
- this.list.push(instance);
100
- }
125
+ }
126
+ /**
127
+ * Returns size of the instance list.
128
+ *
129
+ * @return Size of the instance list.
130
+ */
131
+ size() {
132
+ return this.list.length;
133
+ }
134
+ /**
135
+ * Accessor for a single instance with the given index.
136
+ *
137
+ * @param index Index of the instance.
138
+ * @return Instance with index 'index'.
139
+ */
140
+ get(index) {
141
+ return this.list[index];
142
+ }
143
+ /**
144
+ * Sorts instance list according to the attribute with index 'attributeIndex'.
145
+ *
146
+ * @param attributeIndex index of the attribute.
147
+ */
148
+ sort(attributeIndex) {
149
+ if (attributeIndex == undefined) {
150
+ this.list.sort((a, b) => (a.getClassLabel() < b.getClassLabel() ? -1 :
151
+ a.getClassLabel() > b.getClassLabel() ? 1 : 0));
101
152
  }
102
- /**
103
- * Returns size of the instance list.
104
- *
105
- * @return Size of the instance list.
106
- */
107
- size() {
108
- return this.list.length;
153
+ else {
154
+ this.list.sort((a, b) => a.getAttribute(attributeIndex).getValue() < b.getAttribute(attributeIndex).getValue() ? -1 :
155
+ a.getAttribute(attributeIndex).getValue() > b.getAttribute(attributeIndex).getValue() ? 1 : 0);
109
156
  }
110
- /**
111
- * Accessor for a single instance with the given index.
112
- *
113
- * @param index Index of the instance.
114
- * @return Instance with index 'index'.
115
- */
116
- get(index) {
117
- return this.list[index];
157
+ }
158
+ /**
159
+ * Shuffles the instance list.
160
+ * @param random Random number generation.
161
+ */
162
+ shuffle(random) {
163
+ random.shuffle(this.list);
164
+ }
165
+ /**
166
+ * Creates a bootstrap sample from the current instance list.
167
+ *
168
+ * @param seed To create a different bootstrap sample, we need a new seed for each sample.
169
+ * @return Bootstrap sample.
170
+ */
171
+ bootstrap(seed) {
172
+ return new Bootstrap_1.Bootstrap(this.list, seed);
173
+ }
174
+ /**
175
+ * Extracts the class labels of each instance in the instance list and returns them in an array of {@link String}.
176
+ *
177
+ * @return An array list of class labels.
178
+ */
179
+ getClassLabels() {
180
+ let classLabels = new Array();
181
+ for (let instance of this.list) {
182
+ classLabels.push(instance.getClassLabel());
183
+ }
184
+ return classLabels;
185
+ }
186
+ /**
187
+ * Extracts the class labels of each instance in the instance list and returns them as a set.
188
+ *
189
+ * @return An {@link Array} of distinct class labels.
190
+ */
191
+ getDistinctClassLabels() {
192
+ let classLabels = new Array();
193
+ for (let instance of this.list) {
194
+ if (!classLabels.includes(instance.getClassLabel())) {
195
+ classLabels.push(instance.getClassLabel());
196
+ }
118
197
  }
119
- /**
120
- * Sorts instance list according to the attribute with index 'attributeIndex'.
121
- *
122
- * @param attributeIndex index of the attribute.
123
- */
124
- sort(attributeIndex) {
125
- if (attributeIndex == undefined) {
126
- this.list.sort((a, b) => (a.getClassLabel() < b.getClassLabel() ? -1 :
127
- a.getClassLabel() > b.getClassLabel() ? 1 : 0));
198
+ return classLabels;
199
+ }
200
+ /**
201
+ * Extracts the possible class labels of each instance in the instance list and returns them as a set.
202
+ *
203
+ * @return An {@link Array} of distinct class labels.
204
+ */
205
+ getUnionOfPossibleClassLabels() {
206
+ let possibleClassLabels = new Array();
207
+ for (let instance of this.list) {
208
+ if (instance instanceof CompositeInstance_1.CompositeInstance) {
209
+ let compositeInstance = instance;
210
+ for (let possibleClassLabel of compositeInstance.getPossibleClassLabels()) {
211
+ if (!possibleClassLabels.includes(possibleClassLabel)) {
212
+ possibleClassLabels.push(possibleClassLabel);
213
+ }
214
+ }
128
215
  }
129
216
  else {
130
- this.list.sort((a, b) => a.getAttribute(attributeIndex).getValue() < b.getAttribute(attributeIndex).getValue() ? -1 :
131
- a.getAttribute(attributeIndex).getValue() > b.getAttribute(attributeIndex).getValue() ? 1 : 0);
217
+ if (!possibleClassLabels.includes(instance.getClassLabel())) {
218
+ possibleClassLabels.push(instance.getClassLabel());
219
+ }
132
220
  }
133
221
  }
134
- /**
135
- * Shuffles the instance list.
136
- * @param random Random number generation.
137
- */
138
- shuffle(random) {
139
- random.shuffle(this.list);
140
- }
141
- /**
142
- * Creates a bootstrap sample from the current instance list.
143
- *
144
- * @param seed To create a different bootstrap sample, we need a new seed for each sample.
145
- * @return Bootstrap sample.
146
- */
147
- bootstrap(seed) {
148
- return new Bootstrap_1.Bootstrap(this.list, seed);
149
- }
150
- /**
151
- * Extracts the class labels of each instance in the instance list and returns them in an array of {@link String}.
152
- *
153
- * @return An array list of class labels.
154
- */
155
- getClassLabels() {
156
- let classLabels = new Array();
157
- for (let instance of this.list) {
158
- classLabels.push(instance.getClassLabel());
222
+ return possibleClassLabels;
223
+ }
224
+ /**
225
+ * Extracts distinct discrete values of a given attribute as an array of strings.
226
+ *
227
+ * @param attributeIndex Index of the discrete attribute.
228
+ * @return An array of distinct values of a discrete attribute.
229
+ */
230
+ getAttributeValueList(attributeIndex) {
231
+ let valueList = new Array();
232
+ for (let instance of this.list) {
233
+ if (!valueList.includes(instance.getAttribute(attributeIndex).getValue())) {
234
+ valueList.push(instance.getAttribute(attributeIndex).getValue());
159
235
  }
160
- return classLabels;
161
236
  }
162
- /**
163
- * Extracts the class labels of each instance in the instance list and returns them as a set.
164
- *
165
- * @return An {@link Array} of distinct class labels.
166
- */
167
- getDistinctClassLabels() {
168
- let classLabels = new Array();
237
+ return valueList;
238
+ }
239
+ /**
240
+ * Calculates the mean of a single attribute for this instance list (m_i). If the attribute is discrete, the maximum
241
+ * occurring value for that attribute is returned. If the attribute is continuous, the mean value of the values of
242
+ * all instances are returned.
243
+ *
244
+ * @param index Index of the attribute.
245
+ * @return The mean value of the instances as an attribute.
246
+ */
247
+ attributeAverage(index) {
248
+ if (this.list[0].getAttribute(index) instanceof DiscreteAttribute_1.DiscreteAttribute) {
249
+ let values = new Array();
169
250
  for (let instance of this.list) {
170
- if (!classLabels.includes(instance.getClassLabel())) {
171
- classLabels.push(instance.getClassLabel());
172
- }
251
+ values.push(instance.getAttribute(index).getValue());
173
252
  }
174
- return classLabels;
253
+ return new DiscreteAttribute_1.DiscreteAttribute(Model_1.Model.getMaximum(values));
175
254
  }
176
- /**
177
- * Extracts the possible class labels of each instance in the instance list and returns them as a set.
178
- *
179
- * @return An {@link Array} of distinct class labels.
180
- */
181
- getUnionOfPossibleClassLabels() {
182
- let possibleClassLabels = new Array();
183
- for (let instance of this.list) {
184
- if (instance instanceof CompositeInstance_1.CompositeInstance) {
185
- let compositeInstance = instance;
186
- for (let possibleClassLabel of compositeInstance.getPossibleClassLabels()) {
187
- if (!possibleClassLabels.includes(possibleClassLabel)) {
188
- possibleClassLabels.push(possibleClassLabel);
189
- }
190
- }
191
- }
192
- else {
193
- if (!possibleClassLabels.includes(instance.getClassLabel())) {
194
- possibleClassLabels.push(instance.getClassLabel());
195
- }
255
+ else {
256
+ if (this.list[0].getAttribute(index) instanceof ContinuousAttribute_1.ContinuousAttribute) {
257
+ let sum = 0.0;
258
+ for (let instance of this.list) {
259
+ sum += instance.getAttribute(index).getValue();
196
260
  }
261
+ return new ContinuousAttribute_1.ContinuousAttribute(sum / this.list.length);
262
+ }
263
+ else {
264
+ return undefined;
197
265
  }
198
- return possibleClassLabels;
199
266
  }
200
- /**
201
- * Extracts distinct discrete values of a given attribute as an array of strings.
202
- *
203
- * @param attributeIndex Index of the discrete attribute.
204
- * @return An array of distinct values of a discrete attribute.
205
- */
206
- getAttributeValueList(attributeIndex) {
207
- let valueList = new Array();
208
- for (let instance of this.list) {
209
- if (!valueList.includes(instance.getAttribute(attributeIndex).getValue())) {
210
- valueList.push(instance.getAttribute(attributeIndex).getValue());
267
+ }
268
+ /**
269
+ * Calculates the mean of a single attribute for this instance list (m_i).
270
+ *
271
+ * @param index Index of the attribute.
272
+ * @return The mean value of the instances as an attribute.
273
+ */
274
+ continuousAttributeAverage(index) {
275
+ if (index == undefined) {
276
+ let result = new Array();
277
+ for (let i = 0; i < this.list[0].attributeSize(); i++) {
278
+ for (let attribute of this.continuousAttributeAverage(i)) {
279
+ result.push(attribute);
211
280
  }
212
281
  }
213
- return valueList;
282
+ return result;
214
283
  }
215
- /**
216
- * Calculates the mean of a single attribute for this instance list (m_i). If the attribute is discrete, the maximum
217
- * occurring value for that attribute is returned. If the attribute is continuous, the mean value of the values of
218
- * all instances are returned.
219
- *
220
- * @param index Index of the attribute.
221
- * @return The mean value of the instances as an attribute.
222
- */
223
- attributeAverage(index) {
224
- if (this.list[0].getAttribute(index) instanceof DiscreteAttribute_1.DiscreteAttribute) {
284
+ else {
285
+ if (this.list[0].getAttribute(index) instanceof DiscreteIndexedAttribute_1.DiscreteIndexedAttribute) {
286
+ let maxIndexSize = this.list[0].getAttribute(index).getMaxIndex();
225
287
  let values = new Array();
288
+ for (let i = 0; i < maxIndexSize; i++) {
289
+ values.push(0.0);
290
+ }
226
291
  for (let instance of this.list) {
227
- values.push(instance.getAttribute(index).getValue());
292
+ let valueIndex = instance.getAttribute(index).getIndex();
293
+ values[valueIndex]++;
228
294
  }
229
- return new DiscreteAttribute_1.DiscreteAttribute(Model_1.Model.getMaximum(values));
295
+ for (let i = 0; i < values.length; i++) {
296
+ values[i] /= this.list.length;
297
+ }
298
+ return values;
230
299
  }
231
300
  else {
232
301
  if (this.list[0].getAttribute(index) instanceof ContinuousAttribute_1.ContinuousAttribute) {
@@ -234,288 +303,242 @@
234
303
  for (let instance of this.list) {
235
304
  sum += instance.getAttribute(index).getValue();
236
305
  }
237
- return new ContinuousAttribute_1.ContinuousAttribute(sum / this.list.length);
306
+ let values = new Array();
307
+ values.push(sum / this.list.length);
308
+ return values;
238
309
  }
239
310
  else {
240
311
  return undefined;
241
312
  }
242
313
  }
243
314
  }
244
- /**
245
- * Calculates the mean of a single attribute for this instance list (m_i).
246
- *
247
- * @param index Index of the attribute.
248
- * @return The mean value of the instances as an attribute.
249
- */
250
- continuousAttributeAverage(index) {
251
- if (index == undefined) {
252
- let result = new Array();
253
- for (let i = 0; i < this.list[0].attributeSize(); i++) {
254
- for (let attribute of this.continuousAttributeAverage(i)) {
255
- result.push(attribute);
256
- }
257
- }
258
- return result;
315
+ }
316
+ /**
317
+ * Calculates the standard deviation of a single attribute for this instance list (m_i). If the attribute is discrete,
318
+ * null returned. If the attribute is continuous, the standard deviation of the values all instances are returned.
319
+ *
320
+ * @param index Index of the attribute.
321
+ * @return The standard deviation of the instances as an attribute.
322
+ */
323
+ attributeStandardDeviation(index) {
324
+ if (this.list[0].getAttribute(index) instanceof ContinuousAttribute_1.ContinuousAttribute) {
325
+ let sum = 0.0;
326
+ for (let instance of this.list) {
327
+ sum += instance.getAttribute(index).getValue();
259
328
  }
260
- else {
261
- if (this.list[0].getAttribute(index) instanceof DiscreteIndexedAttribute_1.DiscreteIndexedAttribute) {
262
- let maxIndexSize = this.list[0].getAttribute(index).getMaxIndex();
263
- let values = new Array();
264
- for (let i = 0; i < maxIndexSize; i++) {
265
- values.push(0.0);
266
- }
267
- for (let instance of this.list) {
268
- let valueIndex = instance.getAttribute(index).getIndex();
269
- values[valueIndex]++;
270
- }
271
- for (let i = 0; i < values.length; i++) {
272
- values[i] /= this.list.length;
273
- }
274
- return values;
275
- }
276
- else {
277
- if (this.list[0].getAttribute(index) instanceof ContinuousAttribute_1.ContinuousAttribute) {
278
- let sum = 0.0;
279
- for (let instance of this.list) {
280
- sum += instance.getAttribute(index).getValue();
281
- }
282
- let values = new Array();
283
- values.push(sum / this.list.length);
284
- return values;
285
- }
286
- else {
287
- return undefined;
288
- }
329
+ let average = sum / this.list.length;
330
+ sum = 0.0;
331
+ for (let instance of this.list) {
332
+ sum += Math.pow(instance.getAttribute(index).getValue() - average, 2);
333
+ }
334
+ return new ContinuousAttribute_1.ContinuousAttribute(Math.sqrt(sum / (this.list.length - 1)));
335
+ }
336
+ else {
337
+ return undefined;
338
+ }
339
+ }
340
+ /**
341
+ * Calculates the standard deviation of a single continuous attribute for this instance list (m_i).
342
+ *
343
+ * @param index Index of the attribute.
344
+ * @return The standard deviation of the instances as an attribute.
345
+ */
346
+ continuousAttributeStandardDeviation(index) {
347
+ if (index == undefined) {
348
+ let result = new Array();
349
+ for (let i = 0; i < this.list[0].attributeSize(); i++) {
350
+ for (let attribute of this.continuousAttributeStandardDeviation(i)) {
351
+ result.push(attribute);
289
352
  }
290
353
  }
354
+ return result;
291
355
  }
292
- /**
293
- * Calculates the standard deviation of a single attribute for this instance list (m_i). If the attribute is discrete,
294
- * null returned. If the attribute is continuous, the standard deviation of the values all instances are returned.
295
- *
296
- * @param index Index of the attribute.
297
- * @return The standard deviation of the instances as an attribute.
298
- */
299
- attributeStandardDeviation(index) {
300
- if (this.list[0].getAttribute(index) instanceof ContinuousAttribute_1.ContinuousAttribute) {
301
- let sum = 0.0;
302
- for (let instance of this.list) {
303
- sum += instance.getAttribute(index).getValue();
356
+ else {
357
+ if (this.list[0].getAttribute(index) instanceof DiscreteIndexedAttribute_1.DiscreteIndexedAttribute) {
358
+ let maxIndexSize = this.list[0].getAttribute(index).getMaxIndex();
359
+ let averages = new Array();
360
+ for (let i = 0; i < maxIndexSize; i++) {
361
+ averages.push(0.0);
304
362
  }
305
- let average = sum / this.list.length;
306
- sum = 0.0;
307
363
  for (let instance of this.list) {
308
- sum += Math.pow(instance.getAttribute(index).getValue() - average, 2);
364
+ let valueIndex = instance.getAttribute(index).getIndex();
365
+ averages[valueIndex]++;
309
366
  }
310
- return new ContinuousAttribute_1.ContinuousAttribute(Math.sqrt(sum / (this.list.length - 1)));
311
- }
312
- else {
313
- return undefined;
314
- }
315
- }
316
- /**
317
- * Calculates the standard deviation of a single continuous attribute for this instance list (m_i).
318
- *
319
- * @param index Index of the attribute.
320
- * @return The standard deviation of the instances as an attribute.
321
- */
322
- continuousAttributeStandardDeviation(index) {
323
- if (index == undefined) {
324
- let result = new Array();
325
- for (let i = 0; i < this.list[0].attributeSize(); i++) {
326
- for (let attribute of this.continuousAttributeStandardDeviation(i)) {
327
- result.push(attribute);
367
+ for (let i = 0; i < averages.length; i++) {
368
+ averages[i] /= this.list.length;
369
+ }
370
+ let values = new Array();
371
+ for (let i = 0; i < maxIndexSize; i++) {
372
+ values.push(0.0);
373
+ }
374
+ for (let instance of this.list) {
375
+ let valueIndex = instance.getAttribute(index).getIndex();
376
+ for (let i = 0; i < maxIndexSize; i++) {
377
+ if (i == valueIndex) {
378
+ values[i] += Math.pow(1 - averages[i], 2);
379
+ }
380
+ else {
381
+ values[i] += Math.pow(averages[i], 2);
382
+ }
328
383
  }
329
384
  }
330
- return result;
385
+ for (let i = 0; i < values.length; i++) {
386
+ values[i] = Math.sqrt(values[i] / (this.list.length - 1));
387
+ }
388
+ return values;
331
389
  }
332
390
  else {
333
- if (this.list[0].getAttribute(index) instanceof DiscreteIndexedAttribute_1.DiscreteIndexedAttribute) {
334
- let maxIndexSize = this.list[0].getAttribute(index).getMaxIndex();
335
- let averages = new Array();
336
- for (let i = 0; i < maxIndexSize; i++) {
337
- averages.push(0.0);
338
- }
391
+ if (this.list[0].getAttribute(index) instanceof ContinuousAttribute_1.ContinuousAttribute) {
392
+ let sum = 0.0;
339
393
  for (let instance of this.list) {
340
- let valueIndex = instance.getAttribute(index).getIndex();
341
- averages[valueIndex]++;
342
- }
343
- for (let i = 0; i < averages.length; i++) {
344
- averages[i] /= this.list.length;
345
- }
346
- let values = new Array();
347
- for (let i = 0; i < maxIndexSize; i++) {
348
- values.push(0.0);
394
+ sum += instance.getAttribute(index).getValue();
349
395
  }
396
+ let average = sum / this.list.length;
397
+ sum = 0.0;
350
398
  for (let instance of this.list) {
351
- let valueIndex = instance.getAttribute(index).getIndex();
352
- for (let i = 0; i < maxIndexSize; i++) {
353
- if (i == valueIndex) {
354
- values[i] += Math.pow(1 - averages[i], 2);
355
- }
356
- else {
357
- values[i] += Math.pow(averages[i], 2);
358
- }
359
- }
399
+ sum += Math.pow(instance.getAttribute(index).getValue() - average, 2);
360
400
  }
361
- for (let i = 0; i < values.length; i++) {
362
- values[i] = Math.sqrt(values[i] / (this.list.length - 1));
363
- }
364
- return values;
401
+ let result = new Array();
402
+ result.push(Math.sqrt(sum / (this.list.length - 1)));
403
+ return result;
365
404
  }
366
405
  else {
367
- if (this.list[0].getAttribute(index) instanceof ContinuousAttribute_1.ContinuousAttribute) {
368
- let sum = 0.0;
369
- for (let instance of this.list) {
370
- sum += instance.getAttribute(index).getValue();
371
- }
372
- let average = sum / this.list.length;
373
- sum = 0.0;
374
- for (let instance of this.list) {
375
- sum += Math.pow(instance.getAttribute(index).getValue() - average, 2);
376
- }
377
- let result = new Array();
378
- result.push(Math.sqrt(sum / (this.list.length - 1)));
379
- return result;
380
- }
381
- else {
382
- return undefined;
383
- }
384
- }
385
- }
386
- }
387
- /**
388
- * The attributeDistribution method takes an index as an input and if the attribute of the instance at given index is
389
- * discrete, it returns the distribution of the attributes of that instance.
390
- *
391
- * @param index Index of the attribute.
392
- * @return Distribution of the attribute.
393
- */
394
- attributeDistribution(index) {
395
- let distribution = new DiscreteDistribution_1.DiscreteDistribution();
396
- if (this.list[0].getAttribute(index) instanceof DiscreteAttribute_1.DiscreteAttribute) {
397
- for (let instance of this.list) {
398
- distribution.addItem(instance.getAttribute(index).getValue());
406
+ return undefined;
399
407
  }
400
408
  }
401
- return distribution;
402
409
  }
403
- /**
404
- * The attributeClassDistribution method takes an attribute index as an input. It loops through the instances, gets
405
- * the corresponding value of given attribute index and adds the class label of that instance to the discrete distributions list.
406
- *
407
- * @param attributeIndex Index of the attribute.
408
- * @return Distribution of the class labels.
409
- */
410
- attributeClassDistribution(attributeIndex) {
411
- let distributions = new Array();
412
- let valueList = this.getAttributeValueList(attributeIndex);
413
- for (let ignored of valueList) {
414
- distributions.push(new DiscreteDistribution_1.DiscreteDistribution());
415
- }
410
+ }
411
+ /**
412
+ * The attributeDistribution method takes an index as an input and if the attribute of the instance at given index is
413
+ * discrete, it returns the distribution of the attributes of that instance.
414
+ *
415
+ * @param index Index of the attribute.
416
+ * @return Distribution of the attribute.
417
+ */
418
+ attributeDistribution(index) {
419
+ let distribution = new DiscreteDistribution_1.DiscreteDistribution();
420
+ if (this.list[0].getAttribute(index) instanceof DiscreteAttribute_1.DiscreteAttribute) {
416
421
  for (let instance of this.list) {
417
- distributions[valueList.indexOf(instance.getAttribute(attributeIndex).getValue())].addItem(instance.getClassLabel());
422
+ distribution.addItem(instance.getAttribute(index).getValue());
418
423
  }
419
- return distributions;
420
424
  }
421
- /**
422
- * The discreteIndexedAttributeClassDistribution method takes an attribute index and an attribute value as inputs.
423
- * It loops through the instances, gets the corresponding value of given attribute index and given attribute value.
424
- * Then, adds the class label of that instance to the discrete indexed distributions list.
425
- *
426
- * @param attributeIndex Index of the attribute.
427
- * @param attributeValue Value of the attribute.
428
- * @return Distribution of the class labels.
429
- */
430
- discreteIndexedAttributeClassDistribution(attributeIndex, attributeValue) {
431
- let distribution = new DiscreteDistribution_1.DiscreteDistribution();
432
- for (let instance of this.list) {
433
- if (instance.getAttribute(attributeIndex).getIndex() == attributeValue) {
434
- distribution.addItem(instance.getClassLabel());
435
- }
436
- }
437
- return distribution;
425
+ return distribution;
426
+ }
427
+ /**
428
+ * The attributeClassDistribution method takes an attribute index as an input. It loops through the instances, gets
429
+ * the corresponding value of given attribute index and adds the class label of that instance to the discrete distributions list.
430
+ *
431
+ * @param attributeIndex Index of the attribute.
432
+ * @return Distribution of the class labels.
433
+ */
434
+ attributeClassDistribution(attributeIndex) {
435
+ let distributions = new Array();
436
+ let valueList = this.getAttributeValueList(attributeIndex);
437
+ for (let ignored of valueList) {
438
+ distributions.push(new DiscreteDistribution_1.DiscreteDistribution());
438
439
  }
439
- /**
440
- * The classDistribution method returns the distribution of all the class labels of instances.
441
- *
442
- * @return Distribution of the class labels.
443
- */
444
- classDistribution() {
445
- let distribution = new DiscreteDistribution_1.DiscreteDistribution();
446
- for (let instance of this.list) {
440
+ for (let instance of this.list) {
441
+ distributions[valueList.indexOf(instance.getAttribute(attributeIndex).getValue())].addItem(instance.getClassLabel());
442
+ }
443
+ return distributions;
444
+ }
445
+ /**
446
+ * The discreteIndexedAttributeClassDistribution method takes an attribute index and an attribute value as inputs.
447
+ * It loops through the instances, gets the corresponding value of given attribute index and given attribute value.
448
+ * Then, adds the class label of that instance to the discrete indexed distributions list.
449
+ *
450
+ * @param attributeIndex Index of the attribute.
451
+ * @param attributeValue Value of the attribute.
452
+ * @return Distribution of the class labels.
453
+ */
454
+ discreteIndexedAttributeClassDistribution(attributeIndex, attributeValue) {
455
+ let distribution = new DiscreteDistribution_1.DiscreteDistribution();
456
+ for (let instance of this.list) {
457
+ if (instance.getAttribute(attributeIndex).getIndex() == attributeValue) {
447
458
  distribution.addItem(instance.getClassLabel());
448
459
  }
449
- return distribution;
450
460
  }
451
- /**
452
- * The allAttributesDistribution method returns the distributions of all the attributes of instances.
453
- *
454
- * @return Distributions of all the attributes of instances.
455
- */
456
- allAttributesDistribution() {
457
- let distributions = new Array();
458
- for (let i = 0; i < this.list[0].attributeSize(); i++) {
459
- distributions.push(this.attributeDistribution(i));
460
- }
461
- return distributions;
461
+ return distribution;
462
+ }
463
+ /**
464
+ * The classDistribution method returns the distribution of all the class labels of instances.
465
+ *
466
+ * @return Distribution of the class labels.
467
+ */
468
+ classDistribution() {
469
+ let distribution = new DiscreteDistribution_1.DiscreteDistribution();
470
+ for (let instance of this.list) {
471
+ distribution.addItem(instance.getClassLabel());
462
472
  }
463
- /**
464
- * Returns the mean of all the attributes for instances in the list.
465
- *
466
- * @return Mean of all the attributes for instances in the list.
467
- */
468
- average() {
469
- let result = new Instance_1.Instance(this.list[0].getClassLabel());
470
- for (let i = 0; i < this.list[0].attributeSize(); i++) {
471
- result.addAttribute(this.attributeAverage(i));
472
- }
473
- return result;
473
+ return distribution;
474
+ }
475
+ /**
476
+ * The allAttributesDistribution method returns the distributions of all the attributes of instances.
477
+ *
478
+ * @return Distributions of all the attributes of instances.
479
+ */
480
+ allAttributesDistribution() {
481
+ let distributions = new Array();
482
+ for (let i = 0; i < this.list[0].attributeSize(); i++) {
483
+ distributions.push(this.attributeDistribution(i));
474
484
  }
475
- /**
476
- * Returns the standard deviation of attributes for instances.
477
- *
478
- * @return Standard deviation of attributes for instances.
479
- */
480
- standardDeviation() {
481
- let result = new Instance_1.Instance(this.list[0].getClassLabel());
482
- for (let i = 0; i < this.list[0].attributeSize(); i++) {
483
- result.addAttribute(this.attributeStandardDeviation(i));
484
- }
485
- return result;
485
+ return distributions;
486
+ }
487
+ /**
488
+ * Returns the mean of all the attributes for instances in the list.
489
+ *
490
+ * @return Mean of all the attributes for instances in the list.
491
+ */
492
+ average() {
493
+ let result = new Instance_1.Instance(this.list[0].getClassLabel());
494
+ for (let i = 0; i < this.list[0].attributeSize(); i++) {
495
+ result.addAttribute(this.attributeAverage(i));
486
496
  }
487
- /**
488
- * Calculates a covariance {@link Matrix} by using an average {@link Vector}.
489
- *
490
- * @param average Vector input.
491
- * @return Covariance {@link Matrix}.
492
- */
493
- covariance(average) {
494
- let result = new Matrix_1.Matrix(this.list[0].continuousAttributeSize(), this.list[0].continuousAttributeSize());
495
- for (let instance of this.list) {
496
- let continuousAttributes = instance.continuousAttributes();
497
- for (let i = 0; i < instance.continuousAttributeSize(); i++) {
498
- let xi = continuousAttributes[i];
499
- let mi = average.getValue(i);
500
- for (let j = 0; j < instance.continuousAttributeSize(); j++) {
501
- let xj = continuousAttributes[j];
502
- let mj = average.getValue(j);
503
- result.addValue(i, j, (xi - mi) * (xj - mj));
504
- }
497
+ return result;
498
+ }
499
+ /**
500
+ * Returns the standard deviation of attributes for instances.
501
+ *
502
+ * @return Standard deviation of attributes for instances.
503
+ */
504
+ standardDeviation() {
505
+ let result = new Instance_1.Instance(this.list[0].getClassLabel());
506
+ for (let i = 0; i < this.list[0].attributeSize(); i++) {
507
+ result.addAttribute(this.attributeStandardDeviation(i));
508
+ }
509
+ return result;
510
+ }
511
+ /**
512
+ * Calculates a covariance {@link Matrix} by using an average {@link Vector}.
513
+ *
514
+ * @param average Vector input.
515
+ * @return Covariance {@link Matrix}.
516
+ */
517
+ covariance(average) {
518
+ let result = new Matrix_1.Matrix(this.list[0].continuousAttributeSize(), this.list[0].continuousAttributeSize());
519
+ for (let instance of this.list) {
520
+ let continuousAttributes = instance.continuousAttributes();
521
+ for (let i = 0; i < instance.continuousAttributeSize(); i++) {
522
+ let xi = continuousAttributes[i];
523
+ let mi = average.getValue(i);
524
+ for (let j = 0; j < instance.continuousAttributeSize(); j++) {
525
+ let xj = continuousAttributes[j];
526
+ let mj = average.getValue(j);
527
+ result.addValue(i, j, (xi - mi) * (xj - mj));
505
528
  }
506
529
  }
507
- result.divideByConstant(this.list.length - 1);
508
- return result;
509
- }
510
- /**
511
- * Accessor for the instances.
512
- *
513
- * @return Instances.
514
- */
515
- getInstances() {
516
- return this.list;
517
530
  }
531
+ result.divideByConstant(this.list.length - 1);
532
+ return result;
518
533
  }
519
- exports.InstanceList = InstanceList;
520
- });
534
+ /**
535
+ * Accessor for the instances.
536
+ *
537
+ * @return Instances.
538
+ */
539
+ getInstances() {
540
+ return this.list;
541
+ }
542
+ }
543
+ exports.InstanceList = InstanceList;
521
544
  //# sourceMappingURL=InstanceList.js.map