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
@@ -3,6 +3,51 @@ import { Instance } from "../Instance/Instance";
3
3
  import { Random } from "nlptoolkit-util/dist/Random";
4
4
  export declare class Partition {
5
5
  private multiList;
6
+ /**
7
+ * Divides the instances in the instance list into partitions so that all instances of a class are grouped in a
8
+ * single partition.
9
+ * @param instanceList Instance list for which partition will be created.
10
+ */
11
+ constructor1(instanceList: InstanceList): void;
12
+ /**
13
+ * Creates a partition depending on the distinct values of a discrete attribute. If the discrete attribute has 4
14
+ * distinct values, the resulting partition will have 4 groups, where each group contain instance whose
15
+ * values of that discrete attribute are the same.
16
+ *
17
+ * @param instanceList Instance list for which partition will be created.
18
+ * @param attributeIndex Index of the discrete attribute.
19
+ */
20
+ constructor2(instanceList: InstanceList, attributeIndex: number): void;
21
+ /**
22
+ * Creates a stratified partition of the current instance list. In a stratified partition, the percentage of each
23
+ * class is preserved. For example, let's say there are three classes in the instance list, and let the percentages of
24
+ * these classes be %20, %30, and %50; then the percentages of these classes in the stratified partitions are the
25
+ * same, that is, %20, %30, and %50.
26
+ *
27
+ * @param instanceList Instance list for which partition will be created.
28
+ * @param ratio Ratio of the stratified partition. Ratio is between 0 and 1. If the ratio is 0.2, then 20 percent
29
+ * of the instances are put in the first group, 80 percent of the instances are put in the second group.
30
+ * @param random random is used as a random number.
31
+ * @param stratified If true, stratified partition is obtained.
32
+ */
33
+ constructor3(instanceList: InstanceList, ratio: number, random: Random, stratified: boolean): void;
34
+ /**
35
+ * Creates a partition depending on the distinct values of a discrete indexed attribute.
36
+ *
37
+ * @param instanceList Instance list for which partition will be created.
38
+ * @param attributeIndex Index of the discrete indexed attribute.
39
+ * @param attributeValue Value of the attribute.
40
+ */
41
+ constructor4(instanceList: InstanceList, attributeIndex: number, attributeValue: number): void;
42
+ /**
43
+ * Creates a two group partition depending on the values of a continuous attribute. If the value of the attribute is
44
+ * less than splitValue, the instance is forwarded to the first group, else it is forwarded to the second group.
45
+ *
46
+ * @param instanceList Instance list for which partition will be created.
47
+ * @param attributeIndex Index of the continuous attribute
48
+ * @param splitValue Threshold to divide instances
49
+ */
50
+ constructor5(instanceList: InstanceList, attributeIndex: number, splitValue: number): void;
6
51
  constructor(instanceList?: InstanceList, attributeIndex?: number, stratifiedOrValue?: any, random?: Random);
7
52
  /**
8
53
  * Adds given instance list to the list of instance lists.
@@ -17,93 +17,148 @@
17
17
  this.multiList = new Array();
18
18
  if (instanceList != undefined) {
19
19
  if (attributeIndex == undefined) {
20
- let classLabels = instanceList.getDistinctClassLabels();
21
- for (let classLabel of classLabels) {
22
- this.add(new InstanceListOfSameClass_1.InstanceListOfSameClass(classLabel));
23
- }
24
- for (let instance of instanceList.getInstances()) {
25
- this.get(classLabels.indexOf(instance.getClassLabel())).add(instance);
26
- }
20
+ this.constructor1(instanceList);
27
21
  }
28
22
  else {
29
23
  if (stratifiedOrValue == undefined) {
30
- let valueList = instanceList.getAttributeValueList(attributeIndex);
31
- for (let value of valueList) {
32
- this.add(new InstanceList_1.InstanceList());
33
- }
34
- for (let instance of instanceList.getInstances()) {
35
- this.get(valueList.indexOf(instance.getAttribute(attributeIndex).getValue())).add(instance);
36
- }
24
+ this.constructor2(instanceList, attributeIndex);
37
25
  }
38
26
  else {
39
27
  if (typeof stratifiedOrValue == "boolean") {
40
- this.add(new InstanceList_1.InstanceList());
41
- this.add(new InstanceList_1.InstanceList());
42
- if (stratifiedOrValue) {
43
- let distribution = instanceList.classDistribution();
44
- let counts = new Array(distribution.size).fill(0);
45
- let randomArray = new Array();
46
- for (let i = 0; i < instanceList.size(); i++) {
47
- randomArray.push(i);
48
- }
49
- if (random != undefined) {
50
- random.shuffle(randomArray);
51
- }
52
- for (let i = 0; i < instanceList.size(); i++) {
53
- let instance = instanceList.get(randomArray[i]);
54
- let classIndex = distribution.getIndex(instance.getClassLabel());
55
- let ratio = attributeIndex;
56
- if (counts[classIndex] < instanceList.size() * ratio * distribution.getProbability(instance.getClassLabel())) {
57
- this.get(0).add(instance);
58
- }
59
- else {
60
- this.get(1).add(instance);
61
- }
62
- counts[classIndex]++;
63
- }
64
- }
65
- else {
66
- instanceList.shuffle(random);
67
- for (let i = 0; i < instanceList.size(); i++) {
68
- let instance = instanceList.get(i);
69
- let ratio = attributeIndex;
70
- if (i < instanceList.size() * ratio) {
71
- this.get(0).add(instance);
72
- }
73
- else {
74
- this.get(1).add(instance);
75
- }
76
- }
77
- }
28
+ this.constructor3(instanceList, attributeIndex, random, stratifiedOrValue);
78
29
  }
79
30
  else {
80
- this.add(new InstanceList_1.InstanceList());
81
- this.add(new InstanceList_1.InstanceList());
82
31
  if (Number.isInteger(stratifiedOrValue)) {
83
- for (let instance of instanceList.getInstances()) {
84
- if (instance.getAttribute(attributeIndex).getIndex() == stratifiedOrValue) {
85
- this.get(0).add(instance);
86
- }
87
- else {
88
- this.get(1).add(instance);
89
- }
90
- }
32
+ this.constructor4(instanceList, attributeIndex, stratifiedOrValue);
91
33
  }
92
34
  else {
93
- for (let instance of instanceList.getInstances()) {
94
- if (instance.getAttribute(attributeIndex).getValue() <= stratifiedOrValue) {
95
- this.get(0).add(instance);
96
- }
97
- else {
98
- this.get(1).add(instance);
99
- }
100
- }
35
+ this.constructor5(instanceList, attributeIndex, stratifiedOrValue);
101
36
  }
102
37
  }
103
38
  }
104
39
  }
105
40
  }
106
41
  }
42
+ /**
43
+ * Divides the instances in the instance list into partitions so that all instances of a class are grouped in a
44
+ * single partition.
45
+ * @param instanceList Instance list for which partition will be created.
46
+ */
47
+ constructor1(instanceList) {
48
+ let classLabels = instanceList.getDistinctClassLabels();
49
+ for (let classLabel of classLabels) {
50
+ this.add(new InstanceListOfSameClass_1.InstanceListOfSameClass(classLabel));
51
+ }
52
+ for (let instance of instanceList.getInstances()) {
53
+ this.get(classLabels.indexOf(instance.getClassLabel())).add(instance);
54
+ }
55
+ }
56
+ /**
57
+ * Creates a partition depending on the distinct values of a discrete attribute. If the discrete attribute has 4
58
+ * distinct values, the resulting partition will have 4 groups, where each group contain instance whose
59
+ * values of that discrete attribute are the same.
60
+ *
61
+ * @param instanceList Instance list for which partition will be created.
62
+ * @param attributeIndex Index of the discrete attribute.
63
+ */
64
+ constructor2(instanceList, attributeIndex) {
65
+ let valueList = instanceList.getAttributeValueList(attributeIndex);
66
+ for (let value of valueList) {
67
+ this.add(new InstanceList_1.InstanceList());
68
+ }
69
+ for (let instance of instanceList.getInstances()) {
70
+ this.get(valueList.indexOf(instance.getAttribute(attributeIndex).getValue())).add(instance);
71
+ }
72
+ }
73
+ /**
74
+ * Creates a stratified partition of the current instance list. In a stratified partition, the percentage of each
75
+ * class is preserved. For example, let's say there are three classes in the instance list, and let the percentages of
76
+ * these classes be %20, %30, and %50; then the percentages of these classes in the stratified partitions are the
77
+ * same, that is, %20, %30, and %50.
78
+ *
79
+ * @param instanceList Instance list for which partition will be created.
80
+ * @param ratio Ratio of the stratified partition. Ratio is between 0 and 1. If the ratio is 0.2, then 20 percent
81
+ * of the instances are put in the first group, 80 percent of the instances are put in the second group.
82
+ * @param random random is used as a random number.
83
+ * @param stratified If true, stratified partition is obtained.
84
+ */
85
+ constructor3(instanceList, ratio, random, stratified) {
86
+ this.add(new InstanceList_1.InstanceList());
87
+ this.add(new InstanceList_1.InstanceList());
88
+ if (stratified) {
89
+ let distribution = instanceList.classDistribution();
90
+ let counts = new Array(distribution.size).fill(0);
91
+ let randomArray = new Array();
92
+ for (let i = 0; i < instanceList.size(); i++) {
93
+ randomArray.push(i);
94
+ }
95
+ if (random != undefined) {
96
+ random.shuffle(randomArray);
97
+ }
98
+ for (let i = 0; i < instanceList.size(); i++) {
99
+ let instance = instanceList.get(randomArray[i]);
100
+ let classIndex = distribution.getIndex(instance.getClassLabel());
101
+ if (counts[classIndex] < instanceList.size() * ratio * distribution.getProbability(instance.getClassLabel())) {
102
+ this.get(0).add(instance);
103
+ }
104
+ else {
105
+ this.get(1).add(instance);
106
+ }
107
+ counts[classIndex]++;
108
+ }
109
+ }
110
+ else {
111
+ instanceList.shuffle(random);
112
+ for (let i = 0; i < instanceList.size(); i++) {
113
+ let instance = instanceList.get(i);
114
+ if (i < instanceList.size() * ratio) {
115
+ this.get(0).add(instance);
116
+ }
117
+ else {
118
+ this.get(1).add(instance);
119
+ }
120
+ }
121
+ }
122
+ }
123
+ /**
124
+ * Creates a partition depending on the distinct values of a discrete indexed attribute.
125
+ *
126
+ * @param instanceList Instance list for which partition will be created.
127
+ * @param attributeIndex Index of the discrete indexed attribute.
128
+ * @param attributeValue Value of the attribute.
129
+ */
130
+ constructor4(instanceList, attributeIndex, attributeValue) {
131
+ this.add(new InstanceList_1.InstanceList());
132
+ this.add(new InstanceList_1.InstanceList());
133
+ for (let instance of instanceList.getInstances()) {
134
+ if (instance.getAttribute(attributeIndex).getIndex() == attributeValue) {
135
+ this.get(0).add(instance);
136
+ }
137
+ else {
138
+ this.get(1).add(instance);
139
+ }
140
+ }
141
+ }
142
+ /**
143
+ * Creates a two group partition depending on the values of a continuous attribute. If the value of the attribute is
144
+ * less than splitValue, the instance is forwarded to the first group, else it is forwarded to the second group.
145
+ *
146
+ * @param instanceList Instance list for which partition will be created.
147
+ * @param attributeIndex Index of the continuous attribute
148
+ * @param splitValue Threshold to divide instances
149
+ */
150
+ constructor5(instanceList, attributeIndex, splitValue) {
151
+ this.add(new InstanceList_1.InstanceList());
152
+ this.add(new InstanceList_1.InstanceList());
153
+ for (let instance of instanceList.getInstances()) {
154
+ if (instance.getAttribute(attributeIndex).getValue() <= splitValue) {
155
+ this.get(0).add(instance);
156
+ }
157
+ else {
158
+ this.get(1).add(instance);
159
+ }
160
+ }
161
+ }
107
162
  /**
108
163
  * Adds given instance list to the list of instance lists.
109
164
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Partition.js","sourceRoot":"","sources":["../../source/InstanceList/Partition.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,iDAA4C;IAC5C,uEAAkE;IAOlE,MAAa,SAAS;QAIlB,YAAY,YAA2B,EAAE,cAAuB,EAAE,iBAAuB,EAAE,MAAe;YAFlG,cAAS,GAAwB,IAAI,KAAK,EAAgB,CAAA;YAG9D,IAAI,YAAY,IAAI,SAAS,EAAC;gBAC1B,IAAI,cAAc,IAAI,SAAS,EAAC;oBAC5B,IAAI,WAAW,GAAG,YAAY,CAAC,sBAAsB,EAAE,CAAC;oBACxD,KAAK,IAAI,UAAU,IAAI,WAAW,EAAC;wBAC/B,IAAI,CAAC,GAAG,CAAC,IAAI,iDAAuB,CAAC,UAAU,CAAC,CAAC,CAAC;qBACrD;oBACD,KAAK,IAAI,QAAQ,IAAI,YAAY,CAAC,YAAY,EAAE,EAAE;wBAC9C,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;qBACzE;iBACJ;qBAAM;oBACH,IAAI,iBAAiB,IAAI,SAAS,EAAC;wBAC/B,IAAI,SAAS,GAAG,YAAY,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAA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,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;iBAC7B;aACJ;QACL,CAAC;QAwBD;;;;WAIG;QACH,GAAG,CAAC,IAAkB;YAClB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC7B,CAAC;QAED;;;;WAIG;QACH,IAAI;YACA,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAA;QAChC,CAAC;QAED;;;;;WAKG;QACH,GAAG,CAAC,KAAa;YACb,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;QAChC,CAAC;QAED;;;;WAIG;QACH,QAAQ;YACJ,IAAI,MAAM,GAAG,IAAI,KAAK,CAAkB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAC/D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAC5C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC;aACjD;YACD,OAAO,MAAM,CAAC;QAClB,CAAC;KAEJ;IA3LD,8BA2LC"}
@@ -12,7 +12,15 @@ export declare class DecisionCondition {
12
12
  * @param comparison Comparison character.
13
13
  */
14
14
  constructor(attributeIndex: number, value: Attribute, comparison?: string);
15
+ /**
16
+ * Accessor for the attribute index.
17
+ * @return Attribute index.
18
+ */
15
19
  getAttributeIndex(): number;
20
+ /**
21
+ * Accessor for the value.
22
+ * @return Value.
23
+ */
16
24
  getValue(): Attribute;
17
25
  /**
18
26
  * The satisfy method takes an {@link Instance} as an input.
@@ -28,9 +28,17 @@
28
28
  this.comparison = comparison;
29
29
  this.value = value;
30
30
  }
31
+ /**
32
+ * Accessor for the attribute index.
33
+ * @return Attribute index.
34
+ */
31
35
  getAttributeIndex() {
32
36
  return this.attributeIndex;
33
37
  }
38
+ /**
39
+ * Accessor for the value.
40
+ * @return Value.
41
+ */
34
42
  getValue() {
35
43
  return this.value;
36
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DecisionCondition.js","sourceRoot":"","sources":["../../../source/Model/DecisionTree/DecisionCondition.ts"],"names":[],"mappings":";;;;;;;;;;;;IAEA,uFAAkF;IAClF,yEAAoE;IACpE,6EAAwE;IAExE,MAAa,iBAAiB;QAM1B;;;;;;WAMG;QACH,YAAY,cAAsB,EAAE,KAAgB,EAAE,UAAmB;YAXjE,mBAAc,GAAW,CAAC,CAAC,CAAA;YAC3B,eAAU,GAAW,SAAS,CAAA;YAWlC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;YACrC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;YAC7B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACvB,CAAC;QAED,iBAAiB;YACb,OAAO,IAAI,CAAC,cAAc,CAAA;QAC9B,CAAC;QAED,QAAQ;YACJ,OAAO,IAAI,CAAC,KAAK,CAAA;QACrB,CAAC;QAED;;;;;;;;;;;;;;;WAeG;QACH,OAAO,CAAC,QAAkB;YACtB,IAAI,IAAI,CAAC,KAAK,YAAY,mDAAwB,EAAE;gBAChD,IAAgC,IAAI,CAAC,KAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,EAAE;oBAC1D,OAAmC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAE,CAAC,QAAQ,EAAE,IAAgC,IAAI,CAAC,KAAM,CAAC,QAAQ,EAAE,CAAC;iBACnJ;qBAAM;oBACH,OAAO,IAAI,CAAC;iBACf;aACJ;iBAAM;gBACH,IAAI,IAAI,CAAC,KAAK,YAAY,qCAAiB,EAAE;oBACzC,OAAO,CAAsB,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAE,CAAC,QAAQ,EAAE,IAAyB,IAAI,CAAC,KAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;iBACvI;qBAAM;oBACH,IAAI,IAAI,CAAC,K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Q,EAAE,IAAI,CAAC,CAAC,EAAE;oBAC1D,OAAmC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAE,CAAC,QAAQ,EAAE,IAAgC,IAAI,CAAC,KAAM,CAAC,QAAQ,EAAE,CAAC;iBACnJ;qBAAM;oBACH,OAAO,IAAI,CAAC;iBACf;aACJ;iBAAM;gBACH,IAAI,IAAI,CAAC,KAAK,YAAY,qCAAiB,EAAE;oBACzC,OAAO,CAAsB,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAE,CAAC,QAAQ,EAAE,IAAyB,IAAI,CAAC,KAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;iBACvI;qBAAM;oBACH,IAAI,IAAI,CAAC,KAAK,YAAY,yCAAmB,EAAE;wBAC3C,IAAI,IAAI,CAAC,UAAU,IAAI,GAAG,EAAE;4BACxB,OAA8B,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAE,CAAC,QAAQ,EAAE,IAA2B,IAAI,CAAC,KAAM,CAAC,QAAQ,EAAE,CAAC;yBACzI;6BAAM;4BACH,IAAI,IAAI,CAAC,UAAU,IAAI,GAAG,EAAE;gCACxB,OAA8B,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,cAAc,CAAE,CAAC,QAAQ,EAAE,GAA0B,IAAI,CAAC,KAAM,CAAC,QAAQ,EAAE,CAAC;6BACxI;yBACJ;qBACJ;iBACJ;aACJ;YACD,OAAO,KAAK,CAAC;QACjB,CAAC;KACJ;IA3ED,8CA2EC"}
@@ -6,11 +6,38 @@ import { FileContents } from "nlptoolkit-util/dist/FileContents";
6
6
  export declare class DecisionNode {
7
7
  children: Array<DecisionNode>;
8
8
  private EPSILON;
9
- private data;
10
9
  private classLabel;
11
10
  leaf: boolean;
12
11
  private condition;
12
+ private classLabelsDistribution;
13
+ /**
14
+ * The DecisionNode method takes {@link InstanceList} data as input and then it sets the class label parameter by finding
15
+ * the most occurred class label of given data, it then gets distinct class labels as class labels ArrayList. Later, it adds ordered
16
+ * indices to the indexList and shuffles them randomly. Then, it gets the class distribution of given data and finds the best entropy value
17
+ * of these class distribution.
18
+ * <p>
19
+ * If an attribute of given data is {@link DiscreteIndexedAttribute}, it creates a Distribution according to discrete indexed attribute class distribution
20
+ * and finds the entropy. If it is better than the last best entropy it reassigns the best entropy, best attribute and best split value according to
21
+ * the newly founded best entropy's index. At the end, it also add new distribution to the class distribution .
22
+ * <p>
23
+ * If an attribute of given data is {@link DiscreteAttribute}, it directly finds the entropy. If it is better than the last best entropy it
24
+ * reassigns the best entropy, best attribute and best split value according to the newly founded best entropy's index.
25
+ * <p>
26
+ * If an attribute of given data is {@link ContinuousAttribute}, it creates two distributions; left and right according to class distribution
27
+ * and discrete distribution respectively, and finds the entropy. If it is better than the last best entropy it reassigns the best entropy,
28
+ * best attribute and best split value according to the newly founded best entropy's index. At the end, it also add new distribution to
29
+ * the right distribution and removes from left distribution .
30
+ *
31
+ * @param data {@link InstanceList} input.
32
+ * @param condition {@link DecisionCondition} to check.
33
+ * @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
34
+ * @param isStump Refers to decision trees with only 1 splitting rule.
35
+ */
13
36
  constructor1(data: InstanceList, condition?: DecisionCondition | number, parameter?: RandomForestParameter, isStump?: boolean): void;
37
+ /**
38
+ * Reads the decision node model (as one line) from model file.
39
+ * @param contents Model file
40
+ */
14
41
  constructor2(contents: FileContents): void;
15
42
  /**
16
43
  * The DecisionNode method takes {@link InstanceList} data as input, and then it sets the class label parameter by finding
@@ -40,6 +67,7 @@ export declare class DecisionNode {
40
67
  * The entropyForDiscreteAttribute method takes an attributeIndex and creates an ArrayList of DiscreteDistribution.
41
68
  * Then loops through the distributions and calculates the total entropy.
42
69
  *
70
+ * @param data Instance list.
43
71
  * @param attributeIndex Index of the attribute.
44
72
  * @return Total entropy for the discrete attribute.
45
73
  */
@@ -48,6 +76,7 @@ export declare class DecisionNode {
48
76
  * The createChildrenForDiscreteIndexed method creates an ArrayList of DecisionNodes as children and a partition with respect to
49
77
  * indexed attribute.
50
78
  *
79
+ * @param data Instance list.
51
80
  * @param attributeIndex Index of the attribute.
52
81
  * @param attributeValue Value of the attribute.
53
82
  * @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
@@ -58,6 +87,7 @@ export declare class DecisionNode {
58
87
  * The createChildrenForDiscrete method creates an ArrayList of values, a partition with respect to attributes and an ArrayList
59
88
  * of DecisionNodes as children.
60
89
  *
90
+ * @param data Instance list.
61
91
  * @param attributeIndex Index of the attribute.
62
92
  * @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
63
93
  * @param isStump Refers to decision trees with only 1 splitting rule.
@@ -67,6 +97,7 @@ export declare class DecisionNode {
67
97
  * The createChildrenForContinuous method creates an ArrayList of DecisionNodes as children and a partition with respect to
68
98
  * continuous attribute and the given split value.
69
99
  *
100
+ * @param data Instance list.
70
101
  * @param attributeIndex Index of the attribute.
71
102
  * @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
72
103
  * @param isStump Refers to decision trees with only 1 splitting rule.
@@ -81,5 +112,12 @@ export declare class DecisionNode {
81
112
  * @return The prediction for given instance.
82
113
  */
83
114
  predict(instance: Instance): string;
115
+ /**
116
+ * Recursive method that returns the posterior probability distribution of a given instance. If the node is a leaf
117
+ * node, it returns the class label distribution, otherwise it checks in which direction (child node) this instance
118
+ * is forwarded.
119
+ * @param instance Instance for which the posterior probability distribution is calculated.
120
+ * @return Posterior probability distribution for this instance.
121
+ */
84
122
  predictProbabilityDistribution(instance: Instance): Map<string, number>;
85
123
  }
@@ -48,7 +48,6 @@
48
48
  constructor(data, condition, parameter, isStump) {
49
49
  this.children = undefined;
50
50
  this.EPSILON = 0.0000000001;
51
- this.data = undefined;
52
51
  this.classLabel = undefined;
53
52
  this.leaf = false;
54
53
  this.condition = undefined;
@@ -61,14 +60,41 @@
61
60
  }
62
61
  }
63
62
  }
63
+ /**
64
+ * The DecisionNode method takes {@link InstanceList} data as input and then it sets the class label parameter by finding
65
+ * the most occurred class label of given data, it then gets distinct class labels as class labels ArrayList. Later, it adds ordered
66
+ * indices to the indexList and shuffles them randomly. Then, it gets the class distribution of given data and finds the best entropy value
67
+ * of these class distribution.
68
+ * <p>
69
+ * If an attribute of given data is {@link DiscreteIndexedAttribute}, it creates a Distribution according to discrete indexed attribute class distribution
70
+ * and finds the entropy. If it is better than the last best entropy it reassigns the best entropy, best attribute and best split value according to
71
+ * the newly founded best entropy's index. At the end, it also add new distribution to the class distribution .
72
+ * <p>
73
+ * If an attribute of given data is {@link DiscreteAttribute}, it directly finds the entropy. If it is better than the last best entropy it
74
+ * reassigns the best entropy, best attribute and best split value according to the newly founded best entropy's index.
75
+ * <p>
76
+ * If an attribute of given data is {@link ContinuousAttribute}, it creates two distributions; left and right according to class distribution
77
+ * and discrete distribution respectively, and finds the entropy. If it is better than the last best entropy it reassigns the best entropy,
78
+ * best attribute and best split value according to the newly founded best entropy's index. At the end, it also add new distribution to
79
+ * the right distribution and removes from left distribution .
80
+ *
81
+ * @param data {@link InstanceList} input.
82
+ * @param condition {@link DecisionCondition} to check.
83
+ * @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
84
+ * @param isStump Refers to decision trees with only 1 splitting rule.
85
+ */
64
86
  constructor1(data, condition, parameter, isStump) {
65
87
  let bestAttribute = -1;
66
88
  let bestSplitValue = 0;
67
89
  if (condition instanceof DecisionCondition_1.DecisionCondition) {
68
90
  this.condition = condition;
69
91
  }
70
- this.data = data;
71
- this.classLabel = Model_1.Model.getMaximum(data.getClassLabels());
92
+ this.classLabelsDistribution = new DiscreteDistribution_1.DiscreteDistribution();
93
+ let labels = data.getClassLabels();
94
+ for (let label of labels) {
95
+ this.classLabelsDistribution.addItem(label);
96
+ }
97
+ this.classLabel = Model_1.Model.getMaximum(labels);
72
98
  this.leaf = true;
73
99
  let classLabels = data.getDistinctClassLabels();
74
100
  if (classLabels.length == 1) {
@@ -111,7 +137,7 @@
111
137
  }
112
138
  else {
113
139
  if (data.get(0).getAttribute(index) instanceof DiscreteAttribute_1.DiscreteAttribute) {
114
- let entropy = this.entropyForDiscreteAttribute(index);
140
+ let entropy = this.entropyForDiscreteAttribute(data, index);
115
141
  if (entropy + this.EPSILON < bestEntropy) {
116
142
  bestEntropy = entropy;
117
143
  bestAttribute = index;
@@ -150,20 +176,24 @@
150
176
  if (bestAttribute != -1) {
151
177
  this.leaf = false;
152
178
  if (data.get(0).getAttribute(bestAttribute) instanceof DiscreteIndexedAttribute_1.DiscreteIndexedAttribute) {
153
- this.createChildrenForDiscreteIndexed(bestAttribute, bestSplitValue, parameter, isStump);
179
+ this.createChildrenForDiscreteIndexed(data, bestAttribute, bestSplitValue, parameter, isStump);
154
180
  }
155
181
  else {
156
182
  if (data.get(0).getAttribute(bestAttribute) instanceof DiscreteAttribute_1.DiscreteAttribute) {
157
- this.createChildrenForDiscrete(bestAttribute, parameter, isStump);
183
+ this.createChildrenForDiscrete(data, bestAttribute, parameter, isStump);
158
184
  }
159
185
  else {
160
186
  if (data.get(0).getAttribute(bestAttribute) instanceof ContinuousAttribute_1.ContinuousAttribute) {
161
- this.createChildrenForContinuous(bestAttribute, bestSplitValue, parameter, isStump);
187
+ this.createChildrenForContinuous(data, bestAttribute, bestSplitValue, parameter, isStump);
162
188
  }
163
189
  }
164
190
  }
165
191
  }
166
192
  }
193
+ /**
194
+ * Reads the decision node model (as one line) from model file.
195
+ * @param contents Model file
196
+ */
167
197
  constructor2(contents) {
168
198
  let items = contents.readLine().split(" ");
169
199
  if (items[0] != "-1") {
@@ -193,20 +223,22 @@
193
223
  else {
194
224
  this.leaf = true;
195
225
  this.classLabel = contents.readLine();
226
+ this.classLabelsDistribution = Model_1.Model.loadDiscreteDistribution(contents);
196
227
  }
197
228
  }
198
229
  /**
199
230
  * The entropyForDiscreteAttribute method takes an attributeIndex and creates an ArrayList of DiscreteDistribution.
200
231
  * Then loops through the distributions and calculates the total entropy.
201
232
  *
233
+ * @param data Instance list.
202
234
  * @param attributeIndex Index of the attribute.
203
235
  * @return Total entropy for the discrete attribute.
204
236
  */
205
- entropyForDiscreteAttribute(attributeIndex) {
237
+ entropyForDiscreteAttribute(data, attributeIndex) {
206
238
  let sum = 0.0;
207
- let distributions = this.data.attributeClassDistribution(attributeIndex);
239
+ let distributions = data.attributeClassDistribution(attributeIndex);
208
240
  for (let distribution of distributions) {
209
- sum += (distribution.getSum() / this.data.size()) * distribution.entropy();
241
+ sum += (distribution.getSum() / data.size()) * distribution.entropy();
210
242
  }
211
243
  return sum;
212
244
  }
@@ -214,28 +246,30 @@
214
246
  * The createChildrenForDiscreteIndexed method creates an ArrayList of DecisionNodes as children and a partition with respect to
215
247
  * indexed attribute.
216
248
  *
249
+ * @param data Instance list.
217
250
  * @param attributeIndex Index of the attribute.
218
251
  * @param attributeValue Value of the attribute.
219
252
  * @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
220
253
  * @param isStump Refers to decision trees with only 1 splitting rule.
221
254
  */
222
- createChildrenForDiscreteIndexed(attributeIndex, attributeValue, parameter, isStump) {
223
- let childrenData = new Partition_1.Partition(this.data, attributeIndex, attributeValue);
255
+ createChildrenForDiscreteIndexed(data, attributeIndex, attributeValue, parameter, isStump) {
256
+ let childrenData = new Partition_1.Partition(data, attributeIndex, attributeValue);
224
257
  this.children = new Array();
225
- this.children.push(new DecisionNode(childrenData.get(0), new DecisionCondition_1.DecisionCondition(attributeIndex, new DiscreteIndexedAttribute_1.DiscreteIndexedAttribute("", attributeValue, this.data.get(0).getAttribute(attributeIndex).getMaxIndex())), parameter, isStump));
226
- this.children.push(new DecisionNode(childrenData.get(1), new DecisionCondition_1.DecisionCondition(attributeIndex, new DiscreteIndexedAttribute_1.DiscreteIndexedAttribute("", -1, this.data.get(0).getAttribute(attributeIndex).getMaxIndex())), parameter, isStump));
258
+ this.children.push(new DecisionNode(childrenData.get(0), new DecisionCondition_1.DecisionCondition(attributeIndex, new DiscreteIndexedAttribute_1.DiscreteIndexedAttribute("", attributeValue, data.get(0).getAttribute(attributeIndex).getMaxIndex())), parameter, isStump));
259
+ this.children.push(new DecisionNode(childrenData.get(1), new DecisionCondition_1.DecisionCondition(attributeIndex, new DiscreteIndexedAttribute_1.DiscreteIndexedAttribute("", -1, data.get(0).getAttribute(attributeIndex).getMaxIndex())), parameter, isStump));
227
260
  }
228
261
  /**
229
262
  * The createChildrenForDiscrete method creates an ArrayList of values, a partition with respect to attributes and an ArrayList
230
263
  * of DecisionNodes as children.
231
264
  *
265
+ * @param data Instance list.
232
266
  * @param attributeIndex Index of the attribute.
233
267
  * @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
234
268
  * @param isStump Refers to decision trees with only 1 splitting rule.
235
269
  */
236
- createChildrenForDiscrete(attributeIndex, parameter, isStump) {
237
- let valueList = this.data.getAttributeValueList(attributeIndex);
238
- let childrenData = new Partition_1.Partition(this.data, attributeIndex);
270
+ createChildrenForDiscrete(data, attributeIndex, parameter, isStump) {
271
+ let valueList = data.getAttributeValueList(attributeIndex);
272
+ let childrenData = new Partition_1.Partition(data, attributeIndex);
239
273
  this.children = new Array();
240
274
  for (let i = 0; i < valueList.length; i++) {
241
275
  this.children.push(new DecisionNode(childrenData.get(i), new DecisionCondition_1.DecisionCondition(attributeIndex, new DiscreteAttribute_1.DiscreteAttribute(valueList[i])), parameter, isStump));
@@ -245,13 +279,14 @@
245
279
  * The createChildrenForContinuous method creates an ArrayList of DecisionNodes as children and a partition with respect to
246
280
  * continuous attribute and the given split value.
247
281
  *
282
+ * @param data Instance list.
248
283
  * @param attributeIndex Index of the attribute.
249
284
  * @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
250
285
  * @param isStump Refers to decision trees with only 1 splitting rule.
251
286
  * @param splitValue Split value is used for partitioning.
252
287
  */
253
- createChildrenForContinuous(attributeIndex, splitValue, parameter, isStump) {
254
- let childrenData = new Partition_1.Partition(this.data, attributeIndex, splitValue + 0.0000001);
288
+ createChildrenForContinuous(data, attributeIndex, splitValue, parameter, isStump) {
289
+ let childrenData = new Partition_1.Partition(data, attributeIndex, splitValue + 0.0000001);
255
290
  this.children = new Array();
256
291
  this.children.push(new DecisionNode(childrenData.get(0), new DecisionCondition_1.DecisionCondition(attributeIndex, new ContinuousAttribute_1.ContinuousAttribute(splitValue), "<"), parameter, isStump));
257
292
  this.children.push(new DecisionNode(childrenData.get(1), new DecisionCondition_1.DecisionCondition(attributeIndex, new ContinuousAttribute_1.ContinuousAttribute(splitValue), ">"), parameter, isStump));
@@ -266,7 +301,7 @@
266
301
  predict(instance) {
267
302
  if (instance instanceof CompositeInstance_1.CompositeInstance) {
268
303
  let possibleClassLabels = instance.getPossibleClassLabels();
269
- let distribution = this.data.classDistribution();
304
+ let distribution = this.classLabelsDistribution;
270
305
  let predictedClass = distribution.getMaxItem(possibleClassLabels);
271
306
  if (this.leaf) {
272
307
  return predictedClass;
@@ -300,9 +335,16 @@
300
335
  }
301
336
  }
302
337
  }
338
+ /**
339
+ * Recursive method that returns the posterior probability distribution of a given instance. If the node is a leaf
340
+ * node, it returns the class label distribution, otherwise it checks in which direction (child node) this instance
341
+ * is forwarded.
342
+ * @param instance Instance for which the posterior probability distribution is calculated.
343
+ * @return Posterior probability distribution for this instance.
344
+ */
303
345
  predictProbabilityDistribution(instance) {
304
346
  if (this.leaf) {
305
- return this.data.classDistribution().getProbabilityDistribution();
347
+ return this.classLabelsDistribution.getProbabilityDistribution();
306
348
  }
307
349
  else {
308
350
  for (let node of this.children) {
@@ -310,7 +352,7 @@
310
352
  return node.predictProbabilityDistribution(instance);
311
353
  }
312
354
  }
313
- return this.data.classDistribution().getProbabilityDistribution();
355
+ return this.classLabelsDistribution.getProbabilityDistribution();
314
356
  }
315
357
  }
316
358
  }