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.
- package/dist/Attribute/Attribute.js +6 -16
- package/dist/Attribute/Attribute.js.map +1 -1
- package/dist/Attribute/AttributeType.js +22 -32
- package/dist/Attribute/AttributeType.js.map +1 -1
- package/dist/Attribute/BinaryAttribute.js +14 -24
- package/dist/Attribute/BinaryAttribute.js.map +1 -1
- package/dist/Attribute/ContinuousAttribute.js +46 -55
- package/dist/Attribute/ContinuousAttribute.js.map +1 -1
- package/dist/Attribute/DiscreteAttribute.js +38 -48
- package/dist/Attribute/DiscreteAttribute.js.map +1 -1
- package/dist/Attribute/DiscreteIndexedAttribute.js +47 -55
- package/dist/Attribute/DiscreteIndexedAttribute.js.map +1 -1
- package/dist/DataSet/DataDefinition.js +115 -123
- package/dist/DataSet/DataDefinition.js.map +1 -1
- package/dist/DataSet/DataSet.js +268 -245
- package/dist/DataSet/DataSet.js.map +1 -1
- package/dist/DistanceMetric/DistanceMetric.js +2 -12
- package/dist/DistanceMetric/EuclidianDistance.js +27 -37
- package/dist/DistanceMetric/EuclidianDistance.js.map +1 -1
- package/dist/DistanceMetric/MahalanobisDistance.js +27 -36
- package/dist/DistanceMetric/MahalanobisDistance.js.map +1 -1
- package/dist/Experiment/BootstrapRun.js +31 -40
- package/dist/Experiment/BootstrapRun.js.map +1 -1
- package/dist/Experiment/Experiment.js +46 -53
- package/dist/Experiment/Experiment.js.map +1 -1
- package/dist/Experiment/KFoldRun.js +45 -54
- package/dist/Experiment/KFoldRun.js.map +1 -1
- package/dist/Experiment/KFoldRunSeparateTest.js +48 -58
- package/dist/Experiment/KFoldRunSeparateTest.js.map +1 -1
- package/dist/Experiment/MultipleRun.js +2 -12
- package/dist/Experiment/MxKFoldRun.js +31 -40
- package/dist/Experiment/MxKFoldRun.js.map +1 -1
- package/dist/Experiment/MxKFoldRunSeparateTest.js +35 -44
- package/dist/Experiment/MxKFoldRunSeparateTest.js.map +1 -1
- package/dist/Experiment/SingleRun.js +2 -12
- package/dist/Experiment/SingleRunWithK.js +39 -48
- package/dist/Experiment/SingleRunWithK.js.map +1 -1
- package/dist/Experiment/StratifiedKFoldRun.js +26 -36
- package/dist/Experiment/StratifiedKFoldRun.js.map +1 -1
- package/dist/Experiment/StratifiedKFoldRunSeparateTest.js +30 -40
- package/dist/Experiment/StratifiedKFoldRunSeparateTest.js.map +1 -1
- package/dist/Experiment/StratifiedMxKFoldRun.js +29 -39
- package/dist/Experiment/StratifiedMxKFoldRun.js.map +1 -1
- package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js +34 -43
- package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js.map +1 -1
- package/dist/Experiment/StratifiedSingleRunWithK.js +27 -36
- package/dist/Experiment/StratifiedSingleRunWithK.js.map +1 -1
- package/dist/FeatureSelection/BackwardSelection.js +26 -36
- package/dist/FeatureSelection/BackwardSelection.js.map +1 -1
- package/dist/FeatureSelection/FeatureSubSet.js +72 -82
- package/dist/FeatureSelection/FeatureSubSet.js.map +1 -1
- package/dist/FeatureSelection/FloatingSelection.js +25 -35
- package/dist/FeatureSelection/FloatingSelection.js.map +1 -1
- package/dist/FeatureSelection/ForwardSelection.js +25 -35
- package/dist/FeatureSelection/ForwardSelection.js.map +1 -1
- package/dist/FeatureSelection/SubSetSelection.js +69 -78
- package/dist/FeatureSelection/SubSetSelection.js.map +1 -1
- package/dist/Filter/DiscreteToContinuous.js +50 -60
- package/dist/Filter/DiscreteToContinuous.js.map +1 -1
- package/dist/Filter/DiscreteToIndexed.js +40 -50
- package/dist/Filter/DiscreteToIndexed.js.map +1 -1
- package/dist/Filter/FeatureFilter.js +23 -32
- package/dist/Filter/FeatureFilter.js.map +1 -1
- package/dist/Filter/LaryFilter.js +46 -55
- package/dist/Filter/LaryFilter.js.map +1 -1
- package/dist/Filter/LaryToBinary.js +48 -58
- package/dist/Filter/LaryToBinary.js.map +1 -1
- package/dist/Filter/Normalize.js +33 -41
- package/dist/Filter/Normalize.js.map +1 -1
- package/dist/Filter/Pca.js +86 -96
- package/dist/Filter/Pca.js.map +1 -1
- package/dist/Filter/TrainedFeatureFilter.js +14 -24
- package/dist/Filter/TrainedFeatureFilter.js.map +1 -1
- package/dist/Instance/CompositeInstance.js +46 -56
- package/dist/Instance/CompositeInstance.js.map +1 -1
- package/dist/Instance/Instance.js +145 -154
- package/dist/Instance/Instance.js.map +1 -1
- package/dist/InstanceList/InstanceList.js +466 -443
- package/dist/InstanceList/InstanceList.js.map +1 -1
- package/dist/InstanceList/InstanceListOfSameClass.js +23 -32
- package/dist/InstanceList/InstanceListOfSameClass.js.map +1 -1
- package/dist/InstanceList/Partition.js +167 -177
- package/dist/InstanceList/Partition.js.map +1 -1
- package/dist/Model/DecisionTree/DecisionCondition.js +71 -80
- package/dist/Model/DecisionTree/DecisionCondition.js.map +1 -1
- package/dist/Model/DecisionTree/DecisionNode.js +302 -311
- package/dist/Model/DecisionTree/DecisionNode.js.map +1 -1
- package/dist/Model/DecisionTree/DecisionStump.js +22 -32
- package/dist/Model/DecisionTree/DecisionStump.js.map +1 -1
- package/dist/Model/DecisionTree/DecisionTree.js +89 -98
- package/dist/Model/DecisionTree/DecisionTree.js.map +1 -1
- package/dist/Model/DummyModel.js +64 -73
- package/dist/Model/DummyModel.js.map +1 -1
- package/dist/Model/Ensemble/BaggingModel.js +34 -44
- package/dist/Model/Ensemble/BaggingModel.js.map +1 -1
- package/dist/Model/Ensemble/RandomForestModel.js +31 -41
- package/dist/Model/Ensemble/RandomForestModel.js.map +1 -1
- package/dist/Model/Ensemble/TreeEnsembleModel.js +55 -64
- package/dist/Model/Ensemble/TreeEnsembleModel.js.map +1 -1
- package/dist/Model/Model.js +130 -140
- package/dist/Model/Model.js.map +1 -1
- package/dist/Model/NeuralNetwork/DeepNetworkModel.js +162 -169
- package/dist/Model/NeuralNetwork/DeepNetworkModel.js.map +1 -1
- package/dist/Model/NeuralNetwork/LinearPerceptronModel.js +69 -78
- package/dist/Model/NeuralNetwork/LinearPerceptronModel.js.map +1 -1
- package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.js +112 -120
- package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.js.map +1 -1
- package/dist/Model/NeuralNetwork/NeuralNetworkModel.js +197 -201
- package/dist/Model/NeuralNetwork/NeuralNetworkModel.js.map +1 -1
- package/dist/Model/NonParametric/KnnInstance.js +21 -29
- package/dist/Model/NonParametric/KnnInstance.js.map +1 -1
- package/dist/Model/NonParametric/KnnModel.js +101 -108
- package/dist/Model/NonParametric/KnnModel.js.map +1 -1
- package/dist/Model/Parametric/GaussianModel.js +82 -91
- package/dist/Model/Parametric/GaussianModel.js.map +1 -1
- package/dist/Model/Parametric/KMeansModel.js +59 -67
- package/dist/Model/Parametric/KMeansModel.js.map +1 -1
- package/dist/Model/Parametric/LdaModel.js +83 -91
- package/dist/Model/Parametric/LdaModel.js.map +1 -1
- package/dist/Model/Parametric/NaiveBayesModel.js +119 -132
- package/dist/Model/Parametric/NaiveBayesModel.js.map +1 -1
- package/dist/Model/Parametric/QdaModel.js +70 -79
- package/dist/Model/Parametric/QdaModel.js.map +1 -1
- package/dist/Model/RandomModel.js +85 -92
- package/dist/Model/RandomModel.js.map +1 -1
- package/dist/Model/ValidatedModel.js +21 -31
- package/dist/Model/ValidatedModel.js.map +1 -1
- package/dist/Parameter/ActivationFunction.js +9 -19
- package/dist/Parameter/ActivationFunction.js.map +1 -1
- package/dist/Parameter/BaggingParameter.js +24 -33
- package/dist/Parameter/BaggingParameter.js.map +1 -1
- package/dist/Parameter/C45Parameter.js +34 -42
- package/dist/Parameter/C45Parameter.js.map +1 -1
- package/dist/Parameter/DeepNetworkParameter.js +48 -56
- package/dist/Parameter/DeepNetworkParameter.js.map +1 -1
- package/dist/Parameter/KMeansParameter.js +29 -38
- package/dist/Parameter/KMeansParameter.js.map +1 -1
- package/dist/Parameter/KnnParameter.js +25 -34
- package/dist/Parameter/KnnParameter.js.map +1 -1
- package/dist/Parameter/LinearPerceptronParameter.js +56 -62
- package/dist/Parameter/LinearPerceptronParameter.js.map +1 -1
- package/dist/Parameter/MultiLayerPerceptronParameter.js +38 -46
- package/dist/Parameter/MultiLayerPerceptronParameter.js.map +1 -1
- package/dist/Parameter/Parameter.js +21 -30
- package/dist/Parameter/Parameter.js.map +1 -1
- package/dist/Parameter/RandomForestParameter.js +25 -34
- package/dist/Parameter/RandomForestParameter.js.map +1 -1
- package/dist/Performance/ClassificationPerformance.js +24 -33
- package/dist/Performance/ClassificationPerformance.js.map +1 -1
- package/dist/Performance/ConfusionMatrix.js +149 -158
- package/dist/Performance/ConfusionMatrix.js.map +1 -1
- package/dist/Performance/DetailedClassificationPerformance.js +23 -32
- package/dist/Performance/DetailedClassificationPerformance.js.map +1 -1
- package/dist/Performance/ExperimentPerformance.js +184 -161
- package/dist/Performance/ExperimentPerformance.js.map +1 -1
- package/dist/Performance/Performance.js +21 -30
- package/dist/Performance/Performance.js.map +1 -1
- package/dist/StatisticalTest/Combined5x2F.js +41 -51
- package/dist/StatisticalTest/Combined5x2F.js.map +1 -1
- package/dist/StatisticalTest/Combined5x2t.js +42 -52
- package/dist/StatisticalTest/Combined5x2t.js.map +1 -1
- package/dist/StatisticalTest/Paired5x2t.js +40 -50
- package/dist/StatisticalTest/Paired5x2t.js.map +1 -1
- package/dist/StatisticalTest/PairedTest.js +31 -41
- package/dist/StatisticalTest/PairedTest.js.map +1 -1
- package/dist/StatisticalTest/Pairedt.js +38 -48
- package/dist/StatisticalTest/Pairedt.js.map +1 -1
- package/dist/StatisticalTest/Sign.js +50 -60
- package/dist/StatisticalTest/Sign.js.map +1 -1
- package/dist/StatisticalTest/StatisticalTestResult.js +65 -73
- package/dist/StatisticalTest/StatisticalTestResult.js.map +1 -1
- package/dist/StatisticalTest/StatisticalTestResultType.js +11 -21
- package/dist/StatisticalTest/StatisticalTestResultType.js.map +1 -1
- package/dist/index.js +95 -101
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/tsconfig.json +4 -3
- package/source/tsconfig.json +0 -13
|
@@ -1,232 +1,301 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
this.list = definition;
|
|
82
105
|
}
|
|
83
106
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
131
|
-
|
|
217
|
+
if (!possibleClassLabels.includes(instance.getClassLabel())) {
|
|
218
|
+
possibleClassLabels.push(instance.getClassLabel());
|
|
219
|
+
}
|
|
132
220
|
}
|
|
133
221
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
171
|
-
classLabels.push(instance.getClassLabel());
|
|
172
|
-
}
|
|
251
|
+
values.push(instance.getAttribute(index).getValue());
|
|
173
252
|
}
|
|
174
|
-
return
|
|
253
|
+
return new DiscreteAttribute_1.DiscreteAttribute(Model_1.Model.getMaximum(values));
|
|
175
254
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
|
282
|
+
return result;
|
|
214
283
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
292
|
+
let valueIndex = instance.getAttribute(index).getIndex();
|
|
293
|
+
values[valueIndex]++;
|
|
228
294
|
}
|
|
229
|
-
|
|
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
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
|
|
364
|
+
let valueIndex = instance.getAttribute(index).getIndex();
|
|
365
|
+
averages[valueIndex]++;
|
|
309
366
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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
|
-
|
|
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
|
|
334
|
-
let
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
362
|
-
|
|
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
|
-
|
|
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
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
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
|
-
|
|
422
|
+
distribution.addItem(instance.getAttribute(index).getValue());
|
|
418
423
|
}
|
|
419
|
-
return distributions;
|
|
420
424
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
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
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
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
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
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
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
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
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
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
|
-
|
|
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
|