nlptoolkit-classification 1.0.0

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 (412) hide show
  1. package/README.md +161 -0
  2. package/datasets/bupa.data +345 -0
  3. package/datasets/car.data +1728 -0
  4. package/datasets/chess.data +28056 -0
  5. package/datasets/dermatology.data +366 -0
  6. package/datasets/iris.data +150 -0
  7. package/datasets/nursery.data +12960 -0
  8. package/datasets/tictactoe.data +958 -0
  9. package/dist/Attribute/Attribute.d.ts +4 -0
  10. package/dist/Attribute/Attribute.js +17 -0
  11. package/dist/Attribute/Attribute.js.map +1 -0
  12. package/dist/Attribute/AttributeType.d.ts +18 -0
  13. package/dist/Attribute/AttributeType.js +33 -0
  14. package/dist/Attribute/AttributeType.js.map +1 -0
  15. package/dist/Attribute/BinaryAttribute.d.ts +9 -0
  16. package/dist/Attribute/BinaryAttribute.js +26 -0
  17. package/dist/Attribute/BinaryAttribute.js.map +1 -0
  18. package/dist/Attribute/ContinuousAttribute.d.ts +30 -0
  19. package/dist/Attribute/ContinuousAttribute.js +59 -0
  20. package/dist/Attribute/ContinuousAttribute.js.map +1 -0
  21. package/dist/Attribute/DiscreteAttribute.d.ts +24 -0
  22. package/dist/Attribute/DiscreteAttribute.js +53 -0
  23. package/dist/Attribute/DiscreteAttribute.js.map +1 -0
  24. package/dist/Attribute/DiscreteIndexedAttribute.d.ts +27 -0
  25. package/dist/Attribute/DiscreteIndexedAttribute.js +61 -0
  26. package/dist/Attribute/DiscreteIndexedAttribute.js.map +1 -0
  27. package/dist/Classifier/Bagging.d.ts +16 -0
  28. package/dist/Classifier/Bagging.js +42 -0
  29. package/dist/Classifier/Bagging.js.map +1 -0
  30. package/dist/Classifier/C45.d.ts +13 -0
  31. package/dist/Classifier/C45.js +40 -0
  32. package/dist/Classifier/C45.js.map +1 -0
  33. package/dist/Classifier/C45Stump.d.ts +12 -0
  34. package/dist/Classifier/C45Stump.js +29 -0
  35. package/dist/Classifier/C45Stump.js.map +1 -0
  36. package/dist/Classifier/Classifier.d.ts +39 -0
  37. package/dist/Classifier/Classifier.js +72 -0
  38. package/dist/Classifier/Classifier.js.map +1 -0
  39. package/dist/Classifier/DeepNetwork.d.ts +13 -0
  40. package/dist/Classifier/DeepNetwork.js +31 -0
  41. package/dist/Classifier/DeepNetwork.js.map +1 -0
  42. package/dist/Classifier/Dummy.d.ts +13 -0
  43. package/dist/Classifier/Dummy.js +29 -0
  44. package/dist/Classifier/Dummy.js.map +1 -0
  45. package/dist/Classifier/KMeans.d.ts +12 -0
  46. package/dist/Classifier/KMeans.js +36 -0
  47. package/dist/Classifier/KMeans.js.map +1 -0
  48. package/dist/Classifier/Knn.d.ts +13 -0
  49. package/dist/Classifier/Knn.js +29 -0
  50. package/dist/Classifier/Knn.js.map +1 -0
  51. package/dist/Classifier/Lda.d.ts +12 -0
  52. package/dist/Classifier/Lda.js +52 -0
  53. package/dist/Classifier/Lda.js.map +1 -0
  54. package/dist/Classifier/LinearPerceptron.d.ts +14 -0
  55. package/dist/Classifier/LinearPerceptron.js +32 -0
  56. package/dist/Classifier/LinearPerceptron.js.map +1 -0
  57. package/dist/Classifier/MultiLayerPerceptron.d.ts +14 -0
  58. package/dist/Classifier/MultiLayerPerceptron.js +32 -0
  59. package/dist/Classifier/MultiLayerPerceptron.js.map +1 -0
  60. package/dist/Classifier/NaiveBayes.d.ts +25 -0
  61. package/dist/Classifier/NaiveBayes.js +67 -0
  62. package/dist/Classifier/NaiveBayes.js.map +1 -0
  63. package/dist/Classifier/Qda.d.ts +12 -0
  64. package/dist/Classifier/Qda.js +50 -0
  65. package/dist/Classifier/Qda.js.map +1 -0
  66. package/dist/Classifier/RandomClassifier.d.ts +12 -0
  67. package/dist/Classifier/RandomClassifier.js +32 -0
  68. package/dist/Classifier/RandomClassifier.js.map +1 -0
  69. package/dist/Classifier/RandomForest.d.ts +13 -0
  70. package/dist/Classifier/RandomForest.js +39 -0
  71. package/dist/Classifier/RandomForest.js.map +1 -0
  72. package/dist/DataSet/DataDefinition.d.ts +59 -0
  73. package/dist/DataSet/DataDefinition.js +108 -0
  74. package/dist/DataSet/DataDefinition.js.map +1 -0
  75. package/dist/DataSet/DataSet.d.ts +111 -0
  76. package/dist/DataSet/DataSet.js +286 -0
  77. package/dist/DataSet/DataSet.js.map +1 -0
  78. package/dist/DistanceMetric/DistanceMetric.d.ts +4 -0
  79. package/dist/DistanceMetric/DistanceMetric.js +13 -0
  80. package/dist/DistanceMetric/DistanceMetric.js.map +1 -0
  81. package/dist/DistanceMetric/EuclidianDistance.d.ts +13 -0
  82. package/dist/DistanceMetric/EuclidianDistance.js +43 -0
  83. package/dist/DistanceMetric/EuclidianDistance.js.map +1 -0
  84. package/dist/DistanceMetric/MahalanobisDistance.d.ts +20 -0
  85. package/dist/DistanceMetric/MahalanobisDistance.js +39 -0
  86. package/dist/DistanceMetric/MahalanobisDistance.js.map +1 -0
  87. package/dist/Experiment/BootstrapRun.d.ts +19 -0
  88. package/dist/Experiment/BootstrapRun.js +44 -0
  89. package/dist/Experiment/BootstrapRun.js.map +1 -0
  90. package/dist/Experiment/Experiment.d.ts +37 -0
  91. package/dist/Experiment/Experiment.js +57 -0
  92. package/dist/Experiment/Experiment.js.map +1 -0
  93. package/dist/Experiment/KFoldRun.d.ts +19 -0
  94. package/dist/Experiment/KFoldRun.js +43 -0
  95. package/dist/Experiment/KFoldRun.js.map +1 -0
  96. package/dist/Experiment/KFoldRunSeparateTest.d.ts +24 -0
  97. package/dist/Experiment/KFoldRunSeparateTest.js +51 -0
  98. package/dist/Experiment/KFoldRunSeparateTest.js.map +1 -0
  99. package/dist/Experiment/MultipleRun.d.ts +5 -0
  100. package/dist/Experiment/MultipleRun.js +13 -0
  101. package/dist/Experiment/MultipleRun.js.map +1 -0
  102. package/dist/Experiment/MxKFoldRun.d.ts +20 -0
  103. package/dist/Experiment/MxKFoldRun.js +44 -0
  104. package/dist/Experiment/MxKFoldRun.js.map +1 -0
  105. package/dist/Experiment/MxKFoldRunSeparateTest.d.ts +21 -0
  106. package/dist/Experiment/MxKFoldRunSeparateTest.js +48 -0
  107. package/dist/Experiment/MxKFoldRunSeparateTest.js.map +1 -0
  108. package/dist/Experiment/SingleRun.d.ts +5 -0
  109. package/dist/Experiment/SingleRun.js +13 -0
  110. package/dist/Experiment/SingleRun.js.map +1 -0
  111. package/dist/Experiment/SingleRunWithK.d.ts +19 -0
  112. package/dist/Experiment/SingleRunWithK.js +37 -0
  113. package/dist/Experiment/SingleRunWithK.js.map +1 -0
  114. package/dist/Experiment/StratifiedKFoldRun.d.ts +17 -0
  115. package/dist/Experiment/StratifiedKFoldRun.js +39 -0
  116. package/dist/Experiment/StratifiedKFoldRun.js.map +1 -0
  117. package/dist/Experiment/StratifiedKFoldRunSeparateTest.d.ts +18 -0
  118. package/dist/Experiment/StratifiedKFoldRunSeparateTest.js +43 -0
  119. package/dist/Experiment/StratifiedKFoldRunSeparateTest.js.map +1 -0
  120. package/dist/Experiment/StratifiedMxKFoldRun.d.ts +19 -0
  121. package/dist/Experiment/StratifiedMxKFoldRun.js +43 -0
  122. package/dist/Experiment/StratifiedMxKFoldRun.js.map +1 -0
  123. package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.d.ts +20 -0
  124. package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js +47 -0
  125. package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js.map +1 -0
  126. package/dist/Experiment/StratifiedSingleRunWithK.d.ts +18 -0
  127. package/dist/Experiment/StratifiedSingleRunWithK.js +39 -0
  128. package/dist/Experiment/StratifiedSingleRunWithK.js.map +1 -0
  129. package/dist/FeatureSelection/BackwardSelection.d.ts +18 -0
  130. package/dist/FeatureSelection/BackwardSelection.js +39 -0
  131. package/dist/FeatureSelection/BackwardSelection.js.map +1 -0
  132. package/dist/FeatureSelection/FeatureSubSet.d.ts +47 -0
  133. package/dist/FeatureSelection/FeatureSubSet.js +89 -0
  134. package/dist/FeatureSelection/FeatureSubSet.js.map +1 -0
  135. package/dist/FeatureSelection/FloatingSelection.d.ts +16 -0
  136. package/dist/FeatureSelection/FloatingSelection.js +38 -0
  137. package/dist/FeatureSelection/FloatingSelection.js.map +1 -0
  138. package/dist/FeatureSelection/ForwardSelection.d.ts +17 -0
  139. package/dist/FeatureSelection/ForwardSelection.js +38 -0
  140. package/dist/FeatureSelection/ForwardSelection.js.map +1 -0
  141. package/dist/FeatureSelection/SubSetSelection.d.ts +37 -0
  142. package/dist/FeatureSelection/SubSetSelection.js +90 -0
  143. package/dist/FeatureSelection/SubSetSelection.js.map +1 -0
  144. package/dist/Filter/DiscreteToContinuous.d.ts +25 -0
  145. package/dist/Filter/DiscreteToContinuous.js +69 -0
  146. package/dist/Filter/DiscreteToContinuous.js.map +1 -0
  147. package/dist/Filter/DiscreteToIndexed.d.ts +21 -0
  148. package/dist/Filter/DiscreteToIndexed.js +56 -0
  149. package/dist/Filter/DiscreteToIndexed.js.map +1 -0
  150. package/dist/Filter/FeatureFilter.d.ts +18 -0
  151. package/dist/Filter/FeatureFilter.js +36 -0
  152. package/dist/Filter/FeatureFilter.js.map +1 -0
  153. package/dist/Filter/LaryFilter.d.ts +27 -0
  154. package/dist/Filter/LaryFilter.js +62 -0
  155. package/dist/Filter/LaryFilter.js.map +1 -0
  156. package/dist/Filter/LaryToBinary.d.ts +23 -0
  157. package/dist/Filter/LaryToBinary.js +67 -0
  158. package/dist/Filter/LaryToBinary.js.map +1 -0
  159. package/dist/Filter/Normalize.d.ts +21 -0
  160. package/dist/Filter/Normalize.js +47 -0
  161. package/dist/Filter/Normalize.js.map +1 -0
  162. package/dist/Filter/Pca.d.ts +44 -0
  163. package/dist/Filter/Pca.js +109 -0
  164. package/dist/Filter/Pca.js.map +1 -0
  165. package/dist/Filter/TrainedFeatureFilter.d.ts +11 -0
  166. package/dist/Filter/TrainedFeatureFilter.js +26 -0
  167. package/dist/Filter/TrainedFeatureFilter.js.map +1 -0
  168. package/dist/Instance/CompositeInstance.d.ts +32 -0
  169. package/dist/Instance/CompositeInstance.js +61 -0
  170. package/dist/Instance/CompositeInstance.js.map +1 -0
  171. package/dist/Instance/Instance.d.ts +89 -0
  172. package/dist/Instance/Instance.js +170 -0
  173. package/dist/Instance/Instance.js.map +1 -0
  174. package/dist/InstanceList/InstanceList.d.ts +188 -0
  175. package/dist/InstanceList/InstanceList.js +517 -0
  176. package/dist/InstanceList/InstanceList.js.map +1 -0
  177. package/dist/InstanceList/InstanceListOfSameClass.d.ts +16 -0
  178. package/dist/InstanceList/InstanceListOfSameClass.js +35 -0
  179. package/dist/InstanceList/InstanceListOfSameClass.js.map +1 -0
  180. package/dist/InstanceList/Partition.d.ts +31 -0
  181. package/dist/InstanceList/Partition.js +143 -0
  182. package/dist/InstanceList/Partition.js.map +1 -0
  183. package/dist/Model/DecisionTree/DecisionCondition.d.ts +34 -0
  184. package/dist/Model/DecisionTree/DecisionCondition.js +84 -0
  185. package/dist/Model/DecisionTree/DecisionCondition.js.map +1 -0
  186. package/dist/Model/DecisionTree/DecisionNode.d.ts +82 -0
  187. package/dist/Model/DecisionTree/DecisionNode.js +271 -0
  188. package/dist/Model/DecisionTree/DecisionNode.js.map +1 -0
  189. package/dist/Model/DecisionTree/DecisionTree.d.ts +37 -0
  190. package/dist/Model/DecisionTree/DecisionTree.js +75 -0
  191. package/dist/Model/DecisionTree/DecisionTree.js.map +1 -0
  192. package/dist/Model/DeepNetworkModel.d.ts +42 -0
  193. package/dist/Model/DeepNetworkModel.js +163 -0
  194. package/dist/Model/DeepNetworkModel.js.map +1 -0
  195. package/dist/Model/DummyModel.d.ts +20 -0
  196. package/dist/Model/DummyModel.js +46 -0
  197. package/dist/Model/DummyModel.js.map +1 -0
  198. package/dist/Model/GaussianModel.d.ts +24 -0
  199. package/dist/Model/GaussianModel.js +59 -0
  200. package/dist/Model/GaussianModel.js.map +1 -0
  201. package/dist/Model/KMeansModel.d.ts +27 -0
  202. package/dist/Model/KMeansModel.js +48 -0
  203. package/dist/Model/KMeansModel.js.map +1 -0
  204. package/dist/Model/KnnInstance.d.ts +14 -0
  205. package/dist/Model/KnnInstance.js +33 -0
  206. package/dist/Model/KnnInstance.js.map +1 -0
  207. package/dist/Model/KnnModel.d.ts +36 -0
  208. package/dist/Model/KnnModel.js +83 -0
  209. package/dist/Model/KnnModel.js.map +1 -0
  210. package/dist/Model/LdaModel.d.ts +25 -0
  211. package/dist/Model/LdaModel.js +45 -0
  212. package/dist/Model/LdaModel.js.map +1 -0
  213. package/dist/Model/LinearPerceptronModel.d.ts +21 -0
  214. package/dist/Model/LinearPerceptronModel.js +62 -0
  215. package/dist/Model/LinearPerceptronModel.js.map +1 -0
  216. package/dist/Model/Model.d.ts +12 -0
  217. package/dist/Model/Model.js +31 -0
  218. package/dist/Model/Model.js.map +1 -0
  219. package/dist/Model/MultiLayerPerceptronModel.d.ts +29 -0
  220. package/dist/Model/MultiLayerPerceptronModel.js +101 -0
  221. package/dist/Model/MultiLayerPerceptronModel.js.map +1 -0
  222. package/dist/Model/NaiveBayesModel.d.ts +47 -0
  223. package/dist/Model/NaiveBayesModel.js +95 -0
  224. package/dist/Model/NaiveBayesModel.js.map +1 -0
  225. package/dist/Model/NeuralNetworkModel.d.ts +99 -0
  226. package/dist/Model/NeuralNetworkModel.js +180 -0
  227. package/dist/Model/NeuralNetworkModel.js.map +1 -0
  228. package/dist/Model/QdaModel.d.ts +26 -0
  229. package/dist/Model/QdaModel.js +45 -0
  230. package/dist/Model/QdaModel.js.map +1 -0
  231. package/dist/Model/RandomModel.d.ts +16 -0
  232. package/dist/Model/RandomModel.js +51 -0
  233. package/dist/Model/RandomModel.js.map +1 -0
  234. package/dist/Model/TreeEnsembleModel.d.ts +21 -0
  235. package/dist/Model/TreeEnsembleModel.js +49 -0
  236. package/dist/Model/TreeEnsembleModel.js.map +1 -0
  237. package/dist/Model/ValidatedModel.d.ts +12 -0
  238. package/dist/Model/ValidatedModel.js +35 -0
  239. package/dist/Model/ValidatedModel.js.map +1 -0
  240. package/dist/Parameter/ActivationFunction.d.ts +5 -0
  241. package/dist/Parameter/ActivationFunction.js +20 -0
  242. package/dist/Parameter/ActivationFunction.js.map +1 -0
  243. package/dist/Parameter/BaggingParameter.d.ts +17 -0
  244. package/dist/Parameter/BaggingParameter.js +36 -0
  245. package/dist/Parameter/BaggingParameter.js.map +1 -0
  246. package/dist/Parameter/C45Parameter.d.ts +25 -0
  247. package/dist/Parameter/C45Parameter.js +46 -0
  248. package/dist/Parameter/C45Parameter.js.map +1 -0
  249. package/dist/Parameter/DeepNetworkParameter.d.ts +38 -0
  250. package/dist/Parameter/DeepNetworkParameter.js +60 -0
  251. package/dist/Parameter/DeepNetworkParameter.js.map +1 -0
  252. package/dist/Parameter/KMeansParameter.d.ts +18 -0
  253. package/dist/Parameter/KMeansParameter.js +42 -0
  254. package/dist/Parameter/KMeansParameter.js.map +1 -0
  255. package/dist/Parameter/KnnParameter.d.ts +19 -0
  256. package/dist/Parameter/KnnParameter.js +37 -0
  257. package/dist/Parameter/KnnParameter.js.map +1 -0
  258. package/dist/Parameter/LinearPerceptronParameter.d.ts +41 -0
  259. package/dist/Parameter/LinearPerceptronParameter.js +66 -0
  260. package/dist/Parameter/LinearPerceptronParameter.js.map +1 -0
  261. package/dist/Parameter/MultiLayerPerceptronParameter.d.ts +30 -0
  262. package/dist/Parameter/MultiLayerPerceptronParameter.js +50 -0
  263. package/dist/Parameter/MultiLayerPerceptronParameter.js.map +1 -0
  264. package/dist/Parameter/Parameter.d.ts +15 -0
  265. package/dist/Parameter/Parameter.js +33 -0
  266. package/dist/Parameter/Parameter.js.map +1 -0
  267. package/dist/Parameter/RandomForestParameter.d.ts +18 -0
  268. package/dist/Parameter/RandomForestParameter.js +37 -0
  269. package/dist/Parameter/RandomForestParameter.js.map +1 -0
  270. package/dist/Performance/ClassificationPerformance.d.ts +17 -0
  271. package/dist/Performance/ClassificationPerformance.js +36 -0
  272. package/dist/Performance/ClassificationPerformance.js.map +1 -0
  273. package/dist/Performance/ConfusionMatrix.d.ts +81 -0
  274. package/dist/Performance/ConfusionMatrix.js +178 -0
  275. package/dist/Performance/ConfusionMatrix.js.map +1 -0
  276. package/dist/Performance/DetailedClassificationPerformance.d.ts +17 -0
  277. package/dist/Performance/DetailedClassificationPerformance.js +35 -0
  278. package/dist/Performance/DetailedClassificationPerformance.js.map +1 -0
  279. package/dist/Performance/ExperimentPerformance.d.ts +88 -0
  280. package/dist/Performance/ExperimentPerformance.js +176 -0
  281. package/dist/Performance/ExperimentPerformance.js.map +1 -0
  282. package/dist/Performance/Performance.d.ts +15 -0
  283. package/dist/Performance/Performance.js +33 -0
  284. package/dist/Performance/Performance.js.map +1 -0
  285. package/dist/StatisticalTest/Combined5x2F.d.ts +7 -0
  286. package/dist/StatisticalTest/Combined5x2F.js +43 -0
  287. package/dist/StatisticalTest/Combined5x2F.js.map +1 -0
  288. package/dist/StatisticalTest/Combined5x2t.d.ts +7 -0
  289. package/dist/StatisticalTest/Combined5x2t.js +43 -0
  290. package/dist/StatisticalTest/Combined5x2t.js.map +1 -0
  291. package/dist/StatisticalTest/Paired5x2t.d.ts +7 -0
  292. package/dist/StatisticalTest/Paired5x2t.js +42 -0
  293. package/dist/StatisticalTest/Paired5x2t.js.map +1 -0
  294. package/dist/StatisticalTest/PairedTest.d.ts +6 -0
  295. package/dist/StatisticalTest/PairedTest.js +35 -0
  296. package/dist/StatisticalTest/PairedTest.js.map +1 -0
  297. package/dist/StatisticalTest/Pairedt.d.ts +7 -0
  298. package/dist/StatisticalTest/Pairedt.js +40 -0
  299. package/dist/StatisticalTest/Pairedt.js.map +1 -0
  300. package/dist/StatisticalTest/Sign.d.ts +8 -0
  301. package/dist/StatisticalTest/Sign.js +52 -0
  302. package/dist/StatisticalTest/Sign.js.map +1 -0
  303. package/dist/StatisticalTest/StatisticalTestResult.d.ts +9 -0
  304. package/dist/StatisticalTest/StatisticalTestResult.js +53 -0
  305. package/dist/StatisticalTest/StatisticalTestResult.js.map +1 -0
  306. package/dist/StatisticalTest/StatisticalTestResultType.d.ts +7 -0
  307. package/dist/StatisticalTest/StatisticalTestResultType.js +22 -0
  308. package/dist/StatisticalTest/StatisticalTestResultType.js.map +1 -0
  309. package/index.js +100 -0
  310. package/package.json +30 -0
  311. package/source/Attribute/Attribute.ts +6 -0
  312. package/source/Attribute/AttributeType.ts +18 -0
  313. package/source/Attribute/BinaryAttribute.ts +14 -0
  314. package/source/Attribute/ContinuousAttribute.ts +53 -0
  315. package/source/Attribute/DiscreteAttribute.ts +46 -0
  316. package/source/Attribute/DiscreteIndexedAttribute.ts +54 -0
  317. package/source/Classifier/Bagging.ts +32 -0
  318. package/source/Classifier/C45.ts +30 -0
  319. package/source/Classifier/C45Stump.ts +19 -0
  320. package/source/Classifier/Classifier.ts +71 -0
  321. package/source/Classifier/DeepNetwork.ts +22 -0
  322. package/source/Classifier/Dummy.ts +19 -0
  323. package/source/Classifier/KMeans.ts +26 -0
  324. package/source/Classifier/Knn.ts +21 -0
  325. package/source/Classifier/Lda.ts +43 -0
  326. package/source/Classifier/LinearPerceptron.ts +23 -0
  327. package/source/Classifier/MultiLayerPerceptron.ts +23 -0
  328. package/source/Classifier/NaiveBayes.ts +62 -0
  329. package/source/Classifier/Qda.ts +42 -0
  330. package/source/Classifier/RandomClassifier.ts +22 -0
  331. package/source/Classifier/RandomForest.ts +29 -0
  332. package/source/DataSet/DataDefinition.ts +106 -0
  333. package/source/DataSet/DataSet.ts +279 -0
  334. package/source/DistanceMetric/DistanceMetric.ts +6 -0
  335. package/source/DistanceMetric/EuclidianDistance.ts +32 -0
  336. package/source/DistanceMetric/MahalanobisDistance.ts +33 -0
  337. package/source/Experiment/BootstrapRun.ts +37 -0
  338. package/source/Experiment/Experiment.ts +57 -0
  339. package/source/Experiment/KFoldRun.ts +44 -0
  340. package/source/Experiment/KFoldRunSeparateTest.ts +50 -0
  341. package/source/Experiment/MultipleRun.ts +7 -0
  342. package/source/Experiment/MxKFoldRun.ts +37 -0
  343. package/source/Experiment/MxKFoldRunSeparateTest.ts +40 -0
  344. package/source/Experiment/SingleRun.ts +7 -0
  345. package/source/Experiment/SingleRunWithK.ts +39 -0
  346. package/source/Experiment/StratifiedKFoldRun.ts +30 -0
  347. package/source/Experiment/StratifiedKFoldRunSeparateTest.ts +33 -0
  348. package/source/Experiment/StratifiedMxKFoldRun.ts +34 -0
  349. package/source/Experiment/StratifiedMxKFoldRunSeparateTest.ts +40 -0
  350. package/source/Experiment/StratifiedSingleRunWithK.ts +33 -0
  351. package/source/FeatureSelection/BackwardSelection.ts +28 -0
  352. package/source/FeatureSelection/FeatureSubSet.ts +82 -0
  353. package/source/FeatureSelection/FloatingSelection.ts +27 -0
  354. package/source/FeatureSelection/ForwardSelection.ts +27 -0
  355. package/source/FeatureSelection/SubSetSelection.ts +88 -0
  356. package/source/Filter/DiscreteToContinuous.ts +59 -0
  357. package/source/Filter/DiscreteToIndexed.ts +48 -0
  358. package/source/Filter/FeatureFilter.ts +31 -0
  359. package/source/Filter/LaryFilter.ts +54 -0
  360. package/source/Filter/LaryToBinary.ts +57 -0
  361. package/source/Filter/Normalize.ts +42 -0
  362. package/source/Filter/Pca.ts +104 -0
  363. package/source/Filter/TrainedFeatureFilter.ts +17 -0
  364. package/source/Instance/CompositeInstance.ts +53 -0
  365. package/source/Instance/Instance.ts +170 -0
  366. package/source/InstanceList/InstanceList.ts +519 -0
  367. package/source/InstanceList/InstanceListOfSameClass.ts +25 -0
  368. package/source/InstanceList/Partition.ts +131 -0
  369. package/source/Model/DecisionTree/DecisionCondition.ts +74 -0
  370. package/source/Model/DecisionTree/DecisionNode.ts +257 -0
  371. package/source/Model/DecisionTree/DecisionTree.ts +71 -0
  372. package/source/Model/DeepNetworkModel.ts +156 -0
  373. package/source/Model/DummyModel.ts +40 -0
  374. package/source/Model/GaussianModel.ts +58 -0
  375. package/source/Model/KMeansModel.ts +44 -0
  376. package/source/Model/KnnInstance.ts +27 -0
  377. package/source/Model/KnnModel.ts +78 -0
  378. package/source/Model/LdaModel.ts +39 -0
  379. package/source/Model/LinearPerceptronModel.ts +55 -0
  380. package/source/Model/Model.ts +22 -0
  381. package/source/Model/MultiLayerPerceptronModel.ts +95 -0
  382. package/source/Model/NaiveBayesModel.ts +89 -0
  383. package/source/Model/NeuralNetworkModel.ts +187 -0
  384. package/source/Model/QdaModel.ts +39 -0
  385. package/source/Model/RandomModel.ts +44 -0
  386. package/source/Model/TreeEnsembleModel.ts +43 -0
  387. package/source/Model/ValidatedModel.ts +23 -0
  388. package/source/Parameter/ActivationFunction.ts +3 -0
  389. package/source/Parameter/BaggingParameter.ts +26 -0
  390. package/source/Parameter/C45Parameter.ts +38 -0
  391. package/source/Parameter/DeepNetworkParameter.ts +59 -0
  392. package/source/Parameter/KMeansParameter.ts +33 -0
  393. package/source/Parameter/KnnParameter.ts +28 -0
  394. package/source/Parameter/LinearPerceptronParameter.ts +66 -0
  395. package/source/Parameter/MultiLayerPerceptronParameter.ts +49 -0
  396. package/source/Parameter/Parameter.ts +22 -0
  397. package/source/Parameter/RandomForestParameter.ts +27 -0
  398. package/source/Performance/ClassificationPerformance.ts +26 -0
  399. package/source/Performance/ConfusionMatrix.ts +175 -0
  400. package/source/Performance/DetailedClassificationPerformance.ts +26 -0
  401. package/source/Performance/ExperimentPerformance.ts +175 -0
  402. package/source/Performance/Performance.ts +22 -0
  403. package/source/StatisticalTest/Combined5x2F.ts +33 -0
  404. package/source/StatisticalTest/Combined5x2t.ts +33 -0
  405. package/source/StatisticalTest/Paired5x2t.ts +32 -0
  406. package/source/StatisticalTest/PairedTest.ts +24 -0
  407. package/source/StatisticalTest/Pairedt.ts +30 -0
  408. package/source/StatisticalTest/Sign.ts +41 -0
  409. package/source/StatisticalTest/StatisticalTestResult.ts +42 -0
  410. package/source/StatisticalTest/StatisticalTestResultType.ts +6 -0
  411. package/source/tsconfig.json +13 -0
  412. package/tsconfig.json +15 -0
