nlptoolkit-classification 1.0.6 → 1.0.8

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 (310) hide show
  1. package/README.md +1 -0
  2. package/dist/Attribute/DiscreteAttribute.d.ts +1 -1
  3. package/dist/Attribute/DiscreteAttribute.js.map +1 -1
  4. package/dist/Attribute/DiscreteIndexedAttribute.d.ts +2 -2
  5. package/dist/DataSet/DataDefinition.d.ts +11 -0
  6. package/dist/DataSet/DataDefinition.js +11 -0
  7. package/dist/DataSet/DataDefinition.js.map +1 -1
  8. package/dist/Experiment/BootstrapRun.js +2 -2
  9. package/dist/Experiment/BootstrapRun.js.map +1 -1
  10. package/dist/Experiment/Experiment.d.ts +7 -7
  11. package/dist/Experiment/Experiment.js +6 -6
  12. package/dist/Experiment/Experiment.js.map +1 -1
  13. package/dist/Experiment/KFoldRun.d.ts +17 -2
  14. package/dist/Experiment/KFoldRun.js +19 -4
  15. package/dist/Experiment/KFoldRun.js.map +1 -1
  16. package/dist/Experiment/KFoldRunSeparateTest.d.ts +13 -2
  17. package/dist/Experiment/KFoldRunSeparateTest.js +15 -4
  18. package/dist/Experiment/KFoldRunSeparateTest.js.map +1 -1
  19. package/dist/Experiment/MxKFoldRun.js +1 -1
  20. package/dist/Experiment/MxKFoldRun.js.map +1 -1
  21. package/dist/Experiment/MxKFoldRunSeparateTest.js +1 -1
  22. package/dist/Experiment/MxKFoldRunSeparateTest.js.map +1 -1
  23. package/dist/Experiment/SingleRunWithK.d.ts +18 -3
  24. package/dist/Experiment/SingleRunWithK.js +18 -3
  25. package/dist/Experiment/SingleRunWithK.js.map +1 -1
  26. package/dist/Experiment/StratifiedKFoldRun.js +1 -1
  27. package/dist/Experiment/StratifiedKFoldRun.js.map +1 -1
  28. package/dist/Experiment/StratifiedKFoldRunSeparateTest.js +1 -1
  29. package/dist/Experiment/StratifiedKFoldRunSeparateTest.js.map +1 -1
  30. package/dist/Experiment/StratifiedMxKFoldRun.js +1 -1
  31. package/dist/Experiment/StratifiedMxKFoldRun.js.map +1 -1
  32. package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js +3 -3
  33. package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js.map +1 -1
  34. package/dist/Experiment/StratifiedSingleRunWithK.js +1 -1
  35. package/dist/Experiment/StratifiedSingleRunWithK.js.map +1 -1
  36. package/dist/Filter/LaryFilter.d.ts +1 -1
  37. package/dist/Filter/LaryFilter.js +1 -1
  38. package/dist/Filter/TrainedFeatureFilter.d.ts +1 -1
  39. package/dist/Filter/TrainedFeatureFilter.js +1 -1
  40. package/dist/InstanceList/Partition.d.ts +45 -0
  41. package/dist/InstanceList/Partition.js +125 -70
  42. package/dist/InstanceList/Partition.js.map +1 -1
  43. package/dist/Model/DecisionTree/DecisionCondition.d.ts +8 -0
  44. package/dist/Model/DecisionTree/DecisionCondition.js +8 -0
  45. package/dist/Model/DecisionTree/DecisionCondition.js.map +1 -1
  46. package/dist/Model/DecisionTree/DecisionNode.d.ts +39 -1
  47. package/dist/Model/DecisionTree/DecisionNode.js +64 -22
  48. package/dist/Model/DecisionTree/DecisionNode.js.map +1 -1
  49. package/dist/Model/DecisionTree/DecisionStump.d.ts +17 -0
  50. package/dist/{Classifier/C45Stump.js → Model/DecisionTree/DecisionStump.js} +13 -10
  51. package/dist/Model/DecisionTree/DecisionStump.js.map +1 -0
  52. package/dist/Model/DecisionTree/DecisionTree.d.ts +24 -9
  53. package/dist/Model/DecisionTree/DecisionTree.js +39 -16
  54. package/dist/Model/DecisionTree/DecisionTree.js.map +1 -1
  55. package/dist/Model/DummyModel.d.ts +28 -3
  56. package/dist/Model/DummyModel.js +36 -23
  57. package/dist/Model/DummyModel.js.map +1 -1
  58. package/dist/{Classifier/Bagging.d.ts → Model/Ensemble/BaggingModel.d.ts} +8 -4
  59. package/dist/{Classifier/Bagging.js → Model/Ensemble/BaggingModel.js} +16 -14
  60. package/dist/Model/Ensemble/BaggingModel.js.map +1 -0
  61. package/dist/{Classifier/RandomForest.d.ts → Model/Ensemble/RandomForestModel.d.ts} +8 -4
  62. package/dist/{Classifier/RandomForest.js → Model/Ensemble/RandomForestModel.js} +16 -14
  63. package/dist/Model/Ensemble/RandomForestModel.js.map +1 -0
  64. package/dist/Model/Ensemble/TreeEnsembleModel.d.ts +32 -0
  65. package/dist/Model/{TreeEnsembleModel.js → Ensemble/TreeEnsembleModel.js} +23 -17
  66. package/dist/Model/Ensemble/TreeEnsembleModel.js.map +1 -0
  67. package/dist/Model/Model.d.ts +52 -0
  68. package/dist/Model/Model.js +84 -1
  69. package/dist/Model/Model.js.map +1 -1
  70. package/dist/Model/NeuralNetwork/DeepNetworkModel.d.ts +47 -0
  71. package/dist/Model/{DeepNetworkModel.js → NeuralNetwork/DeepNetworkModel.js} +55 -55
  72. package/dist/Model/NeuralNetwork/DeepNetworkModel.js.map +1 -0
  73. package/dist/Model/NeuralNetwork/LinearPerceptronModel.d.ts +31 -0
  74. package/dist/Model/NeuralNetwork/LinearPerceptronModel.js +84 -0
  75. package/dist/Model/NeuralNetwork/LinearPerceptronModel.js.map +1 -0
  76. package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.d.ts +39 -0
  77. package/dist/Model/{MultiLayerPerceptronModel.js → NeuralNetwork/MultiLayerPerceptronModel.js} +41 -37
  78. package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.js.map +1 -0
  79. package/dist/Model/{NeuralNetworkModel.d.ts → NeuralNetwork/NeuralNetworkModel.d.ts} +19 -5
  80. package/dist/Model/{NeuralNetworkModel.js → NeuralNetwork/NeuralNetworkModel.js} +19 -6
  81. package/dist/Model/NeuralNetwork/NeuralNetworkModel.js.map +1 -0
  82. package/dist/Model/{KnnInstance.d.ts → NonParametric/KnnInstance.d.ts} +1 -1
  83. package/dist/Model/NonParametric/KnnInstance.js.map +1 -0
  84. package/dist/Model/{KnnModel.d.ts → NonParametric/KnnModel.d.ts} +30 -6
  85. package/dist/Model/{KnnModel.js → NonParametric/KnnModel.js} +42 -19
  86. package/dist/Model/NonParametric/KnnModel.js.map +1 -0
  87. package/dist/Model/{GaussianModel.d.ts → Parametric/GaussianModel.d.ts} +20 -2
  88. package/dist/Model/{GaussianModel.js → Parametric/GaussianModel.js} +21 -3
  89. package/dist/Model/Parametric/GaussianModel.js.map +1 -0
  90. package/dist/Model/Parametric/KMeansModel.d.ts +36 -0
  91. package/dist/Model/Parametric/KMeansModel.js +73 -0
  92. package/dist/Model/Parametric/KMeansModel.js.map +1 -0
  93. package/dist/Model/Parametric/LdaModel.d.ts +44 -0
  94. package/dist/Model/Parametric/LdaModel.js +98 -0
  95. package/dist/Model/Parametric/LdaModel.js.map +1 -0
  96. package/dist/Model/{NaiveBayesModel.d.ts → Parametric/NaiveBayesModel.d.ts} +30 -10
  97. package/dist/Model/{NaiveBayesModel.js → Parametric/NaiveBayesModel.js} +64 -27
  98. package/dist/Model/Parametric/NaiveBayesModel.js.map +1 -0
  99. package/dist/Model/Parametric/QdaModel.d.ts +30 -0
  100. package/dist/Model/Parametric/QdaModel.js +84 -0
  101. package/dist/Model/Parametric/QdaModel.js.map +1 -0
  102. package/dist/Model/RandomModel.d.ts +32 -2
  103. package/dist/Model/RandomModel.js +48 -16
  104. package/dist/Model/RandomModel.js.map +1 -1
  105. package/dist/Parameter/C45Parameter.d.ts +2 -2
  106. package/dist/Parameter/DeepNetworkParameter.d.ts +2 -2
  107. package/dist/Parameter/KnnParameter.d.ts +1 -1
  108. package/dist/Parameter/LinearPerceptronParameter.d.ts +4 -4
  109. package/dist/Parameter/MultiLayerPerceptronParameter.d.ts +2 -2
  110. package/dist/Parameter/Parameter.d.ts +1 -1
  111. package/dist/Performance/ConfusionMatrix.d.ts +1 -1
  112. package/dist/StatisticalTest/Combined5x2F.d.ts +12 -0
  113. package/dist/StatisticalTest/Combined5x2F.js +12 -0
  114. package/dist/StatisticalTest/Combined5x2F.js.map +1 -1
  115. package/dist/StatisticalTest/Combined5x2t.d.ts +13 -0
  116. package/dist/StatisticalTest/Combined5x2t.js +13 -0
  117. package/dist/StatisticalTest/Combined5x2t.js.map +1 -1
  118. package/dist/StatisticalTest/Paired5x2t.d.ts +12 -0
  119. package/dist/StatisticalTest/Paired5x2t.js +12 -0
  120. package/dist/StatisticalTest/Paired5x2t.js.map +1 -1
  121. package/dist/StatisticalTest/PairedTest.d.ts +12 -0
  122. package/dist/StatisticalTest/PairedTest.js +12 -0
  123. package/dist/StatisticalTest/PairedTest.js.map +1 -1
  124. package/dist/StatisticalTest/Pairedt.d.ts +12 -0
  125. package/dist/StatisticalTest/Pairedt.js +12 -0
  126. package/dist/StatisticalTest/Pairedt.js.map +1 -1
  127. package/dist/StatisticalTest/Sign.d.ts +17 -0
  128. package/dist/StatisticalTest/Sign.js +17 -0
  129. package/dist/StatisticalTest/Sign.js.map +1 -1
  130. package/dist/StatisticalTest/StatisticalTestResult.d.ts +30 -0
  131. package/dist/StatisticalTest/StatisticalTestResult.js +30 -0
  132. package/dist/StatisticalTest/StatisticalTestResult.js.map +1 -1
  133. package/dist/index.d.ts +88 -0
  134. package/dist/index.js +111 -0
  135. package/dist/index.js.map +1 -0
  136. package/models/bagging-bupa.txt +10346 -0
  137. package/models/bagging-car.txt +40752 -0
  138. package/models/bagging-dermatology.txt +2990 -0
  139. package/models/bagging-iris.txt +1332 -0
  140. package/models/bagging-tictactoe.txt +29442 -0
  141. package/models/c45-bupa.txt +3 -0
  142. package/models/c45-car.txt +212 -0
  143. package/models/c45-carIndexed.txt +92 -0
  144. package/models/c45-dermatology.txt +22 -0
  145. package/models/c45-iris.txt +7 -0
  146. package/models/c45-tictactoe.txt +147 -0
  147. package/models/c45-tictactoeIndexed.txt +79 -0
  148. package/models/c45stump-bupa.txt +6 -0
  149. package/models/c45stump-car.txt +11 -0
  150. package/models/c45stump-chess.txt +35 -0
  151. package/models/c45stump-dermatology.txt +11 -0
  152. package/models/c45stump-iris.txt +5 -0
  153. package/models/c45stump-nursery.txt +10 -0
  154. package/models/c45stump-tictactoe.txt +9 -0
  155. package/models/randomforest-bupa.txt +10346 -0
  156. package/models/randomforest-car.txt +40752 -0
  157. package/models/randomforest-carIndexed.txt +15594 -0
  158. package/models/randomforest-dermatology.txt +2990 -0
  159. package/models/randomforest-iris.txt +1332 -0
  160. package/models/randomforest-tictactoe.txt +29442 -0
  161. package/package.json +7 -7
  162. package/source/Attribute/DiscreteAttribute.ts +1 -1
  163. package/source/Attribute/DiscreteIndexedAttribute.ts +2 -2
  164. package/source/DataSet/DataDefinition.ts +11 -0
  165. package/source/Experiment/BootstrapRun.ts +2 -2
  166. package/source/Experiment/Experiment.ts +10 -10
  167. package/source/Experiment/KFoldRun.ts +20 -5
  168. package/source/Experiment/KFoldRunSeparateTest.ts +16 -5
  169. package/source/Experiment/MxKFoldRun.ts +1 -1
  170. package/source/Experiment/MxKFoldRunSeparateTest.ts +1 -1
  171. package/source/Experiment/SingleRunWithK.ts +20 -5
  172. package/source/Experiment/StratifiedKFoldRun.ts +1 -1
  173. package/source/Experiment/StratifiedKFoldRunSeparateTest.ts +1 -1
  174. package/source/Experiment/StratifiedMxKFoldRun.ts +1 -1
  175. package/source/Experiment/StratifiedMxKFoldRunSeparateTest.ts +3 -3
  176. package/source/Experiment/StratifiedSingleRunWithK.ts +1 -1
  177. package/source/Filter/LaryFilter.ts +1 -1
  178. package/source/Filter/TrainedFeatureFilter.ts +1 -1
  179. package/source/InstanceList/Partition.ts +125 -65
  180. package/source/Model/DecisionTree/DecisionCondition.ts +8 -0
  181. package/source/Model/DecisionTree/DecisionNode.ts +65 -22
  182. package/source/Model/DecisionTree/DecisionStump.ts +26 -0
  183. package/source/Model/DecisionTree/DecisionTree.ts +44 -15
  184. package/source/Model/DummyModel.ts +40 -19
  185. package/source/{Classifier/Bagging.ts → Model/Ensemble/BaggingModel.ts} +15 -12
  186. package/source/{Classifier/RandomForest.ts → Model/Ensemble/RandomForestModel.ts} +14 -12
  187. package/source/Model/{TreeEnsembleModel.ts → Ensemble/TreeEnsembleModel.ts} +26 -18
  188. package/source/Model/Model.ts +92 -0
  189. package/source/Model/{DeepNetworkModel.ts → NeuralNetwork/DeepNetworkModel.ts} +59 -56
  190. package/source/Model/NeuralNetwork/LinearPerceptronModel.ts +81 -0
  191. package/source/Model/{MultiLayerPerceptronModel.ts → NeuralNetwork/MultiLayerPerceptronModel.ts} +46 -39
  192. package/source/Model/{NeuralNetworkModel.ts → NeuralNetwork/NeuralNetworkModel.ts} +20 -7
  193. package/source/Model/{KnnInstance.ts → NonParametric/KnnInstance.ts} +1 -1
  194. package/source/Model/{KnnModel.ts → NonParametric/KnnModel.ts} +48 -19
  195. package/source/Model/{GaussianModel.ts → Parametric/GaussianModel.ts} +21 -3
  196. package/source/Model/Parametric/KMeansModel.ts +72 -0
  197. package/source/Model/Parametric/LdaModel.ts +98 -0
  198. package/source/Model/{NaiveBayesModel.ts → Parametric/NaiveBayesModel.ts} +68 -25
  199. package/source/Model/Parametric/QdaModel.ts +83 -0
  200. package/source/Model/RandomModel.ts +54 -16
  201. package/source/Parameter/C45Parameter.ts +2 -2
  202. package/source/Parameter/DeepNetworkParameter.ts +2 -2
  203. package/source/Parameter/KnnParameter.ts +1 -1
  204. package/source/Parameter/LinearPerceptronParameter.ts +4 -4
  205. package/source/Parameter/MultiLayerPerceptronParameter.ts +2 -2
  206. package/source/Parameter/Parameter.ts +1 -1
  207. package/source/Performance/ConfusionMatrix.ts +1 -1
  208. package/source/StatisticalTest/Combined5x2F.ts +12 -0
  209. package/source/StatisticalTest/Combined5x2t.ts +13 -0
  210. package/source/StatisticalTest/Paired5x2t.ts +12 -0
  211. package/source/StatisticalTest/PairedTest.ts +12 -0
  212. package/source/StatisticalTest/Pairedt.ts +12 -0
  213. package/source/StatisticalTest/Sign.ts +17 -0
  214. package/source/StatisticalTest/StatisticalTestResult.ts +30 -0
  215. package/source/index.ts +88 -0
  216. package/source/tsconfig.json +1 -1
  217. package/tests/Classifier/C45Test.ts +2 -2
  218. package/tests/Classifier/DeepNetworkTest.ts +3 -5
  219. package/tests/Classifier/DummyTest.ts +2 -2
  220. package/tests/Classifier/KMeansTest.ts +2 -2
  221. package/tests/Classifier/KnnTest.ts +2 -2
  222. package/tests/Classifier/LdaTest.ts +2 -2
  223. package/tests/Classifier/LinearPerceptronTest.ts +2 -2
  224. package/tests/Classifier/MultiLayerPerceptronTest.ts +2 -3
  225. package/tests/Classifier/NaiveBayesTest.ts +2 -2
  226. package/tests/Classifier/QdaTest.ts +2 -2
  227. package/tests/Classifier/RandomForestTest.ts +2 -2
  228. package/tsconfig.json +1 -2
  229. package/dist/Classifier/Bagging.js.map +0 -1
  230. package/dist/Classifier/C45.d.ts +0 -14
  231. package/dist/Classifier/C45.js +0 -43
  232. package/dist/Classifier/C45.js.map +0 -1
  233. package/dist/Classifier/C45Stump.d.ts +0 -13
  234. package/dist/Classifier/C45Stump.js.map +0 -1
  235. package/dist/Classifier/Classifier.d.ts +0 -40
  236. package/dist/Classifier/Classifier.js +0 -72
  237. package/dist/Classifier/Classifier.js.map +0 -1
  238. package/dist/Classifier/DeepNetwork.d.ts +0 -14
  239. package/dist/Classifier/DeepNetwork.js +0 -34
  240. package/dist/Classifier/DeepNetwork.js.map +0 -1
  241. package/dist/Classifier/Dummy.d.ts +0 -14
  242. package/dist/Classifier/Dummy.js +0 -32
  243. package/dist/Classifier/Dummy.js.map +0 -1
  244. package/dist/Classifier/KMeans.d.ts +0 -13
  245. package/dist/Classifier/KMeans.js +0 -39
  246. package/dist/Classifier/KMeans.js.map +0 -1
  247. package/dist/Classifier/Knn.d.ts +0 -14
  248. package/dist/Classifier/Knn.js +0 -32
  249. package/dist/Classifier/Knn.js.map +0 -1
  250. package/dist/Classifier/Lda.d.ts +0 -13
  251. package/dist/Classifier/Lda.js +0 -55
  252. package/dist/Classifier/Lda.js.map +0 -1
  253. package/dist/Classifier/LinearPerceptron.d.ts +0 -15
  254. package/dist/Classifier/LinearPerceptron.js +0 -35
  255. package/dist/Classifier/LinearPerceptron.js.map +0 -1
  256. package/dist/Classifier/MultiLayerPerceptron.d.ts +0 -15
  257. package/dist/Classifier/MultiLayerPerceptron.js +0 -35
  258. package/dist/Classifier/MultiLayerPerceptron.js.map +0 -1
  259. package/dist/Classifier/NaiveBayes.d.ts +0 -26
  260. package/dist/Classifier/NaiveBayes.js +0 -70
  261. package/dist/Classifier/NaiveBayes.js.map +0 -1
  262. package/dist/Classifier/Qda.d.ts +0 -13
  263. package/dist/Classifier/Qda.js +0 -53
  264. package/dist/Classifier/Qda.js.map +0 -1
  265. package/dist/Classifier/RandomClassifier.d.ts +0 -13
  266. package/dist/Classifier/RandomClassifier.js +0 -35
  267. package/dist/Classifier/RandomClassifier.js.map +0 -1
  268. package/dist/Classifier/RandomForest.js.map +0 -1
  269. package/dist/Model/DeepNetworkModel.d.ts +0 -45
  270. package/dist/Model/DeepNetworkModel.js.map +0 -1
  271. package/dist/Model/GaussianModel.js.map +0 -1
  272. package/dist/Model/KMeansModel.d.ts +0 -28
  273. package/dist/Model/KMeansModel.js +0 -61
  274. package/dist/Model/KMeansModel.js.map +0 -1
  275. package/dist/Model/KnnInstance.js.map +0 -1
  276. package/dist/Model/KnnModel.js.map +0 -1
  277. package/dist/Model/LdaModel.d.ts +0 -28
  278. package/dist/Model/LdaModel.js +0 -67
  279. package/dist/Model/LdaModel.js.map +0 -1
  280. package/dist/Model/LinearPerceptronModel.d.ts +0 -24
  281. package/dist/Model/LinearPerceptronModel.js +0 -91
  282. package/dist/Model/LinearPerceptronModel.js.map +0 -1
  283. package/dist/Model/MultiLayerPerceptronModel.d.ts +0 -33
  284. package/dist/Model/MultiLayerPerceptronModel.js.map +0 -1
  285. package/dist/Model/NaiveBayesModel.js.map +0 -1
  286. package/dist/Model/NeuralNetworkModel.js.map +0 -1
  287. package/dist/Model/QdaModel.d.ts +0 -27
  288. package/dist/Model/QdaModel.js +0 -63
  289. package/dist/Model/QdaModel.js.map +0 -1
  290. package/dist/Model/TreeEnsembleModel.d.ts +0 -22
  291. package/dist/Model/TreeEnsembleModel.js.map +0 -1
  292. package/index.js +0 -100
  293. package/source/Classifier/C45.ts +0 -34
  294. package/source/Classifier/C45Stump.ts +0 -23
  295. package/source/Classifier/Classifier.ts +0 -72
  296. package/source/Classifier/DeepNetwork.ts +0 -26
  297. package/source/Classifier/Dummy.ts +0 -23
  298. package/source/Classifier/KMeans.ts +0 -30
  299. package/source/Classifier/Knn.ts +0 -25
  300. package/source/Classifier/Lda.ts +0 -47
  301. package/source/Classifier/LinearPerceptron.ts +0 -27
  302. package/source/Classifier/MultiLayerPerceptron.ts +0 -27
  303. package/source/Classifier/NaiveBayes.ts +0 -66
  304. package/source/Classifier/Qda.ts +0 -46
  305. package/source/Classifier/RandomClassifier.ts +0 -26
  306. package/source/Model/KMeansModel.ts +0 -56
  307. package/source/Model/LdaModel.ts +0 -62
  308. package/source/Model/LinearPerceptronModel.ts +0 -83
  309. package/source/Model/QdaModel.ts +0 -57
  310. /package/dist/Model/{KnnInstance.js → NonParametric/KnnInstance.js} +0 -0
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "nlptoolkit-classification",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Classification Library",
5
- "main": "index.js",
6
- "types": "index.js",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
7
  "scripts": {
8
8
  "test": "Mocha"
9
9
  },
