nlptoolkit-classification 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (382) hide show
  1. package/README.md +1 -0
  2. package/dist/Attribute/Attribute.js +6 -16
  3. package/dist/Attribute/Attribute.js.map +1 -1
  4. package/dist/Attribute/AttributeType.js +22 -32
  5. package/dist/Attribute/AttributeType.js.map +1 -1
  6. package/dist/Attribute/BinaryAttribute.js +14 -24
  7. package/dist/Attribute/BinaryAttribute.js.map +1 -1
  8. package/dist/Attribute/ContinuousAttribute.js +46 -55
  9. package/dist/Attribute/ContinuousAttribute.js.map +1 -1
  10. package/dist/Attribute/DiscreteAttribute.d.ts +1 -1
  11. package/dist/Attribute/DiscreteAttribute.js +38 -48
  12. package/dist/Attribute/DiscreteAttribute.js.map +1 -1
  13. package/dist/Attribute/DiscreteIndexedAttribute.d.ts +2 -2
  14. package/dist/Attribute/DiscreteIndexedAttribute.js +47 -55
  15. package/dist/Attribute/DiscreteIndexedAttribute.js.map +1 -1
  16. package/dist/DataSet/DataDefinition.d.ts +11 -0
  17. package/dist/DataSet/DataDefinition.js +115 -112
  18. package/dist/DataSet/DataDefinition.js.map +1 -1
  19. package/dist/DataSet/DataSet.js +268 -245
  20. package/dist/DataSet/DataSet.js.map +1 -1
  21. package/dist/DistanceMetric/DistanceMetric.js +2 -12
  22. package/dist/DistanceMetric/EuclidianDistance.js +27 -37
  23. package/dist/DistanceMetric/EuclidianDistance.js.map +1 -1
  24. package/dist/DistanceMetric/MahalanobisDistance.js +27 -36
  25. package/dist/DistanceMetric/MahalanobisDistance.js.map +1 -1
  26. package/dist/Experiment/BootstrapRun.js +31 -40
  27. package/dist/Experiment/BootstrapRun.js.map +1 -1
  28. package/dist/Experiment/Experiment.d.ts +7 -7
  29. package/dist/Experiment/Experiment.js +46 -53
  30. package/dist/Experiment/Experiment.js.map +1 -1
  31. package/dist/Experiment/KFoldRun.d.ts +17 -2
  32. package/dist/Experiment/KFoldRun.js +45 -39
  33. package/dist/Experiment/KFoldRun.js.map +1 -1
  34. package/dist/Experiment/KFoldRunSeparateTest.d.ts +13 -2
  35. package/dist/Experiment/KFoldRunSeparateTest.js +48 -47
  36. package/dist/Experiment/KFoldRunSeparateTest.js.map +1 -1
  37. package/dist/Experiment/MultipleRun.js +2 -12
  38. package/dist/Experiment/MxKFoldRun.js +31 -40
  39. package/dist/Experiment/MxKFoldRun.js.map +1 -1
  40. package/dist/Experiment/MxKFoldRunSeparateTest.js +35 -44
  41. package/dist/Experiment/MxKFoldRunSeparateTest.js.map +1 -1
  42. package/dist/Experiment/SingleRun.js +2 -12
  43. package/dist/Experiment/SingleRunWithK.d.ts +18 -3
  44. package/dist/Experiment/SingleRunWithK.js +39 -33
  45. package/dist/Experiment/SingleRunWithK.js.map +1 -1
  46. package/dist/Experiment/StratifiedKFoldRun.js +26 -36
  47. package/dist/Experiment/StratifiedKFoldRun.js.map +1 -1
  48. package/dist/Experiment/StratifiedKFoldRunSeparateTest.js +30 -40
  49. package/dist/Experiment/StratifiedKFoldRunSeparateTest.js.map +1 -1
  50. package/dist/Experiment/StratifiedMxKFoldRun.js +29 -39
  51. package/dist/Experiment/StratifiedMxKFoldRun.js.map +1 -1
  52. package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js +34 -43
  53. package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js.map +1 -1
  54. package/dist/Experiment/StratifiedSingleRunWithK.js +27 -36
  55. package/dist/Experiment/StratifiedSingleRunWithK.js.map +1 -1
  56. package/dist/FeatureSelection/BackwardSelection.js +26 -36
  57. package/dist/FeatureSelection/BackwardSelection.js.map +1 -1
  58. package/dist/FeatureSelection/FeatureSubSet.js +72 -82
  59. package/dist/FeatureSelection/FeatureSubSet.js.map +1 -1
  60. package/dist/FeatureSelection/FloatingSelection.js +25 -35
  61. package/dist/FeatureSelection/FloatingSelection.js.map +1 -1
  62. package/dist/FeatureSelection/ForwardSelection.js +25 -35
  63. package/dist/FeatureSelection/ForwardSelection.js.map +1 -1
  64. package/dist/FeatureSelection/SubSetSelection.js +69 -78
  65. package/dist/FeatureSelection/SubSetSelection.js.map +1 -1
  66. package/dist/Filter/DiscreteToContinuous.js +50 -60
  67. package/dist/Filter/DiscreteToContinuous.js.map +1 -1
  68. package/dist/Filter/DiscreteToIndexed.js +40 -50
  69. package/dist/Filter/DiscreteToIndexed.js.map +1 -1
  70. package/dist/Filter/FeatureFilter.js +23 -32
  71. package/dist/Filter/FeatureFilter.js.map +1 -1
  72. package/dist/Filter/LaryFilter.d.ts +1 -1
  73. package/dist/Filter/LaryFilter.js +46 -55
  74. package/dist/Filter/LaryFilter.js.map +1 -1
  75. package/dist/Filter/LaryToBinary.js +48 -58
  76. package/dist/Filter/LaryToBinary.js.map +1 -1
  77. package/dist/Filter/Normalize.js +33 -41
  78. package/dist/Filter/Normalize.js.map +1 -1
  79. package/dist/Filter/Pca.js +86 -96
  80. package/dist/Filter/Pca.js.map +1 -1
  81. package/dist/Filter/TrainedFeatureFilter.d.ts +1 -1
  82. package/dist/Filter/TrainedFeatureFilter.js +14 -24
  83. package/dist/Filter/TrainedFeatureFilter.js.map +1 -1
  84. package/dist/Instance/CompositeInstance.js +46 -56
  85. package/dist/Instance/CompositeInstance.js.map +1 -1
  86. package/dist/Instance/Instance.js +145 -154
  87. package/dist/Instance/Instance.js.map +1 -1
  88. package/dist/InstanceList/InstanceList.js +466 -443
  89. package/dist/InstanceList/InstanceList.js.map +1 -1
  90. package/dist/InstanceList/InstanceListOfSameClass.js +23 -32
  91. package/dist/InstanceList/InstanceListOfSameClass.js.map +1 -1
  92. package/dist/InstanceList/Partition.d.ts +45 -0
  93. package/dist/InstanceList/Partition.js +176 -131
  94. package/dist/InstanceList/Partition.js.map +1 -1
  95. package/dist/Model/DecisionTree/DecisionCondition.d.ts +8 -0
  96. package/dist/Model/DecisionTree/DecisionCondition.js +71 -72
  97. package/dist/Model/DecisionTree/DecisionCondition.js.map +1 -1
  98. package/dist/Model/DecisionTree/DecisionNode.d.ts +38 -1
  99. package/dist/Model/DecisionTree/DecisionNode.js +302 -275
  100. package/dist/Model/DecisionTree/DecisionNode.js.map +1 -1
  101. package/dist/Model/DecisionTree/DecisionStump.d.ts +17 -0
  102. package/dist/Model/DecisionTree/DecisionStump.js +25 -0
  103. package/dist/Model/DecisionTree/DecisionStump.js.map +1 -0
  104. package/dist/Model/DecisionTree/DecisionTree.d.ts +24 -9
  105. package/dist/Model/DecisionTree/DecisionTree.js +90 -76
  106. package/dist/Model/DecisionTree/DecisionTree.js.map +1 -1
  107. package/dist/Model/DummyModel.d.ts +28 -3
  108. package/dist/Model/DummyModel.js +64 -50
  109. package/dist/Model/DummyModel.js.map +1 -1
  110. package/dist/{Classifier/Bagging.d.ts → Model/Ensemble/BaggingModel.d.ts} +8 -4
  111. package/dist/Model/Ensemble/BaggingModel.js +37 -0
  112. package/dist/Model/Ensemble/BaggingModel.js.map +1 -0
  113. package/dist/{Classifier/RandomForest.d.ts → Model/Ensemble/RandomForestModel.d.ts} +8 -4
  114. package/dist/Model/Ensemble/RandomForestModel.js +34 -0
  115. package/dist/Model/Ensemble/RandomForestModel.js.map +1 -0
  116. package/dist/Model/Ensemble/TreeEnsembleModel.d.ts +32 -0
  117. package/dist/Model/Ensemble/TreeEnsembleModel.js +61 -0
  118. package/dist/Model/Ensemble/TreeEnsembleModel.js.map +1 -0
  119. package/dist/Model/Model.d.ts +50 -0
  120. package/dist/Model/Model.js +131 -72
  121. package/dist/Model/Model.js.map +1 -1
  122. package/dist/Model/NeuralNetwork/DeepNetworkModel.d.ts +47 -0
  123. package/dist/Model/NeuralNetwork/DeepNetworkModel.js +180 -0
  124. package/dist/Model/NeuralNetwork/DeepNetworkModel.js.map +1 -0
  125. package/dist/Model/NeuralNetwork/LinearPerceptronModel.d.ts +31 -0
  126. package/dist/Model/NeuralNetwork/LinearPerceptronModel.js +75 -0
  127. package/dist/Model/NeuralNetwork/LinearPerceptronModel.js.map +1 -0
  128. package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.d.ts +39 -0
  129. package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.js +119 -0
  130. package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.js.map +1 -0
  131. package/dist/Model/{NeuralNetworkModel.d.ts → NeuralNetwork/NeuralNetworkModel.d.ts} +19 -5
  132. package/dist/Model/NeuralNetwork/NeuralNetworkModel.js +211 -0
  133. package/dist/Model/NeuralNetwork/NeuralNetworkModel.js.map +1 -0
  134. package/dist/Model/{KnnInstance.d.ts → NonParametric/KnnInstance.d.ts} +1 -1
  135. package/dist/Model/NonParametric/KnnInstance.js +25 -0
  136. package/dist/Model/NonParametric/KnnInstance.js.map +1 -0
  137. package/dist/Model/{KnnModel.d.ts → NonParametric/KnnModel.d.ts} +30 -6
  138. package/dist/Model/NonParametric/KnnModel.js +111 -0
  139. package/dist/Model/NonParametric/KnnModel.js.map +1 -0
  140. package/dist/Model/{GaussianModel.d.ts → Parametric/GaussianModel.d.ts} +20 -2
  141. package/dist/Model/Parametric/GaussianModel.js +95 -0
  142. package/dist/Model/Parametric/GaussianModel.js.map +1 -0
  143. package/dist/Model/Parametric/KMeansModel.d.ts +36 -0
  144. package/dist/Model/Parametric/KMeansModel.js +65 -0
  145. package/dist/Model/Parametric/KMeansModel.js.map +1 -0
  146. package/dist/Model/Parametric/LdaModel.d.ts +44 -0
  147. package/dist/Model/Parametric/LdaModel.js +90 -0
  148. package/dist/Model/Parametric/LdaModel.js.map +1 -0
  149. package/dist/Model/{NaiveBayesModel.d.ts → Parametric/NaiveBayesModel.d.ts} +30 -10
  150. package/dist/Model/Parametric/NaiveBayesModel.js +131 -0
  151. package/dist/Model/Parametric/NaiveBayesModel.js.map +1 -0
  152. package/dist/Model/Parametric/QdaModel.d.ts +30 -0
  153. package/dist/Model/Parametric/QdaModel.js +75 -0
  154. package/dist/Model/Parametric/QdaModel.js.map +1 -0
  155. package/dist/Model/RandomModel.d.ts +32 -2
  156. package/dist/Model/RandomModel.js +85 -60
  157. package/dist/Model/RandomModel.js.map +1 -1
  158. package/dist/Model/ValidatedModel.js +21 -31
  159. package/dist/Model/ValidatedModel.js.map +1 -1
  160. package/dist/Parameter/ActivationFunction.js +9 -19
  161. package/dist/Parameter/ActivationFunction.js.map +1 -1
  162. package/dist/Parameter/BaggingParameter.js +24 -33
  163. package/dist/Parameter/BaggingParameter.js.map +1 -1
  164. package/dist/Parameter/C45Parameter.d.ts +2 -2
  165. package/dist/Parameter/C45Parameter.js +34 -42
  166. package/dist/Parameter/C45Parameter.js.map +1 -1
  167. package/dist/Parameter/DeepNetworkParameter.d.ts +2 -2
  168. package/dist/Parameter/DeepNetworkParameter.js +48 -56
  169. package/dist/Parameter/DeepNetworkParameter.js.map +1 -1
  170. package/dist/Parameter/KMeansParameter.js +29 -38
  171. package/dist/Parameter/KMeansParameter.js.map +1 -1
  172. package/dist/Parameter/KnnParameter.d.ts +1 -1
  173. package/dist/Parameter/KnnParameter.js +25 -34
  174. package/dist/Parameter/KnnParameter.js.map +1 -1
  175. package/dist/Parameter/LinearPerceptronParameter.d.ts +4 -4
  176. package/dist/Parameter/LinearPerceptronParameter.js +56 -62
  177. package/dist/Parameter/LinearPerceptronParameter.js.map +1 -1
  178. package/dist/Parameter/MultiLayerPerceptronParameter.d.ts +2 -2
  179. package/dist/Parameter/MultiLayerPerceptronParameter.js +38 -46
  180. package/dist/Parameter/MultiLayerPerceptronParameter.js.map +1 -1
  181. package/dist/Parameter/Parameter.d.ts +1 -1
  182. package/dist/Parameter/Parameter.js +21 -30
  183. package/dist/Parameter/Parameter.js.map +1 -1
  184. package/dist/Parameter/RandomForestParameter.js +25 -34
  185. package/dist/Parameter/RandomForestParameter.js.map +1 -1
  186. package/dist/Performance/ClassificationPerformance.js +24 -33
  187. package/dist/Performance/ClassificationPerformance.js.map +1 -1
  188. package/dist/Performance/ConfusionMatrix.d.ts +1 -1
  189. package/dist/Performance/ConfusionMatrix.js +149 -158
  190. package/dist/Performance/ConfusionMatrix.js.map +1 -1
  191. package/dist/Performance/DetailedClassificationPerformance.js +23 -32
  192. package/dist/Performance/DetailedClassificationPerformance.js.map +1 -1
  193. package/dist/Performance/ExperimentPerformance.js +184 -161
  194. package/dist/Performance/ExperimentPerformance.js.map +1 -1
  195. package/dist/Performance/Performance.js +21 -30
  196. package/dist/Performance/Performance.js.map +1 -1
  197. package/dist/StatisticalTest/Combined5x2F.d.ts +12 -0
  198. package/dist/StatisticalTest/Combined5x2F.js +41 -39
  199. package/dist/StatisticalTest/Combined5x2F.js.map +1 -1
  200. package/dist/StatisticalTest/Combined5x2t.d.ts +13 -0
  201. package/dist/StatisticalTest/Combined5x2t.js +42 -39
  202. package/dist/StatisticalTest/Combined5x2t.js.map +1 -1
  203. package/dist/StatisticalTest/Paired5x2t.d.ts +12 -0
  204. package/dist/StatisticalTest/Paired5x2t.js +40 -38
  205. package/dist/StatisticalTest/Paired5x2t.js.map +1 -1
  206. package/dist/StatisticalTest/PairedTest.d.ts +12 -0
  207. package/dist/StatisticalTest/PairedTest.js +31 -29
  208. package/dist/StatisticalTest/PairedTest.js.map +1 -1
  209. package/dist/StatisticalTest/Pairedt.d.ts +12 -0
  210. package/dist/StatisticalTest/Pairedt.js +38 -36
  211. package/dist/StatisticalTest/Pairedt.js.map +1 -1
  212. package/dist/StatisticalTest/Sign.d.ts +17 -0
  213. package/dist/StatisticalTest/Sign.js +50 -43
  214. package/dist/StatisticalTest/Sign.js.map +1 -1
  215. package/dist/StatisticalTest/StatisticalTestResult.d.ts +30 -0
  216. package/dist/StatisticalTest/StatisticalTestResult.js +65 -43
  217. package/dist/StatisticalTest/StatisticalTestResult.js.map +1 -1
  218. package/dist/StatisticalTest/StatisticalTestResultType.js +11 -21
  219. package/dist/StatisticalTest/StatisticalTestResultType.js.map +1 -1
  220. package/dist/index.d.ts +88 -0
  221. package/dist/index.js +105 -0
  222. package/dist/index.js.map +1 -0
  223. package/package.json +9 -8
  224. package/source/Attribute/DiscreteAttribute.ts +1 -1
  225. package/source/Attribute/DiscreteIndexedAttribute.ts +2 -2
  226. package/source/DataSet/DataDefinition.ts +11 -0
  227. package/source/Experiment/BootstrapRun.ts +2 -2
  228. package/source/Experiment/Experiment.ts +10 -10
  229. package/source/Experiment/KFoldRun.ts +20 -5
  230. package/source/Experiment/KFoldRunSeparateTest.ts +16 -5
  231. package/source/Experiment/MxKFoldRun.ts +1 -1
  232. package/source/Experiment/MxKFoldRunSeparateTest.ts +1 -1
  233. package/source/Experiment/SingleRunWithK.ts +20 -5
  234. package/source/Experiment/StratifiedKFoldRun.ts +1 -1
  235. package/source/Experiment/StratifiedKFoldRunSeparateTest.ts +1 -1
  236. package/source/Experiment/StratifiedMxKFoldRun.ts +1 -1
  237. package/source/Experiment/StratifiedMxKFoldRunSeparateTest.ts +3 -3
  238. package/source/Experiment/StratifiedSingleRunWithK.ts +1 -1
  239. package/source/Filter/LaryFilter.ts +1 -1
  240. package/source/Filter/TrainedFeatureFilter.ts +1 -1
  241. package/source/InstanceList/Partition.ts +125 -65
  242. package/source/Model/DecisionTree/DecisionCondition.ts +8 -0
  243. package/source/Model/DecisionTree/DecisionNode.ts +56 -20
  244. package/source/Model/DecisionTree/DecisionStump.ts +26 -0
  245. package/source/Model/DecisionTree/DecisionTree.ts +44 -15
  246. package/source/Model/DummyModel.ts +40 -10
  247. package/source/{Classifier/Bagging.ts → Model/Ensemble/BaggingModel.ts} +15 -12
  248. package/source/{Classifier/RandomForest.ts → Model/Ensemble/RandomForestModel.ts} +14 -12
  249. package/source/Model/{TreeEnsembleModel.ts → Ensemble/TreeEnsembleModel.ts} +26 -18
  250. package/source/Model/Model.ts +77 -0
  251. package/source/Model/{DeepNetworkModel.ts → NeuralNetwork/DeepNetworkModel.ts} +59 -56
  252. package/source/Model/NeuralNetwork/LinearPerceptronModel.ts +81 -0
  253. package/source/Model/{MultiLayerPerceptronModel.ts → NeuralNetwork/MultiLayerPerceptronModel.ts} +46 -39
  254. package/source/Model/{NeuralNetworkModel.ts → NeuralNetwork/NeuralNetworkModel.ts} +20 -7
  255. package/source/Model/{KnnInstance.ts → NonParametric/KnnInstance.ts} +1 -1
  256. package/source/Model/{KnnModel.ts → NonParametric/KnnModel.ts} +48 -19
  257. package/source/Model/{GaussianModel.ts → Parametric/GaussianModel.ts} +21 -3
  258. package/source/Model/Parametric/KMeansModel.ts +72 -0
  259. package/source/Model/Parametric/LdaModel.ts +98 -0
  260. package/source/Model/{NaiveBayesModel.ts → Parametric/NaiveBayesModel.ts} +68 -25
  261. package/source/Model/Parametric/QdaModel.ts +83 -0
  262. package/source/Model/RandomModel.ts +54 -16
  263. package/source/Parameter/C45Parameter.ts +2 -2
  264. package/source/Parameter/DeepNetworkParameter.ts +2 -2
  265. package/source/Parameter/KnnParameter.ts +1 -1
  266. package/source/Parameter/LinearPerceptronParameter.ts +4 -4
  267. package/source/Parameter/MultiLayerPerceptronParameter.ts +2 -2
  268. package/source/Parameter/Parameter.ts +1 -1
  269. package/source/Performance/ConfusionMatrix.ts +1 -1
  270. package/source/StatisticalTest/Combined5x2F.ts +12 -0
  271. package/source/StatisticalTest/Combined5x2t.ts +13 -0
  272. package/source/StatisticalTest/Paired5x2t.ts +12 -0
  273. package/source/StatisticalTest/PairedTest.ts +12 -0
  274. package/source/StatisticalTest/Pairedt.ts +12 -0
  275. package/source/StatisticalTest/Sign.ts +17 -0
  276. package/source/StatisticalTest/StatisticalTestResult.ts +30 -0
  277. package/source/index.ts +88 -0
  278. package/tests/Classifier/C45Test.ts +2 -2
  279. package/tests/Classifier/DeepNetworkTest.ts +3 -5
  280. package/tests/Classifier/DummyTest.ts +2 -2
  281. package/tests/Classifier/KMeansTest.ts +2 -2
  282. package/tests/Classifier/KnnTest.ts +2 -2
  283. package/tests/Classifier/LdaTest.ts +2 -2
  284. package/tests/Classifier/LinearPerceptronTest.ts +2 -2
  285. package/tests/Classifier/MultiLayerPerceptronTest.ts +2 -3
  286. package/tests/Classifier/NaiveBayesTest.ts +2 -2
  287. package/tests/Classifier/QdaTest.ts +2 -2
  288. package/tests/Classifier/RandomForestTest.ts +2 -2
  289. package/tsconfig.json +4 -4
  290. package/dist/Classifier/Bagging.js +0 -45
  291. package/dist/Classifier/Bagging.js.map +0 -1
  292. package/dist/Classifier/C45.d.ts +0 -14
  293. package/dist/Classifier/C45.js +0 -43
  294. package/dist/Classifier/C45.js.map +0 -1
  295. package/dist/Classifier/C45Stump.d.ts +0 -13
  296. package/dist/Classifier/C45Stump.js +0 -32
  297. package/dist/Classifier/C45Stump.js.map +0 -1
  298. package/dist/Classifier/Classifier.d.ts +0 -40
  299. package/dist/Classifier/Classifier.js +0 -72
  300. package/dist/Classifier/Classifier.js.map +0 -1
  301. package/dist/Classifier/DeepNetwork.d.ts +0 -14
  302. package/dist/Classifier/DeepNetwork.js +0 -34
  303. package/dist/Classifier/DeepNetwork.js.map +0 -1
  304. package/dist/Classifier/Dummy.d.ts +0 -14
  305. package/dist/Classifier/Dummy.js +0 -32
  306. package/dist/Classifier/Dummy.js.map +0 -1
  307. package/dist/Classifier/KMeans.d.ts +0 -13
  308. package/dist/Classifier/KMeans.js +0 -39
  309. package/dist/Classifier/KMeans.js.map +0 -1
  310. package/dist/Classifier/Knn.d.ts +0 -14
  311. package/dist/Classifier/Knn.js +0 -32
  312. package/dist/Classifier/Knn.js.map +0 -1
  313. package/dist/Classifier/Lda.d.ts +0 -13
  314. package/dist/Classifier/Lda.js +0 -55
  315. package/dist/Classifier/Lda.js.map +0 -1
  316. package/dist/Classifier/LinearPerceptron.d.ts +0 -15
  317. package/dist/Classifier/LinearPerceptron.js +0 -35
  318. package/dist/Classifier/LinearPerceptron.js.map +0 -1
  319. package/dist/Classifier/MultiLayerPerceptron.d.ts +0 -15
  320. package/dist/Classifier/MultiLayerPerceptron.js +0 -35
  321. package/dist/Classifier/MultiLayerPerceptron.js.map +0 -1
  322. package/dist/Classifier/NaiveBayes.d.ts +0 -26
  323. package/dist/Classifier/NaiveBayes.js +0 -70
  324. package/dist/Classifier/NaiveBayes.js.map +0 -1
  325. package/dist/Classifier/Qda.d.ts +0 -13
  326. package/dist/Classifier/Qda.js +0 -53
  327. package/dist/Classifier/Qda.js.map +0 -1
  328. package/dist/Classifier/RandomClassifier.d.ts +0 -13
  329. package/dist/Classifier/RandomClassifier.js +0 -35
  330. package/dist/Classifier/RandomClassifier.js.map +0 -1
  331. package/dist/Classifier/RandomForest.js +0 -42
  332. package/dist/Classifier/RandomForest.js.map +0 -1
  333. package/dist/Model/DeepNetworkModel.d.ts +0 -45
  334. package/dist/Model/DeepNetworkModel.js +0 -187
  335. package/dist/Model/DeepNetworkModel.js.map +0 -1
  336. package/dist/Model/GaussianModel.js +0 -86
  337. package/dist/Model/GaussianModel.js.map +0 -1
  338. package/dist/Model/KMeansModel.d.ts +0 -28
  339. package/dist/Model/KMeansModel.js +0 -61
  340. package/dist/Model/KMeansModel.js.map +0 -1
  341. package/dist/Model/KnnInstance.js +0 -33
  342. package/dist/Model/KnnInstance.js.map +0 -1
  343. package/dist/Model/KnnModel.js +0 -95
  344. package/dist/Model/KnnModel.js.map +0 -1
  345. package/dist/Model/LdaModel.d.ts +0 -28
  346. package/dist/Model/LdaModel.js +0 -67
  347. package/dist/Model/LdaModel.js.map +0 -1
  348. package/dist/Model/LinearPerceptronModel.d.ts +0 -24
  349. package/dist/Model/LinearPerceptronModel.js +0 -91
  350. package/dist/Model/LinearPerceptronModel.js.map +0 -1
  351. package/dist/Model/MultiLayerPerceptronModel.d.ts +0 -33
  352. package/dist/Model/MultiLayerPerceptronModel.js +0 -123
  353. package/dist/Model/MultiLayerPerceptronModel.js.map +0 -1
  354. package/dist/Model/NaiveBayesModel.js +0 -107
  355. package/dist/Model/NaiveBayesModel.js.map +0 -1
  356. package/dist/Model/NeuralNetworkModel.js +0 -202
  357. package/dist/Model/NeuralNetworkModel.js.map +0 -1
  358. package/dist/Model/QdaModel.d.ts +0 -27
  359. package/dist/Model/QdaModel.js +0 -63
  360. package/dist/Model/QdaModel.js.map +0 -1
  361. package/dist/Model/TreeEnsembleModel.d.ts +0 -22
  362. package/dist/Model/TreeEnsembleModel.js +0 -64
  363. package/dist/Model/TreeEnsembleModel.js.map +0 -1
  364. package/index.js +0 -100
  365. package/source/Classifier/C45.ts +0 -34
  366. package/source/Classifier/C45Stump.ts +0 -23
  367. package/source/Classifier/Classifier.ts +0 -72
  368. package/source/Classifier/DeepNetwork.ts +0 -26
  369. package/source/Classifier/Dummy.ts +0 -23
  370. package/source/Classifier/KMeans.ts +0 -30
  371. package/source/Classifier/Knn.ts +0 -25
  372. package/source/Classifier/Lda.ts +0 -47
  373. package/source/Classifier/LinearPerceptron.ts +0 -27
  374. package/source/Classifier/MultiLayerPerceptron.ts +0 -27
  375. package/source/Classifier/NaiveBayes.ts +0 -66
  376. package/source/Classifier/Qda.ts +0 -46
  377. package/source/Classifier/RandomClassifier.ts +0 -26
  378. package/source/Model/KMeansModel.ts +0 -56
  379. package/source/Model/LdaModel.ts +0 -62
  380. package/source/Model/LinearPerceptronModel.ts +0 -83
  381. package/source/Model/QdaModel.ts +0 -57
  382. package/source/tsconfig.json +0 -13