@@ -0,0 +1,37 @@
1
+ import { ValidatedModel } from "../ValidatedModel";
2
+ import { DecisionNode } from "./DecisionNode";
3
+ import { Instance } from "../../Instance/Instance";
4
+ import { InstanceList } from "../../InstanceList/InstanceList";
5
+ export declare class DecisionTree extends ValidatedModel {
6
+ private root;
7
+ /**
8
+ * Constructor that sets root node of the decision tree.
9
+ *
10
+ * @param root DecisionNode type input.
11
+ */
12
+ constructor(root: DecisionNode);
13
+ /**
14
+ * The predict method performs prediction on the root node of given instance, and if it is null, it returns the possible class labels.
15
+ * Otherwise it returns the returned class labels.
16
+ *
17
+ * @param instance Instance make prediction.
18
+ * @return Possible class labels.
19
+ */
20
+ predict(instance: Instance): string;
21
+ predictProbability(instance: Instance): Map<string, number>;
22
+ /**
23
+ * The prune method takes a {@link DecisionNode} and an {@link InstanceList} as inputs. It checks the classification performance
24
+ * of given InstanceList before pruning, i.e making a node leaf, and after pruning. If the after performance is better than the
25
+ * before performance it prune the given InstanceList from the tree.
26
+ *
27
+ * @param node DecisionNode that will be pruned if conditions hold.
28
+ * @param pruneSet Small subset of tree that will be removed from tree.
29
+ */
30
+ pruneNode(node: DecisionNode, pruneSet: InstanceList): void;
31
+ /**
32
+ * The prune method takes an {@link InstanceList} and performs pruning to the root node.
33
+ *
34
+ * @param pruneSet {@link InstanceList} to perform pruning.
35
+ */
36
+ prune(pruneSet: InstanceList): void;
37
+ }
@@ -0,0 +1,75 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../ValidatedModel", "../../Instance/CompositeInstance"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DecisionTree = void 0;
13
+ const ValidatedModel_1 = require("../ValidatedModel");
14
+ const CompositeInstance_1 = require("../../Instance/CompositeInstance");
15
+ class DecisionTree extends ValidatedModel_1.ValidatedModel {
16
+ /**
17
+ * Constructor that sets root node of the decision tree.
18
+ *
19
+ * @param root DecisionNode type input.
20
+ */
21
+ constructor(root) {
22
+ super();
23
+ this.root = root;
24
+ }
25
+ /**
26
+ * The predict method performs prediction on the root node of given instance, and if it is null, it returns the possible class labels.
27
+ * Otherwise it returns the returned class labels.
28
+ *
29
+ * @param instance Instance make prediction.
30
+ * @return Possible class labels.
31
+ */
32
+ predict(instance) {
33
+ let predictedClass = this.root.predict(instance);
34
+ if ((predictedClass == null) && ((instance instanceof CompositeInstance_1.CompositeInstance))) {
35
+ predictedClass = instance.getPossibleClassLabels()[0];
36
+ }
37
+ return predictedClass;
38
+ }
39
+ predictProbability(instance) {
40
+ return this.root.predictProbabilityDistribution(instance);
41
+ }
42
+ /**
43
+ * The prune method takes a {@link DecisionNode} and an {@link InstanceList} as inputs. It checks the classification performance
44
+ * of given InstanceList before pruning, i.e making a node leaf, and after pruning. If the after performance is better than the
45
+ * before performance it prune the given InstanceList from the tree.
46
+ *
47
+ * @param node DecisionNode that will be pruned if conditions hold.
48
+ * @param pruneSet Small subset of tree that will be removed from tree.
49
+ */
50
+ pruneNode(node, pruneSet) {
51
+ if (node.leaf) {
52
+ return;
53
+ }
54
+ let before = this.testClassifier(pruneSet);
55
+ node.leaf = true;
56
+ let after = this.testClassifier(pruneSet);
57
+ if (after.getAccuracy() < before.getAccuracy()) {
58
+ node.leaf = false;
59
+ for (let child of node.children) {
60
+ this.pruneNode(child, pruneSet);
61
+ }
62
+ }
63
+ }
64
+ /**
65
+ * The prune method takes an {@link InstanceList} and performs pruning to the root node.
66
+ *
67
+ * @param pruneSet {@link InstanceList} to perform pruning.
68
+ */
69
+ prune(pruneSet) {
70
+ this.pruneNode(this.root, pruneSet);
71
+ }
72
+ }
73
+ exports.DecisionTree = DecisionTree;
74
+ });
75
+ //# sourceMappingURL=DecisionTree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DecisionTree.js","sourceRoot":"","sources":["../../../source/Model/DecisionTree/DecisionTree.ts"],"names":[],"mappings":";;;;;;;;;;;;IAA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,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QACvC,CAAC;KACJ;IAhED,oCAgEC"}
@@ -0,0 +1,42 @@
1
+ import { NeuralNetworkModel } from "./NeuralNetworkModel";
2
+ import { DeepNetworkParameter } from "../Parameter/DeepNetworkParameter";
3
+ import { InstanceList } from "../InstanceList/InstanceList";
4
+ export declare class DeepNetworkModel extends NeuralNetworkModel {
5
+ private weights;
6
+ private hiddenLayerSize;
7
+ private readonly activationFunction;
8
+ /**
9
+ * The allocateWeights method takes {@link DeepNetworkParameter}s as an input. First it adds random weights to the {@link Array}
10
+ * of {@link Matrix} weights' first layer. Then it loops through the layers and adds random weights till the last layer.
11
+ * At the end it adds random weights to the last layer and also sets the hiddenLayerSize value.
12
+ *
13
+ * @param parameters {@link DeepNetworkParameter} input.
14
+ */
15
+ private allocateWeights;
16
+ /**
17
+ * The setBestWeights method creates an {@link Array} of Matrix as bestWeights and clones the values of weights {@link Array}
18
+ * into this newly created {@link Array}.
19
+ *
20
+ * @return An {@link Array} clones from the weights ArrayList.
21
+ */
22
+ private setBestWeights;
23
+ /**
24
+ * Constructor that takes two {@link InstanceList} train set and validation set and {@link DeepNetworkParameter} as inputs.
25
+ * First it sets the class labels, their sizes as K and the size of the continuous attributes as d of given train set and
26
+ * allocates weights and sets the best weights. At each epoch, it shuffles the train set and loops through the each item of that train set,
27
+ * it multiplies the weights Matrix with input Vector than applies the sigmoid function and stores the result as hidden and add bias.
28
+ * Then updates weights and at the end it compares the performance of these weights with validation set. It updates the bestClassificationPerformance and
29
+ * bestWeights according to the current situation. At the end it updates the learning rate via etaDecrease value and finishes
30
+ * with clearing the weights.
31
+ *
32
+ * @param trainSet {@link InstanceList} to be used as trainSet.
33
+ * @param validationSet {@link InstanceList} to be used as validationSet.
34
+ * @param parameters {@link DeepNetworkParameter} input.
35
+ */
36
+ constructor(trainSet: InstanceList, validationSet: InstanceList, parameters: DeepNetworkParameter);
37
+ /**
38
+ * The calculateOutput method loops size of the weights times and calculate one hidden layer at a time and adds bias term.
39
+ * At the end it updates the output y value.
40
+ */
41
+ protected calculateOutput(): void;
42
+ }
@@ -0,0 +1,163 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./NeuralNetworkModel", "nlptoolkit-math/dist/Matrix", "../Parameter/ActivationFunction", "nlptoolkit-math/dist/Vector", "../Performance/ClassificationPerformance"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DeepNetworkModel = void 0;
13
+ const NeuralNetworkModel_1 = require("./NeuralNetworkModel");
14
+ const Matrix_1 = require("nlptoolkit-math/dist/Matrix");
15
+ const ActivationFunction_1 = require("../Parameter/ActivationFunction");
16
+ const Vector_1 = require("nlptoolkit-math/dist/Vector");
17
+ const ClassificationPerformance_1 = require("../Performance/ClassificationPerformance");
18
+ class DeepNetworkModel extends NeuralNetworkModel_1.NeuralNetworkModel {
19
+ /**
20
+ * Constructor that takes two {@link InstanceList} train set and validation set and {@link DeepNetworkParameter} as inputs.
21
+ * First it sets the class labels, their sizes as K and the size of the continuous attributes as d of given train set and
22
+ * allocates weights and sets the best weights. At each epoch, it shuffles the train set and loops through the each item of that train set,
23
+ * it multiplies the weights Matrix with input Vector than applies the sigmoid function and stores the result as hidden and add bias.
24
+ * Then updates weights and at the end it compares the performance of these weights with validation set. It updates the bestClassificationPerformance and
25
+ * bestWeights according to the current situation. At the end it updates the learning rate via etaDecrease value and finishes
26
+ * with clearing the weights.
27
+ *
28
+ * @param trainSet {@link InstanceList} to be used as trainSet.
29
+ * @param validationSet {@link InstanceList} to be used as validationSet.
30
+ * @param parameters {@link DeepNetworkParameter} input.
31
+ */
32
+ constructor(trainSet, validationSet, parameters) {
33
+ super(trainSet);
34
+ let tmpHidden = new Vector_1.Vector(0, 0);
35
+ let deltaWeights = new Array();
36
+ let hidden = new Array();
37
+ let hiddenBiased = new Array();
38
+ this.activationFunction = parameters.getActivationFunction();
39
+ this.allocateWeights(parameters);
40
+ let bestWeights = this.setBestWeights();
41
+ let bestClassificationPerformance = new ClassificationPerformance_1.ClassificationPerformance(0.0);
42
+ let epoch = parameters.getEpoch();
43
+ let learningRate = parameters.getLearningRate();
44
+ for (let i = 0; i < epoch; i++) {
45
+ trainSet.shuffle(parameters.getSeed());
46
+ for (let j = 0; j < trainSet.size(); j++) {
47
+ this.createInputVector(trainSet.get(j));
48
+ hidden = new Array();
49
+ hiddenBiased = new Array();
50
+ deltaWeights = new Array();
51
+ for (let k = 0; k < this.hiddenLayerSize; k++) {
52
+ if (k == 0) {
53
+ hidden.push(this.calculateHidden(this.x, this.weights[k], this.activationFunction));
54
+ }
55
+ else {
56
+ hidden.push(this.calculateHidden(hiddenBiased[k - 1], this.weights[k], this.activationFunction));
57
+ }
58
+ hiddenBiased.push(hidden[k].biased());
59
+ }
60
+ let rMinusY = this.calculateRMinusY(trainSet.get(j), hiddenBiased[this.hiddenLayerSize - 1], this.weights[this.weights.length - 1]);
61
+ deltaWeights.splice(0, 0, new Matrix_1.Matrix(rMinusY, hiddenBiased[this.hiddenLayerSize - 1]));
62
+ for (let k = this.weights.length - 2; k >= 0; k--) {
63
+ let tmph;
64
+ if (k == this.weights.length - 2) {
65
+ tmph = this.weights[k + 1].multiplyWithVectorFromLeft(rMinusY);
66
+ }
67
+ else {
68
+ tmph = this.weights[k + 1].multiplyWithVectorFromLeft(tmpHidden);
69
+ }
70
+ tmph.remove(0);
71
+ let activationDerivative;
72
+ switch (this.activationFunction) {
73
+ case ActivationFunction_1.ActivationFunction.SIGMOID:
74
+ default:
75
+ let oneMinusHidden = this.calculateOneMinusHidden(hidden[k]);
76
+ activationDerivative = oneMinusHidden.elementProduct(hidden[k]);
77
+ break;
78
+ case ActivationFunction_1.ActivationFunction.TANH:
79
+ let one = new Vector_1.Vector(hidden.length, 1.0);
80
+ hidden[k].tanh();
81
+ activationDerivative = one.difference(hidden[k].elementProduct(hidden[k]));
82
+ break;
83
+ case ActivationFunction_1.ActivationFunction.RELU:
84
+ hidden[k].reluDerivative();
85
+ activationDerivative = hidden[k];
86
+ break;
87
+ }
88
+ tmpHidden = tmph.elementProduct(activationDerivative);
89
+ if (k == 0) {
90
+ deltaWeights.splice(0, 0, new Matrix_1.Matrix(tmpHidden, this.x));
91
+ }
92
+ else {
93
+ deltaWeights.splice(0, 0, new Matrix_1.Matrix(tmpHidden, hiddenBiased[k - 1]));
94
+ }
95
+ }
96
+ for (let k = 0; k < this.weights.length; k++) {
97
+ deltaWeights[k].multiplyWithConstant(learningRate);
98
+ this.weights[k].add(deltaWeights[k]);
99
+ }
100
+ }
101
+ let currentClassificationPerformance = this.testClassifier(validationSet);
102
+ if (currentClassificationPerformance.getAccuracy() > bestClassificationPerformance.getAccuracy()) {
103
+ bestClassificationPerformance = currentClassificationPerformance;
104
+ bestWeights = this.setBestWeights();
105
+ }
106
+ learningRate *= parameters.getEtaDecrease();
107
+ }
108
+ this.weights = new Array();
109
+ for (let m of bestWeights) {
110
+ this.weights.push(m);
111
+ }
112
+ }
113
+ /**
114
+ * The allocateWeights method takes {@link DeepNetworkParameter}s as an input. First it adds random weights to the {@link Array}
115
+ * of {@link Matrix} weights' first layer. Then it loops through the layers and adds random weights till the last layer.
116
+ * At the end it adds random weights to the last layer and also sets the hiddenLayerSize value.
117
+ *
118
+ * @param parameters {@link DeepNetworkParameter} input.
119
+ */
120
+ allocateWeights(parameters) {
121
+ this.weights = new Array();
122
+ this.weights.push(this.allocateLayerWeights(parameters.getHiddenNodes(0), this.d + 1));
123
+ for (let i = 0; i < parameters.layerSize() - 1; i++) {
124
+ this.weights.push(this.allocateLayerWeights(parameters.getHiddenNodes(i + 1), parameters.getHiddenNodes(i) + 1));
125
+ }
126
+ this.weights.push(this.allocateLayerWeights(this.K, parameters.getHiddenNodes(parameters.layerSize() - 1) + 1));
127
+ this.hiddenLayerSize = parameters.layerSize();
128
+ }
129
+ /**
130
+ * The setBestWeights method creates an {@link Array} of Matrix as bestWeights and clones the values of weights {@link Array}
131
+ * into this newly created {@link Array}.
132
+ *
133
+ * @return An {@link Array} clones from the weights ArrayList.
134
+ */
135
+ setBestWeights() {
136
+ let bestWeights = new Array();
137
+ for (let m of this.weights) {
138
+ bestWeights.push(m.clone());
139
+ }
140
+ return bestWeights;
141
+ }
142
+ /**
143
+ * The calculateOutput method loops size of the weights times and calculate one hidden layer at a time and adds bias term.
144
+ * At the end it updates the output y value.
145
+ */
146
+ calculateOutput() {
147
+ let hiddenBiased;
148
+ for (let i = 0; i < this.weights.length - 1; i++) {
149
+ let hidden;
150
+ if (i == 0) {
151
+ hidden = this.calculateHidden(this.x, this.weights[i], this.activationFunction);
152
+ }
153
+ else {
154
+ hidden = this.calculateHidden(hiddenBiased, this.weights[i], this.activationFunction);
155
+ }
156
+ hiddenBiased = hidden.biased();
157
+ }
158
+ this.y = this.weights[this.weights.length - 1].multiplyWithVectorFromRight(hiddenBiased);
159
+ }
160
+ }
161
+ exports.DeepNetworkModel = DeepNetworkModel;
162
+ });
163
+ //# sourceMappingURL=DeepNetworkModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeepNetworkModel.js","sourceRoot":"","sources":["../../source/Model/DeepNetworkModel.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,6DAAwD;IACxD,wDAAmD;IACnD,wEAAmE;IAGnE,wDAAmD;IACnD,wFAAmF;IAEnF,MAAa,gBAAiB,SAAQ,uCAAkB;QAqCpD;;;;;;;;;;;;WAYG;QACH,YAAY,QAAsB,EAAE,aAA2B,EAAE,UAAgC;YAC7F,KAAK,CAAC,QAAQ,CAAC,CAAC;YAChB,IAAI,SAAS,GAAG,IAAI,eAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACjC,IAAI,YAAY,GAAG,IAAI,KAAK,EAAU,CAAC;YACvC,IAAI,M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import { Instance } from "../Instance/Instance";
3
+ import { InstanceList } from "../InstanceList/InstanceList";
4
+ export declare class DummyModel extends Model {
5
+ private distribution;
6
+ /**
7
+ * Constructor which sets the distribution using the given {@link InstanceList}.
8
+ *
9
+ * @param trainSet {@link InstanceList} which is used to get the class distribution.
10
+ */
11
+ constructor(trainSet: InstanceList);
12
+ /**
13
+ * The predict method takes an Instance as an input and returns the entry of distribution which has the maximum value.
14
+ *
15
+ * @param instance Instance to make prediction.
16
+ * @return The entry of distribution which has the maximum value.
17
+ */
18
+ predict(instance: Instance): string;
19
+ predictProbability(instance: Instance): Map<string, number>;
20
+ }
@@ -0,0 +1,46 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./Model", "../Instance/CompositeInstance"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.DummyModel = void 0;
13
+ const Model_1 = require("./Model");
14
+ const CompositeInstance_1 = require("../Instance/CompositeInstance");
15
+ class DummyModel extends Model_1.Model {
16
+ /**
17
+ * Constructor which sets the distribution using the given {@link InstanceList}.
18
+ *
19
+ * @param trainSet {@link InstanceList} which is used to get the class distribution.
20
+ */
21
+ constructor(trainSet) {
22
+ super();
23
+ this.distribution = trainSet.classDistribution();
24
+ }
25
+ /**
26
+ * The predict method takes an Instance as an input and returns the entry of distribution which has the maximum value.
27
+ *
28
+ * @param instance Instance to make prediction.
29
+ * @return The entry of distribution which has the maximum value.
30
+ */
31
+ predict(instance) {
32
+ if ((instance instanceof CompositeInstance_1.CompositeInstance)) {
33
+ let possibleClassLabels = instance.getPossibleClassLabels();
34
+ return this.distribution.getMaxItem(possibleClassLabels);
35
+ }
36
+ else {
37
+ return this.distribution.getMaxItem();
38
+ }
39
+ }
40
+ predictProbability(instance) {
41
+ return this.distribution.getProbabilityDistribution();
42
+ }
43
+ }
44
+ exports.DummyModel = DummyModel;
45
+ });
46
+ //# sourceMappingURL=DummyModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DummyModel.js","sourceRoot":"","sources":["../../source/Model/DummyModel.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,mCAA8B;IAI9B,qEAAgE;IAEhE,MAAa,UAAW,SAAQ,aAAK;QAIjC;;;;WAIG;QACH,YAAY,QAAsB;YAC9B,KAAK,EAAE,CAAC;YACR,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,iBAAiB,EAAE,CAAC;QACrD,CAAC;QAED;;;;;WAKG;QACH,OAAO,CAAC,QAAkB;YACtB,IAAI,CAAC,QAAQ,YAAY,qCAAiB,CAAC,EAAE;gBACzC,IAAI,mBAAmB,GAAwB,QAAS,CAAC,sBAAsB,EAAE,CAAC;gBAClF,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC;aAC5D;iBAAM;gBACH,OAAO,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,CAAC;aACzC;QACL,CAAC;QAED,kBAAkB,CAAC,QAAkB;YACjC,OAAO,IAAI,CAAC,YAAY,CAAC,0BAA0B,EAAE,CAAC;QAC1D,CAAC;KAEJ;IAjCD,gCAiCC"}
@@ -0,0 +1,24 @@
1
+ import { DiscreteDistribution } from "nlptoolkit-math/dist/DiscreteDistribution";
2
+ import { Instance } from "../Instance/Instance";
3
+ import { ValidatedModel } from "./ValidatedModel";
4
+ export declare abstract class GaussianModel extends ValidatedModel {
5
+ protected priorDistribution: DiscreteDistribution;
6
+ /**
7
+ * Abstract method calculateMetric takes an {@link Instance} and a String as inputs.
8
+ *
9
+ * @param instance {@link Instance} input.
10
+ * @param Ci String input.
11
+ * @return A double value as metric.
12
+ */
13
+ abstract calculateMetric(instance: Instance, Ci: string): number;
14
+ /**
15
+ * The predict method takes an Instance as an input. First it gets the size of prior distribution and loops this size times.
16
+ * Then it gets the possible class labels and and calculates metric value. At the end, it returns the class which has the
17
+ * maximum value of metric.
18
+ *
19
+ * @param instance {@link Instance} to predict.
20
+ * @return The class which has the maximum value of metric.
21
+ */
22
+ predict(instance: Instance): string;
23
+ predictProbability(instance: Instance): Map<string, number>;
24
+ }
@@ -0,0 +1,59 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./ValidatedModel", "../Instance/CompositeInstance"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GaussianModel = void 0;
13
+ const ValidatedModel_1 = require("./ValidatedModel");
14
+ const CompositeInstance_1 = require("../Instance/CompositeInstance");
15
+ class GaussianModel extends ValidatedModel_1.ValidatedModel {
16
+ /**
17
+ * The predict method takes an Instance as an input. First it gets the size of prior distribution and loops this size times.
18
+ * Then it gets the possible class labels and and calculates metric value. At the end, it returns the class which has the
19
+ * maximum value of metric.
20
+ *
21
+ * @param instance {@link Instance} to predict.
22
+ * @return The class which has the maximum value of metric.
23
+ */
24
+ predict(instance) {
25
+ let maxMetric = Number.NEGATIVE_INFINITY;
26
+ let predictedClass, size;
27
+ if (instance instanceof CompositeInstance_1.CompositeInstance) {
28
+ predictedClass = instance.getPossibleClassLabels()[0];
29
+ size = instance.getPossibleClassLabels().length;
30
+ }
31
+ else {
32
+ predictedClass = this.priorDistribution.getMaxItem();
33
+ size = this.priorDistribution.size;
34
+ }
35
+ for (let i = 0; i < size; i++) {
36
+ let Ci;
37
+ if (instance instanceof CompositeInstance_1.CompositeInstance) {
38
+ Ci = instance.getPossibleClassLabels()[i];
39
+ }
40
+ else {
41
+ Ci = this.priorDistribution.getItem(i);
42
+ }
43
+ if (this.priorDistribution.containsItem(Ci)) {
44
+ let metric = this.calculateMetric(instance, Ci);
45
+ if (metric > maxMetric) {
46
+ maxMetric = metric;
47
+ predictedClass = Ci;
48
+ }
49
+ }
50
+ }
51
+ return predictedClass;
52
+ }
53
+ predictProbability(instance) {
54
+ return undefined;
55
+ }
56
+ }
57
+ exports.GaussianModel = GaussianModel;
58
+ });
59
+ //# sourceMappingURL=GaussianModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GaussianModel.js","sourceRoot":"","sources":["../../source/Model/GaussianModel.ts"],"names":[],"mappings":";;;;;;;;;;;;IAEA,qDAAgD;IAChD,qEAAgE;IAEhE,MAAsB,aAAc,SAAQ,+BAAc;QAatD;;;;;;;WAOG;QACH,OAAO,CAAC,QAAkB;YACtB,IAAI,SAAS,GAAG,MAAM,CAAC,iBAAiB,CAAC;YACzC,IAAI,cAAc,EAAE,IAAI,CAAA;YACxB,IAAI,QAAQ,YAAY,qCAAiB,EAAE;gBACvC,cAAc,GAAwB,QAAS,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC,CAAC;gBAC5E,IAAI,GAAwB,QAAS,CAAC,sBAAsB,EAAE,CAAC,MAAM,CAAC;aACzE;iBAAM;gBACH,cAAc,GAAG,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,CAAC;gBACrD,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC;aACtC;YACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE;gBAC3B,IAAI,EAAE,CAAA;gBACN,IAAI,QAAQ,YAAY,qCAAiB,EAAE;oBACvC,EAAE,GAAwB,QAAS,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC,CAAC;iBACnE;qBAAM;oBACH,EAAE,GAAG,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;iBAC1C;gBACD,IAAI,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC,EAAE,CAAC,EAAE;oBACzC,IAAI,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;oBAChD,IAAI,MAAM,GAAG,SAAS,EAAE;wBACpB,SAAS,GAAG,MAAM,CAAC;wBACnB,cAAc,GAAG,EAAE,CAAC;qBACvB;iBACJ;aACJ;YACD,OAAO,cAAc,CAAC;QAC1B,CAAC;QAED,kBAAkB,CAAC,QAAkB;YACjC,OAAO,SAAS,CAAC;QACrB,CAAC;KACJ;IApDD,sCAoDC"}
@@ -0,0 +1,27 @@
1
+ import { GaussianModel } from "./GaussianModel";
2
+ import { InstanceList } from "../InstanceList/InstanceList";
3
+ import { DistanceMetric } from "../DistanceMetric/DistanceMetric";
4
+ import { Instance } from "../Instance/Instance";
5
+ import { DiscreteDistribution } from "nlptoolkit-math/dist/DiscreteDistribution";
6
+ export declare class KMeansModel extends GaussianModel {
7
+ private classMeans;
8
+ private distanceMetric;
9
+ /**
10
+ * The constructor that sets the classMeans, priorDistribution and distanceMetric according to given inputs.
11
+ *
12
+ * @param priorDistribution {@link DiscreteDistribution} input.
13
+ * @param classMeans {@link InstanceList} of class means.
14
+ * @param distanceMetric {@link DistanceMetric} input.
15
+ */
16
+ constructor(priorDistribution: DiscreteDistribution, classMeans: InstanceList, distanceMetric: DistanceMetric);
17
+ /**
18
+ * The calculateMetric method takes an {@link Instance} and a String as inputs. It loops through the class means, if
19
+ * the corresponding class label is same as the given String it returns the negated distance between given instance and the
20
+ * current item of class means. Otherwise it returns the smallest negative number.
21
+ *
22
+ * @param instance {@link Instance} input.
23
+ * @param Ci String input.
24
+ * @return The negated distance between given instance and the current item of class means.
25
+ */
26
+ calculateMetric(instance: Instance, Ci: string): number;
27
+ }
@@ -0,0 +1,48 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "./GaussianModel"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.KMeansModel = void 0;
13
+ const GaussianModel_1 = require("./GaussianModel");
14
+ class KMeansModel extends GaussianModel_1.GaussianModel {
15
+ /**
16
+ * The constructor that sets the classMeans, priorDistribution and distanceMetric according to given inputs.
17
+ *
18
+ * @param priorDistribution {@link DiscreteDistribution} input.
19
+ * @param classMeans {@link InstanceList} of class means.
20
+ * @param distanceMetric {@link DistanceMetric} input.
21
+ */
22
+ constructor(priorDistribution, classMeans, distanceMetric) {
23
+ super();
24
+ this.classMeans = classMeans;
25
+ this.priorDistribution = priorDistribution;
26
+ this.distanceMetric = distanceMetric;
27
+ }
28
+ /**
29
+ * The calculateMetric method takes an {@link Instance} and a String as inputs. It loops through the class means, if
30
+ * the corresponding class label is same as the given String it returns the negated distance between given instance and the
31
+ * current item of class means. Otherwise it returns the smallest negative number.
32
+ *
33
+ * @param instance {@link Instance} input.
34
+ * @param Ci String input.
35
+ * @return The negated distance between given instance and the current item of class means.
36
+ */
37
+ calculateMetric(instance, Ci) {
38
+ for (let i = 0; i < this.classMeans.size(); i++) {
39
+ if (this.classMeans.get(i).getClassLabel() == Ci) {
40
+ return -this.distanceMetric.distance(instance, this.classMeans.get(i));
41
+ }
42
+ }
43
+ return Number.NEGATIVE_INFINITY;
44
+ }
45
+ }
46
+ exports.KMeansModel = KMeansModel;
47
+ });
48
+ //# sourceMappingURL=KMeansModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KMeansModel.js","sourceRoot":"","sources":["../../source/Model/KMeansModel.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,mDAA8C;IAM9C,MAAa,WAAY,SAAQ,6BAAa;QAK1C;;;;;;WAMG;QACH,YAAY,iBAAuC,EAAE,UAAwB,EAAE,cAA8B;YACzG,KAAK,EAAE,CAAC;YACR,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;YAC7B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;YAC3C,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACzC,CAAC;QAED;;;;;;;;WAQG;QACH,eAAe,CAAC,QAAkB,EAAE,EAAU;YAC1C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;gBAC7C,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE;oBAC9C,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;iBAC1E;aACJ;YACD,OAAO,MAAM,CAAC,iBAAiB,CAAC;QACpC,CAAC;KAEJ;IArCD,kCAqCC"}
@@ -0,0 +1,14 @@
1
+ import { Instance } from "../Instance/Instance";
2
+ export declare class KnnInstance {
3
+ private readonly distance;
4
+ private readonly instance;
5
+ /**
6
+ * The constructor that sets the instance and distance value.
7
+ *
8
+ * @param instance {@link Instance} input.
9
+ * @param distance Double distance value.
10
+ */
11
+ constructor(instance: Instance, distance: number);
12
+ getInstance(): Instance;
13
+ getDistance(): number;
14
+ }
@@ -0,0 +1,33 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.KnnInstance = void 0;
13
+ class KnnInstance {
14
+ /**
15
+ * The constructor that sets the instance and distance value.
16
+ *
17
+ * @param instance {@link Instance} input.
18
+ * @param distance Double distance value.
19
+ */
20
+ constructor(instance, distance) {
21
+ this.instance = instance;
22
+ this.distance = distance;
23
+ }
24
+ getInstance() {
25
+ return this.instance;
26
+ }
27
+ getDistance() {
28
+ return this.distance;
29
+ }
30
+ }
31
+ exports.KnnInstance = KnnInstance;
32
+ });
33
+ //# sourceMappingURL=KnnInstance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KnnInstance.js","sourceRoot":"","sources":["../../source/Model/KnnInstance.ts"],"names":[],"mappings":";;;;;;;;;;;;IAEA,MAAa,WAAW;QAKpB;;;;;WAKG;QACH,YAAY,QAAkB,EAAE,QAAgB;YAC5C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;YACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC7B,CAAC;QAED,WAAW;YACP,OAAO,IAAI,CAAC,QAAQ,CAAA;QACxB,CAAC;QAED,WAAW;YACP,OAAO,IAAI,CAAC,QAAQ,CAAA;QACxB,CAAC;KAEJ;IAxBD,kCAwBC"}