@@ -24,9 +24,9 @@
24
24
  "typescript": "^4.5.4"
25
25
  },
26
26
  "dependencies": {
27
- "nlptoolkit-datastructure": "^1.0.4",
28
- "nlptoolkit-math": "^1.0.3",
29
- "nlptoolkit-sampling": "^1.0.2",
30
- "nlptoolkit-util": "^1.0.8"
27
+ "nlptoolkit-datastructure": "^1.0.8",
28
+ "nlptoolkit-math": "^1.0.5",
29
+ "nlptoolkit-sampling": "^1.0.4",
30
+ "nlptoolkit-util": "^1.0.11"
31
31
  }
32
32
  }
@@ -2,7 +2,7 @@ import {Attribute} from "./Attribute";
2
2
 
3
3
  export class DiscreteAttribute extends Attribute{
4
4
 
5
- private value: string = "NULL"
5
+ private readonly value: string = "NULL"
6
6
 
7
7
  /**
8
8
  * Constructor for a discrete attribute.
@@ -2,8 +2,8 @@ import {DiscreteAttribute} from "./DiscreteAttribute";
2
2
 
3
3
  export class DiscreteIndexedAttribute extends DiscreteAttribute{
4
4
 
5
- private index: number
6
- private maxIndex: number
5
+ private readonly index: number
6
+ private readonly maxIndex: number
7
7
 
8
8
  /**
9
9
  * Constructor for a discrete attribute.
@@ -21,10 +21,21 @@ export class DataDefinition {
21
21
  }
22
22
  }
23
23
 
24
+ /**
25
+ * Returns number of distinct values for a given discrete attribute with index attributeIndex.
26
+ * @param attributeIndex Index of the discrete attribute.
27
+ * @return Number of distinct values for a given discrete attribute
28
+ */
24
29
  numberOfValues(attributeIndex: number): number{
25
30
  return this.attributeValueList[attributeIndex].length
26
31
  }
27
32
 
33
+ /**
34
+ * Returns the index of the given value in the values list of the attributeIndex'th discrete attribute.
35
+ * @param attributeIndex Index of the discrete attribute.
36
+ * @param value Value of the discrete attribute
37
+ * @return Index of the given value in the values list of the discrete attribute.
38
+ */
28
39
  featureValueIndex(attributeIndex: number, value: String): number{
29
40
  for (let i = 0; i < this.attributeValueList[attributeIndex].length; i++){
30
41
  if (this.attributeValueList[attributeIndex][i] == value){
@@ -29,8 +29,8 @@ export class BootstrapRun implements MultipleRun{
29
29
  for (let i = 0; i < this.numberOfBootstraps; i++) {
30
30
  let bootstrap = new Bootstrap<Instance>(experiment.getDataSet().getInstances(), i + experiment.getParameter().getSeed());
31
31
  let bootstrapSample = new InstanceList(bootstrap.getSample());
32
- experiment.getClassifier().train(bootstrapSample, experiment.getParameter());
33
- result.add(experiment.getClassifier().test(experiment.getDataSet().getInstanceList()));
32
+ experiment.getmodel().train(bootstrapSample, experiment.getParameter());
33
+ result.add(experiment.getmodel().test(experiment.getDataSet().getInstanceList()));
34
34
  }
35
35
  return result;
36
36
  }
@@ -1,22 +1,22 @@
1
- import {Classifier} from "../Classifier/Classifier";
2
1
  import {Parameter} from "../Parameter/Parameter";
3
2
  import {DataSet} from "../DataSet/DataSet";
4
3
  import {FeatureSubSet} from "../FeatureSelection/FeatureSubSet";
4
+ import {Model} from "../Model/Model";
5
5
 
6
6
  export class Experiment {
7
7
 
8
- private classifier: Classifier
9
- private parameter: Parameter
10
- private dataSet: DataSet
8
+ private readonly model: Model
9
+ private readonly parameter: Parameter
10
+ private readonly dataSet: DataSet
11
11
 
12
12
  /**
13
13
  * Constructor for a specific machine learning experiment
14
- * @param classifier Classifier used in the machine learning experiment
14
+ * @param model Model used in the machine learning experiment
15
15
  * @param parameter Parameter(s) of the classifier.
16
16
  * @param dataSet DataSet on which the classifier is run.
17
17
  */
18
- constructor(classifier: Classifier, parameter: Parameter, dataSet: DataSet) {
19
- this.classifier = classifier
18
+ constructor(model: Model, parameter: Parameter, dataSet: DataSet) {
19
+ this.model = model
20
20
  this.parameter = parameter
21
21
  this.dataSet = dataSet
22
22
  }
@@ -25,8 +25,8 @@ export class Experiment {
25
25
  * Accessor for the classifier attribute.
26
26
  * @return Classifier attribute.
27
27
  */
28
- getClassifier(): Classifier{
29
- return this.classifier
28
+ getmodel(): Model{
29
+ return this.model
30
30
  }
31
31
 
32
32
  /**
@@ -51,7 +51,7 @@ export class Experiment {
51
51
  * @return Experiment constructed
52
52
  */
53
53
  featureSelectedExperiment(featureSubSet: FeatureSubSet): Experiment{
54
- return new Experiment(this.classifier, this.parameter, this.dataSet.getSubSetOfFeatures(featureSubSet));
54
+ return new Experiment(this.model, this.parameter, this.dataSet.getSubSetOfFeatures(featureSubSet));
55
55
  }
56
56
 
57
57
  }
@@ -1,30 +1,45 @@
1
1
  import {MultipleRun} from "./MultipleRun";
2
2
  import {Experiment} from "./Experiment";
3
3
  import {ExperimentPerformance} from "../Performance/ExperimentPerformance";
4
- import {Classifier} from "../Classifier/Classifier";
5
4
  import {Parameter} from "../Parameter/Parameter";
6
5
  import {CrossValidation} from "nlptoolkit-sampling/dist/CrossValidation";
7
6
  import {Instance} from "../Instance/Instance";
8
7
  import {InstanceList} from "../InstanceList/InstanceList";
9
8
  import {KFoldCrossValidation} from "nlptoolkit-sampling/dist/KFoldCrossValidation";
9
+ import {Model} from "../Model/Model";
10
10
 
11
11
  export class KFoldRun implements MultipleRun{
12
12
 
13
13
  protected K: number
14
14
 
15
+ /**
16
+ * Constructor for KFoldRun class. Basically sets K parameter of the K-fold cross-validation.
17
+ *
18
+ * @param K K of the K-fold cross-validation.
19
+ */
15
20
  constructor(K: number) {
16
21
  this.K = K
17
22
  }
18
23
 
19
- protected runExperiment(classifier: Classifier,
24
+ /**
25
+ * Runs a K fold cross-validated experiment for the given classifier with the given parameters. The experiment
26
+ * results will be added to the experimentPerformance.
27
+ * @param model Model for the experiment
28
+ * @param parameter Hyperparameters of the classifier of the experiment
29
+ * @param experimentPerformance Storage to add experiment results
30
+ * @param crossValidation K-fold crossvalidated dataset.
31
+ * @throws DiscreteFeaturesNotAllowed If the classifier does not allow discrete features and the dataset contains
32
+ * discrete features, DiscreteFeaturesNotAllowed will be thrown.
33
+ */
34
+ protected runExperiment(model: Model,
20
35
  parameter: Parameter,
21
36
  experimentPerformance: ExperimentPerformance,
22
37
  crossValidation: CrossValidation<Instance>){
23
38
  for (let i = 0; i < this.K; i++) {
24
39
  let trainSet = new InstanceList(crossValidation.getTrainFold(i));
25
40
  let testSet = new InstanceList(crossValidation.getTestFold(i));
26
- classifier.train(trainSet, parameter);
27
- experimentPerformance.add(classifier.test(testSet));
41
+ model.train(trainSet, parameter);
42
+ experimentPerformance.add(model.test(testSet));
28
43
  }
29
44
  }
30
45
 
@@ -37,7 +52,7 @@ export class KFoldRun implements MultipleRun{
37
52
  execute(experiment: Experiment): ExperimentPerformance {
38
53
  let result = new ExperimentPerformance();
39
54
  let crossValidation = new KFoldCrossValidation<Instance>(experiment.getDataSet().getInstances(), this.K, experiment.getParameter().getSeed());
40
- this.runExperiment(experiment.getClassifier(), experiment.getParameter(), result, crossValidation);
55
+ this.runExperiment(experiment.getmodel(), experiment.getParameter(), result, crossValidation);
41
56
  return result;
42
57
  }
43
58
 
@@ -1,5 +1,4 @@
1
1
  import {KFoldRun} from "./KFoldRun";
2
- import {Classifier} from "../Classifier/Classifier";
3
2
  import {Parameter} from "../Parameter/Parameter";
4
3
  import {ExperimentPerformance} from "../Performance/ExperimentPerformance";
5
4
  import {InstanceList} from "../InstanceList/InstanceList";
@@ -8,6 +7,7 @@ import {Instance} from "../Instance/Instance";
8
7
  import {Experiment} from "./Experiment";
9
8
  import {KFoldCrossValidation} from "nlptoolkit-sampling/dist/KFoldCrossValidation";
10
9
  import {Partition} from "../InstanceList/Partition";
10
+ import {Model} from "../Model/Model";
11
11
 
12
12
  export class KFoldRunSeparateTest extends KFoldRun{
13
13
 
@@ -20,15 +20,26 @@ export class KFoldRunSeparateTest extends KFoldRun{
20
20
  super(K);
21
21
  }
22
22
 
23
- protected runExperiment(classifier: Classifier,
23
+ /**
24
+ * Runs a K fold cross-validated experiment for the given classifier with the given parameters. Testing will be
25
+ * done on the separate test set. The experiment results will be added to the experimentPerformance.
26
+ * @param model Model for the experiment
27
+ * @param parameter Hyperparameters of the classifier of the experiment
28
+ * @param experimentPerformance Storage to add experiment results
29
+ * @param crossValidation K-fold crossvalidated dataset.
30
+ * @param testSet Test set on which experiment performance is calculated.
31
+ * @throws DiscreteFeaturesNotAllowed If the classifier does not allow discrete features and the dataset contains
32
+ * discrete features, DiscreteFeaturesNotAllowed will be thrown.
33
+ */
34
+ protected runExperiment(model: Model,
24
35
  parameter: Parameter,
25
36
  experimentPerformance: ExperimentPerformance,
26
37
  crossValidation: CrossValidation<Instance>,
27
38
  testSet?: InstanceList) {
28
39
  for (let i = 0; i < this.K; i++) {
29
40
  let trainSet = new InstanceList(crossValidation.getTrainFold(i));
30
- classifier.train(trainSet, parameter);
31
- experimentPerformance.add(classifier.test(testSet));
41
+ model.train(trainSet, parameter);
42
+ experimentPerformance.add(model.test(testSet));
32
43
  }
33
44
  }
34
45
 
@@ -43,7 +54,7 @@ export class KFoldRunSeparateTest extends KFoldRun{
43
54
  let instanceList = experiment.getDataSet().getInstanceList();
44
55
  let partition = new Partition(instanceList, 0.25, true);
45
56
  let crossValidation = new KFoldCrossValidation<Instance>(partition.get(1).getInstances(), this.K, experiment.getParameter().getSeed());
46
- this.runExperiment(experiment.getClassifier(), experiment.getParameter(), result, crossValidation, partition.get(0));
57
+ this.runExperiment(experiment.getmodel(), experiment.getParameter(), result, crossValidation, partition.get(0));
47
58
  return result;
48
59
  }
49
60
 
@@ -29,7 +29,7 @@ export class MxKFoldRun extends KFoldRun{
29
29
  let result = new ExperimentPerformance();
30
30
  for (let j = 0; j < this.M; j++) {
31
31
  let crossValidation = new KFoldCrossValidation<Instance>(experiment.getDataSet().getInstances(), this.K, experiment.getParameter().getSeed());
32
- this.runExperiment(experiment.getClassifier(), experiment.getParameter(), result, crossValidation);
32
+ this.runExperiment(experiment.getmodel(), experiment.getParameter(), result, crossValidation);
33
33
  }
34
34
  return result;
35
35
  }
@@ -33,7 +33,7 @@ export class MxKFoldRunSeparateTest extends KFoldRunSeparateTest{
33
33
  let partition = new Partition(instanceList, 0.25, true);
34
34
  for (let j = 0; j < this.M; j++) {
35
35
  let crossValidation = new KFoldCrossValidation<Instance>(partition.get(1).getInstances(), this.K, experiment.getParameter().getSeed());
36
- this.runExperiment(experiment.getClassifier(), experiment.getParameter(), result, crossValidation, partition.get(0));
36
+ this.runExperiment(experiment.getmodel(), experiment.getParameter(), result, crossValidation, partition.get(0));
37
37
  }
38
38
  return result;
39
39
  }
@@ -4,24 +4,39 @@ import {KFoldCrossValidation} from "nlptoolkit-sampling/dist/KFoldCrossValidatio
4
4
  import {Instance} from "../Instance/Instance";
5
5
  import {Performance} from "../Performance/Performance";
6
6
  import {InstanceList} from "../InstanceList/InstanceList";
7
- import {Classifier} from "../Classifier/Classifier";
8
7
  import {Parameter} from "../Parameter/Parameter";
9
8
  import {CrossValidation} from "nlptoolkit-sampling/dist/CrossValidation";
9
+ import {Model} from "../Model/Model";
10
10
 
11
11
  export class SingleRunWithK implements SingleRun{
12
12
 
13
- private K: number
13
+ private readonly K: number
14
14
 
15
+ /**
16
+ * Constructor for SingleRunWithK class. Basically sets K parameter of the K-fold cross-validation.
17
+ *
18
+ * @param K K of the K-fold cross-validation.
19
+ */
15
20
  constructor(K: number) {
16
21
  this.K = K
17
22
  }
18
23
 
19
- runExperiment(classifier: Classifier,
24
+ /**
25
+ * Runs first fold of a K fold cross-validated experiment for the given classifier with the given parameters.
26
+ * The experiment result will be returned.
27
+ * @param model Classifier for the experiment
28
+ * @param parameter Hyperparameters of the classifier of the experiment
29
+ * @param crossValidation K-fold crossvalidated dataset.
30
+ * @return The experiment result of the first fold of the K-fold cross-validated experiment.
31
+ * @throws DiscreteFeaturesNotAllowed If the classifier does not allow discrete features and the dataset contains
32
+ * discrete features, DiscreteFeaturesNotAllowed will be thrown.
33
+ */
34
+ runExperiment(model: Model,
20
35
  parameter: Parameter,
21
36
  crossValidation: CrossValidation<Instance>){
22
37
  let trainSet = new InstanceList(crossValidation.getTrainFold(0));
23
38
  let testSet = new InstanceList(crossValidation.getTestFold(0));
24
- return classifier.singleRun(parameter, trainSet, testSet);
39
+ return model.singleRun(parameter, trainSet, testSet);
25
40
  }
26
41
 
27
42
  /**
@@ -33,7 +48,7 @@ export class SingleRunWithK implements SingleRun{
33
48
  execute(experiment: Experiment): Performance {
34
49
  let crossValidation = new KFoldCrossValidation<Instance>(experiment.getDataSet().getInstances(), this.K,
35
50
  experiment.getParameter().getSeed());
36
- return this.runExperiment(experiment.getClassifier(), experiment.getParameter(), crossValidation);
51
+ return this.runExperiment(experiment.getmodel(), experiment.getParameter(), crossValidation);
37
52
  }
38
53
 
39
54
  }
@@ -23,7 +23,7 @@ export class StratifiedKFoldRun extends KFoldRun{
23
23
  execute(experiment: Experiment): ExperimentPerformance {
24
24
  let result = new ExperimentPerformance();
25
25
  let crossValidation = new StratifiedKFoldCrossValidation<Instance>(experiment.getDataSet().getClassInstances(), this.K, experiment.getParameter().getSeed());
26
- this.runExperiment(experiment.getClassifier(), experiment.getParameter(), result, crossValidation);
26
+ this.runExperiment(experiment.getmodel(), experiment.getParameter(), result, crossValidation);
27
27
  return result;
28
28
  }
29
29
 
@@ -27,7 +27,7 @@ export class StratifiedKFoldRunSeparateTest extends KFoldRunSeparateTest{
27
27
  let instanceList = experiment.getDataSet().getInstanceList();
28
28
  let partition = new Partition(instanceList, 0.25, true);
29
29
  let crossValidation = new StratifiedKFoldCrossValidation<Instance>(new Partition(partition.get(1)).getLists(), this.K, experiment.getParameter().getSeed());
30
- this.runExperiment(experiment.getClassifier(), experiment.getParameter(), result, crossValidation, partition.get(0));
30
+ this.runExperiment(experiment.getmodel(), experiment.getParameter(), result, crossValidation, partition.get(0));
31
31
  return result;
32
32
  }
33
33
  }
@@ -27,7 +27,7 @@ export class StratifiedMxKFoldRun extends MxKFoldRun{
27
27
  for (let j = 0; j < this.M; j++) {
28
28
  let crossValidation = new StratifiedKFoldCrossValidation<Instance>(experiment.getDataSet().getClassInstances(),
29
29
  this.K, experiment.getParameter().getSeed());
30
- this.runExperiment(experiment.getClassifier(), experiment.getParameter(), result, crossValidation);
30
+ this.runExperiment(experiment.getmodel(), experiment.getParameter(), result, crossValidation);
31
31
  }
32
32
  return result;
33
33
  }
@@ -28,12 +28,12 @@ export class StratifiedMxKFoldRunSeparateTest extends StratifiedKFoldRunSeparate
28
28
  */
29
29
  execute(experiment: Experiment): ExperimentPerformance {
30
30
  let result = new ExperimentPerformance();
31
+ let instanceList = experiment.getDataSet().getInstanceList();
32
+ let partition = new Partition(instanceList, 0.25, true);
31
33
  for (let j = 0; j < this.M; j++) {
32
- let instanceList = experiment.getDataSet().getInstanceList();
33
- let partition = new Partition(instanceList, 0.25, true);
34
34
  let crossValidation = new StratifiedKFoldCrossValidation<Instance>(new Partition(partition.get(1)).getLists(),
35
35
  this.K, experiment.getParameter().getSeed());
36
- this.runExperiment(experiment.getClassifier(), experiment.getParameter(), result, crossValidation, partition.get(0));
36
+ this.runExperiment(experiment.getmodel(), experiment.getParameter(), result, crossValidation, partition.get(0));
37
37
  }
38
38
  return result;
39
39
  }
@@ -28,6 +28,6 @@ export class StratifiedSingleRunWithK {
28
28
  this.K, experiment.getParameter().getSeed());
29
29
  let trainSet = new InstanceList(crossValidation.getTrainFold(0));
30
30
  let testSet = new InstanceList(crossValidation.getTestFold(0));
31
- return experiment.getClassifier().singleRun(experiment.getParameter(), trainSet, testSet);
31
+ return experiment.getmodel().singleRun(experiment.getParameter(), trainSet, testSet);
32
32
  }
33
33
  }
@@ -10,7 +10,7 @@ export abstract class LaryFilter extends FeatureFilter{
10
10
  /**
11
11
  * Constructor that sets the dataSet and all the attributes distributions.
12
12
  *
13
- * @param dataSet DataSet that will bu used.
13
+ * @param dataSet DataSet that will be used.
14
14
  */
15
15
  constructor(dataSet: DataSet) {
16
16
  super(dataSet);
@@ -8,7 +8,7 @@ export abstract class TrainedFeatureFilter extends FeatureFilter{
8
8
  /**
9
9
  * Constructor that sets the dataSet.
10
10
  *
11
- * @param dataSet DataSet that will bu used.
11
+ * @param dataSet DataSet that will be used.
12
12
  */
13
13
  constructor(dataSet: DataSet) {
14
14
  super(dataSet);
@@ -10,81 +10,141 @@ export class Partition {
10
10
 
11
11
  private multiList: Array<InstanceList> = new Array<InstanceList>()
12
12
 
13
+ /**
14
+ * Divides the instances in the instance list into partitions so that all instances of a class are grouped in a
15
+ * single partition.
16
+ * @param instanceList Instance list for which partition will be created.
17
+ */
18
+ constructor1(instanceList: InstanceList){
19
+ let classLabels = instanceList.getDistinctClassLabels();
20
+ for (let classLabel of classLabels){
21
+ this.add(new InstanceListOfSameClass(classLabel));
22
+ }
23
+ for (let instance of instanceList.getInstances()) {
24
+ this.get(classLabels.indexOf(instance.getClassLabel())).add(instance);
25
+ }
26
+ }
27
+
28
+ /**
29
+ * Creates a partition depending on the distinct values of a discrete attribute. If the discrete attribute has 4
30
+ * distinct values, the resulting partition will have 4 groups, where each group contain instance whose
31
+ * values of that discrete attribute are the same.
32
+ *
33
+ * @param instanceList Instance list for which partition will be created.
34
+ * @param attributeIndex Index of the discrete attribute.
35
+ */
36
+ constructor2(instanceList: InstanceList, attributeIndex: number){
37
+ let valueList = instanceList.getAttributeValueList(attributeIndex);
38
+ for (let value of valueList) {
39
+ this.add(new InstanceList());
40
+ }
41
+ for (let instance of instanceList.getInstances()) {
42
+ this.get(valueList.indexOf((<DiscreteAttribute> instance.getAttribute(attributeIndex)).getValue())).add(instance);
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Creates a stratified partition of the current instance list. In a stratified partition, the percentage of each
48
+ * class is preserved. For example, let's say there are three classes in the instance list, and let the percentages of
49
+ * these classes be %20, %30, and %50; then the percentages of these classes in the stratified partitions are the
50
+ * same, that is, %20, %30, and %50.
51
+ *
52
+ * @param instanceList Instance list for which partition will be created.
53
+ * @param ratio Ratio of the stratified partition. Ratio is between 0 and 1. If the ratio is 0.2, then 20 percent
54
+ * of the instances are put in the first group, 80 percent of the instances are put in the second group.
55
+ * @param random random is used as a random number.
56
+ * @param stratified If true, stratified partition is obtained.
57
+ */
58
+ constructor3(instanceList: InstanceList, ratio: number, random: Random, stratified: boolean){
59
+ this.add(new InstanceList());
60
+ this.add(new InstanceList());
61
+ if (stratified){
62
+ let distribution = instanceList.classDistribution();
63
+ let counts = new Array<number>(distribution.size).fill(0)
64
+ let randomArray = new Array<number>()
65
+ for (let i = 0; i < instanceList.size(); i++){
66
+ randomArray.push(i);
67
+ }
68
+ if (random != undefined){
69
+ random.shuffle(randomArray)
70
+ }
71
+ for (let i = 0; i < instanceList.size(); i++) {
72
+ let instance = instanceList.get(randomArray[i]);
73
+ let classIndex = distribution.getIndex(instance.getClassLabel());
74
+ if (counts[classIndex] < instanceList.size() * ratio * distribution.getProbability(instance.getClassLabel())) {
75
+ this.get(0).add(instance);
76
+ } else {
77
+ this.get(1).add(instance);
78
+ }
79
+ counts[classIndex]++;
80
+ }
81
+ } else {
82
+ instanceList.shuffle(random)
83
+ for (let i = 0; i < instanceList.size(); i++) {
84
+ let instance = instanceList.get(i);
85
+ if (i < instanceList.size() * ratio) {
86
+ this.get(0).add(instance);
87
+ } else {
88
+ this.get(1).add(instance);
89
+ }
90
+ }
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Creates a partition depending on the distinct values of a discrete indexed attribute.
96
+ *
97
+ * @param instanceList Instance list for which partition will be created.
98
+ * @param attributeIndex Index of the discrete indexed attribute.
99
+ * @param attributeValue Value of the attribute.
100
+ */
101
+ constructor4(instanceList: InstanceList, attributeIndex: number, attributeValue: number){
102
+ this.add(new InstanceList());
103
+ this.add(new InstanceList());
104
+ for (let instance of instanceList.getInstances()) {
105
+ if ((<DiscreteIndexedAttribute> instance.getAttribute(attributeIndex)).getIndex() == attributeValue) {
106
+ this.get(0).add(instance);
107
+ } else {
108
+ this.get(1).add(instance);
109
+ }
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Creates a two group partition depending on the values of a continuous attribute. If the value of the attribute is
115
+ * less than splitValue, the instance is forwarded to the first group, else it is forwarded to the second group.
116
+ *
117
+ * @param instanceList Instance list for which partition will be created.
118
+ * @param attributeIndex Index of the continuous attribute
119
+ * @param splitValue Threshold to divide instances
120
+ */
121
+ constructor5(instanceList: InstanceList, attributeIndex: number, splitValue: number){
122
+ this.add(new InstanceList());
123
+ this.add(new InstanceList());
124
+ for (let instance of instanceList.getInstances()) {
125
+ if ((<ContinuousAttribute> instance.getAttribute(attributeIndex)).getValue() <= splitValue) {
126
+ this.get(0).add(instance);
127
+ } else {
128
+ this.get(1).add(instance);
129
+ }
130
+ }
131
+ }
132
+
13
133
  constructor(instanceList?: InstanceList, attributeIndex?: number, stratifiedOrValue?: any, random?: Random) {
14
134
  if (instanceList != undefined){
15
135
  if (attributeIndex == undefined){
16
- let classLabels = instanceList.getDistinctClassLabels();
17
- for (let classLabel of classLabels){
18
- this.add(new InstanceListOfSameClass(classLabel));
19
- }
20
- for (let instance of instanceList.getInstances()) {
21
- this.get(classLabels.indexOf(instance.getClassLabel())).add(instance);
22
- }
136
+ this.constructor1(instanceList);
23
137
  } else {
24
138
  if (stratifiedOrValue == undefined){
25
- let valueList = instanceList.getAttributeValueList(attributeIndex);
26
- for (let value of valueList) {
27
- this.add(new InstanceList());
28
- }
29
- for (let instance of instanceList.getInstances()) {
30
- this.get(valueList.indexOf((<DiscreteAttribute> instance.getAttribute(attributeIndex)).getValue())).add(instance);
31
- }
139
+ this.constructor2(instanceList, attributeIndex)
32
140
  } else {
33
141
  if (typeof stratifiedOrValue == "boolean"){
34
- this.add(new InstanceList());
35
- this.add(new InstanceList());
36
- if (stratifiedOrValue){
37
- let distribution = instanceList.classDistribution();
38
- let counts = new Array<number>(distribution.size).fill(0)
39
- let randomArray = new Array<number>()
40
- for (let i = 0; i < instanceList.size(); i++){
41
- randomArray.push(i);
42
- }
43
- if (random != undefined){
44
- random.shuffle(randomArray)
45
- }
46
- for (let i = 0; i < instanceList.size(); i++) {
47
- let instance = instanceList.get(randomArray[i]);
48
- let classIndex = distribution.getIndex(instance.getClassLabel());
49
- let ratio = attributeIndex
50
- if (counts[classIndex] < instanceList.size() * ratio * distribution.getProbability(instance.getClassLabel())) {
51
- this.get(0).add(instance);
52
- } else {
53
- this.get(1).add(instance);
54
- }
55
- counts[classIndex]++;
56
- }
57
- } else {
58
- instanceList.shuffle(random)
59
- for (let i = 0; i < instanceList.size(); i++) {
60
- let instance = instanceList.get(i);
61
- let ratio = attributeIndex
62
- if (i < instanceList.size() * ratio) {
63
- this.get(0).add(instance);
64
- } else {
65
- this.get(1).add(instance);
66
- }
67
- }
68
- }
142
+ this.constructor3(instanceList, attributeIndex, random, stratifiedOrValue)
69
143
  } else {
70
- this.add(new InstanceList());
71
- this.add(new InstanceList());
72
144
  if (Number.isInteger(stratifiedOrValue)){
73
- for (let instance of instanceList.getInstances()) {
74
- if ((<DiscreteIndexedAttribute> instance.getAttribute(attributeIndex)).getIndex() == stratifiedOrValue) {
75
- this.get(0).add(instance);
76
- } else {
77
- this.get(1).add(instance);
78
- }
79
- }
145
+ this.constructor4(instanceList, attributeIndex, stratifiedOrValue);
80
146
  } else {
81
- for (let instance of instanceList.getInstances()) {
82
- if ((<ContinuousAttribute> instance.getAttribute(attributeIndex)).getValue() <= stratifiedOrValue) {
83
- this.get(0).add(instance);
84
- } else {
85
- this.get(1).add(instance);
86
- }
87
- }
147
+ this.constructor5(instanceList, attributeIndex, stratifiedOrValue);
88
148
  }
89
149
  }
90
150
  }
@@ -23,10 +23,18 @@ export class DecisionCondition {
23
23
  this.value = value;
24
24
  }
25
25
 
26
+ /**
27
+ * Accessor for the attribute index.
28
+ * @return Attribute index.
29
+ */
26
30
  getAttributeIndex(): number{
27
31
  return this.attributeIndex
28
32
  }
29
33
 
34
+ /**
35
+ * Accessor for the value.
36
+ * @return Value.
37
+ */
30
38
  getValue(): Attribute{
31
39
  return this.value
32
40
  }