@@ -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
  }
@@ -16,19 +16,40 @@ export class DecisionNode {
16
16
 
17
17
  children: Array<DecisionNode> = undefined
18
18
  private EPSILON: number = 0.0000000001;
19
- private data : InstanceList = undefined
20
19
  private classLabel : string = undefined
21
20
  leaf: boolean = false
22
21
  private condition: DecisionCondition = undefined
23
22
  private classLabelsDistribution: DiscreteDistribution
24
23
 
24
+ /**
25
+ * The DecisionNode method takes {@link InstanceList} data as input and then it sets the class label parameter by finding
26
+ * the most occurred class label of given data, it then gets distinct class labels as class labels ArrayList. Later, it adds ordered
27
+ * indices to the indexList and shuffles them randomly. Then, it gets the class distribution of given data and finds the best entropy value
28
+ * of these class distribution.
29
+ * <p>
30
+ * If an attribute of given data is {@link DiscreteIndexedAttribute}, it creates a Distribution according to discrete indexed attribute class distribution
31
+ * 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
32
+ * the newly founded best entropy's index. At the end, it also add new distribution to the class distribution .
33
+ * <p>
34
+ * If an attribute of given data is {@link DiscreteAttribute}, it directly finds the entropy. If it is better than the last best entropy it
35
+ * reassigns the best entropy, best attribute and best split value according to the newly founded best entropy's index.
36
+ * <p>
37
+ * If an attribute of given data is {@link ContinuousAttribute}, it creates two distributions; left and right according to class distribution
38
+ * and discrete distribution respectively, and finds the entropy. If it is better than the last best entropy it reassigns the best entropy,
39
+ * best attribute and best split value according to the newly founded best entropy's index. At the end, it also add new distribution to
40
+ * the right distribution and removes from left distribution .
41
+ *
42
+ * @param data {@link InstanceList} input.
43
+ * @param condition {@link DecisionCondition} to check.
44
+ * @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
45
+ * @param isStump Refers to decision trees with only 1 splitting rule.
46
+ */
25
47
  constructor1(data: InstanceList, condition?: DecisionCondition | number, parameter?: RandomForestParameter, isStump?: boolean){
26
48
  let bestAttribute = -1
27
49
  let bestSplitValue = 0
28
50
  if (condition instanceof DecisionCondition){
29
51
  this.condition = condition;
30
52
  }
31
- this.data = data
32
53
  this.classLabelsDistribution = new DiscreteDistribution()
33
54
  let labels = data.getClassLabels()
34
55
  for (let label of labels){
@@ -75,7 +96,7 @@ export class DecisionNode {
75
96
  }
76
97
  } else {
77
98
  if (data.get(0).getAttribute(index) instanceof DiscreteAttribute) {
78
- let entropy = this.entropyForDiscreteAttribute(index);
99
+ let entropy = this.entropyForDiscreteAttribute(data, index);
79
100
  if (entropy + this.EPSILON < bestEntropy) {
80
101
  bestEntropy = entropy;
81
102
  bestAttribute = index;
@@ -112,19 +133,23 @@ export class DecisionNode {
112
133
  if (bestAttribute != -1) {
113
134
  this.leaf = false;
114
135
  if (data.get(0).getAttribute(bestAttribute) instanceof DiscreteIndexedAttribute) {
115
- this.createChildrenForDiscreteIndexed(bestAttribute, bestSplitValue, parameter, isStump);
136
+ this.createChildrenForDiscreteIndexed(data, bestAttribute, bestSplitValue, parameter, isStump);
116
137
  } else {
117
138
  if (data.get(0).getAttribute(bestAttribute) instanceof DiscreteAttribute) {
118
- this.createChildrenForDiscrete(bestAttribute, parameter, isStump);
139
+ this.createChildrenForDiscrete(data, bestAttribute, parameter, isStump);
119
140
  } else {
120
141
  if (data.get(0).getAttribute(bestAttribute) instanceof ContinuousAttribute) {
121
- this.createChildrenForContinuous(bestAttribute, bestSplitValue, parameter, isStump);
142
+ this.createChildrenForContinuous(data, bestAttribute, bestSplitValue, parameter, isStump);
122
143
  }
123
144
  }
124
145
  }
125
146
  }
126
147
  }
127
148
 
149
+ /**
150
+ * Reads the decision node model (as one line) from model file.
151
+ * @param contents Model file
152
+ */
128
153
  constructor2(contents: FileContents){
129
154
  let items = contents.readLine().split(" ")
130
155
  if (items[0] != "-1"){
@@ -191,14 +216,15 @@ export class DecisionNode {
191
216
  * The entropyForDiscreteAttribute method takes an attributeIndex and creates an ArrayList of DiscreteDistribution.
192
217
  * Then loops through the distributions and calculates the total entropy.
193
218
  *
219
+ * @param data Instance list.
194
220
  * @param attributeIndex Index of the attribute.
195
221
  * @return Total entropy for the discrete attribute.
196
222
  */
197
- private entropyForDiscreteAttribute(attributeIndex: number): number{
223
+ private entropyForDiscreteAttribute(data: InstanceList, attributeIndex: number): number{
198
224
  let sum = 0.0;
199
- let distributions = this.data.attributeClassDistribution(attributeIndex);
225
+ let distributions = data.attributeClassDistribution(attributeIndex);
200
226
  for (let distribution of distributions) {
201
- sum += (distribution.getSum() / this.data.size()) * distribution.entropy();
227
+ sum += (distribution.getSum() / data.size()) * distribution.entropy();
202
228
  }
203
229
  return sum;
204
230
  }
@@ -207,29 +233,31 @@ export class DecisionNode {
207
233
  * The createChildrenForDiscreteIndexed method creates an ArrayList of DecisionNodes as children and a partition with respect to
208
234
  * indexed attribute.
209
235
  *
236
+ * @param data Instance list.
210
237
  * @param attributeIndex Index of the attribute.
211
238
  * @param attributeValue Value of the attribute.
212
239
  * @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
213
240
  * @param isStump Refers to decision trees with only 1 splitting rule.
214
241
  */
215
- private createChildrenForDiscreteIndexed(attributeIndex: number, attributeValue: number, parameter: RandomForestParameter, isStump: boolean){
216
- let childrenData = new Partition(this.data, attributeIndex, attributeValue);
242
+ private createChildrenForDiscreteIndexed(data: InstanceList, attributeIndex: number, attributeValue: number, parameter: RandomForestParameter, isStump: boolean){
243
+ let childrenData = new Partition(data, attributeIndex, attributeValue);
217
244
  this.children = new Array<DecisionNode>();
218
- this.children.push(new DecisionNode(childrenData.get(0), new DecisionCondition(attributeIndex, new DiscreteIndexedAttribute("", attributeValue, (<DiscreteIndexedAttribute> this.data.get(0).getAttribute(attributeIndex)).getMaxIndex())), parameter, isStump));
219
- this.children.push(new DecisionNode(childrenData.get(1), new DecisionCondition(attributeIndex, new DiscreteIndexedAttribute("", -1, (<DiscreteIndexedAttribute> this.data.get(0).getAttribute(attributeIndex)).getMaxIndex())), parameter, isStump));
245
+ this.children.push(new DecisionNode(childrenData.get(0), new DecisionCondition(attributeIndex, new DiscreteIndexedAttribute("", attributeValue, (<DiscreteIndexedAttribute> data.get(0).getAttribute(attributeIndex)).getMaxIndex())), parameter, isStump));
246
+ this.children.push(new DecisionNode(childrenData.get(1), new DecisionCondition(attributeIndex, new DiscreteIndexedAttribute("", -1, (<DiscreteIndexedAttribute> data.get(0).getAttribute(attributeIndex)).getMaxIndex())), parameter, isStump));
220
247
  }
221
248
 
222
249
  /**
223
250
  * The createChildrenForDiscrete method creates an ArrayList of values, a partition with respect to attributes and an ArrayList
224
251
  * of DecisionNodes as children.
225
252
  *
253
+ * @param data Instance list.
226
254
  * @param attributeIndex Index of the attribute.
227
255
  * @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
228
256
  * @param isStump Refers to decision trees with only 1 splitting rule.
229
257
  */
230
- private createChildrenForDiscrete(attributeIndex: number, parameter: RandomForestParameter, isStump: boolean){
231
- let valueList = this.data.getAttributeValueList(attributeIndex);
232
- let childrenData = new Partition(this.data, attributeIndex);
258
+ private createChildrenForDiscrete(data: InstanceList, attributeIndex: number, parameter: RandomForestParameter, isStump: boolean){
259
+ let valueList = data.getAttributeValueList(attributeIndex);
260
+ let childrenData = new Partition(data, attributeIndex);
233
261
  this.children = new Array<DecisionNode>();
234
262
  for (let i = 0; i < valueList.length; i++) {
235
263
  this.children.push(new DecisionNode(childrenData.get(i), new DecisionCondition(attributeIndex, new DiscreteAttribute(valueList[i])), parameter, isStump));
@@ -240,13 +268,14 @@ export class DecisionNode {
240
268
  * The createChildrenForContinuous method creates an ArrayList of DecisionNodes as children and a partition with respect to
241
269
  * continuous attribute and the given split value.
242
270
  *
271
+ * @param data Instance list.
243
272
  * @param attributeIndex Index of the attribute.
244
273
  * @param parameter RandomForestParameter like seed, ensembleSize, attributeSubsetSize.
245
274
  * @param isStump Refers to decision trees with only 1 splitting rule.
246
275
  * @param splitValue Split value is used for partitioning.
247
276
  */
248
- private createChildrenForContinuous(attributeIndex: number, splitValue: number, parameter: RandomForestParameter, isStump: boolean){
249
- let childrenData = new Partition(this.data, attributeIndex, splitValue + 0.0000001);
277
+ private createChildrenForContinuous(data: InstanceList, attributeIndex: number, splitValue: number, parameter: RandomForestParameter, isStump: boolean){
278
+ let childrenData = new Partition(data, attributeIndex, splitValue + 0.0000001);
250
279
  this.children = new Array<DecisionNode>();
251
280
  this.children.push(new DecisionNode(childrenData.get(0), new DecisionCondition(attributeIndex, new ContinuousAttribute(splitValue), "<"), parameter, isStump));
252
281
  this.children.push(new DecisionNode(childrenData.get(1), new DecisionCondition(attributeIndex, new ContinuousAttribute(splitValue), ">"), parameter, isStump));
@@ -262,7 +291,7 @@ export class DecisionNode {
262
291
  predict(instance: Instance): string{
263
292
  if (instance instanceof CompositeInstance) {
264
293
  let possibleClassLabels = (<CompositeInstance> instance).getPossibleClassLabels();
265
- let distribution = this.data.classDistribution();
294
+ let distribution = this.classLabelsDistribution;
266
295
  let predictedClass = distribution.getMaxItem(possibleClassLabels);
267
296
  if (this.leaf) {
268
297
  return predictedClass;
@@ -293,6 +322,13 @@ export class DecisionNode {
293
322
  }
294
323
  }
295
324
 
325
+ /**
326
+ * Recursive method that returns the posterior probability distribution of a given instance. If the node is a leaf
327
+ * node, it returns the class label distribution, otherwise it checks in which direction (child node) this instance
328
+ * is forwarded.
329
+ * @param instance Instance for which the posterior probability distribution is calculated.
330
+ * @return Posterior probability distribution for this instance.
331
+ */
296
332
  predictProbabilityDistribution(instance: Instance): Map<string, number>{
297
333
  if (this.leaf) {
298
334
  return this.classLabelsDistribution.getProbabilityDistribution();
@@ -302,7 +338,7 @@ export class DecisionNode {
302
338
  return node.predictProbabilityDistribution(instance);
303
339
  }
304
340
  }
305
- return this.data.classDistribution().getProbabilityDistribution();
341
+ return this.classLabelsDistribution.getProbabilityDistribution();
306
342
  }
307
343
  }
308
344
  }
@@ -0,0 +1,26 @@
1
+ import {DecisionTree} from "./DecisionTree";
2
+ import {InstanceList} from "../../InstanceList/InstanceList";
3
+ import {Parameter} from "../../Parameter/Parameter";
4
+ import {DecisionNode} from "./DecisionNode";
5
+
6
+ export class DecisionStump extends DecisionTree {
7
+
8
+ /**
9
+ * Training algorithm for C4.5 Stump univariate decision tree classifier.
10
+ *
11
+ * @param trainSet Training data given to the algorithm.
12
+ * @param parameters -
13
+ */
14
+ train(trainSet: InstanceList, parameters: Parameter): void {
15
+ this.root = new DecisionNode(trainSet, undefined, undefined, true);
16
+ }
17
+
18
+ /**
19
+ * Loads the decision tree model from an input file.
20
+ * @param fileName File name of the decision tree model.
21
+ */
22
+ loadModel(fileName: string): void{
23
+ this.constructor2(fileName)
24
+ }
25
+
26
+ }