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,36 @@
1
+ import { Model } from "./Model";
2
+ import { InstanceList } from "../InstanceList/InstanceList";
3
+ import { Instance } from "../Instance/Instance";
4
+ import { DistanceMetric } from "../DistanceMetric/DistanceMetric";
5
+ export declare class KnnModel extends Model {
6
+ private data;
7
+ private k;
8
+ private distanceMetric;
9
+ /**
10
+ * Constructor that sets the data {@link InstanceList}, k value and the {@link DistanceMetric}.
11
+ *
12
+ * @param data {@link InstanceList} input.
13
+ * @param k K value.
14
+ * @param distanceMetric {@link DistanceMetric} input.
15
+ */
16
+ constructor(data: InstanceList, k: number, distanceMetric: DistanceMetric);
17
+ /**
18
+ * The predict method takes an {@link Instance} as an input and finds the nearest neighbors of given instance. Then
19
+ * it returns the first possible class label as the predicted class.
20
+ *
21
+ * @param instance {@link Instance} to make prediction.
22
+ * @return The first possible class label as the predicted class.
23
+ */
24
+ predict(instance: Instance): string;
25
+ predictProbability(instance: Instance): Map<string, number>;
26
+ /**
27
+ * The nearestNeighbors method takes an {@link Instance} as an input. First it gets the possible class labels, then loops
28
+ * through the data {@link InstanceList} and creates new {@link Array} of {@link KnnInstance}s and adds the corresponding data with
29
+ * the distance between data and given instance. After sorting this newly created ArrayList, it loops k times and
30
+ * returns the first k instances as an {@link InstanceList}.
31
+ *
32
+ * @param instance {@link Instance} to find nearest neighbors/
33
+ * @return The first k instances which are nearest to the given instance as an {@link InstanceList}.
34
+ */
35
+ nearestNeighbors(instance: Instance): InstanceList;
36
+ }
@@ -0,0 +1,83 @@
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", "../InstanceList/InstanceList", "../Instance/CompositeInstance", "./KnnInstance"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.KnnModel = void 0;
13
+ const Model_1 = require("./Model");
14
+ const InstanceList_1 = require("../InstanceList/InstanceList");
15
+ const CompositeInstance_1 = require("../Instance/CompositeInstance");
16
+ const KnnInstance_1 = require("./KnnInstance");
17
+ class KnnModel extends Model_1.Model {
18
+ /**
19
+ * Constructor that sets the data {@link InstanceList}, k value and the {@link DistanceMetric}.
20
+ *
21
+ * @param data {@link InstanceList} input.
22
+ * @param k K value.
23
+ * @param distanceMetric {@link DistanceMetric} input.
24
+ */
25
+ constructor(data, k, distanceMetric) {
26
+ super();
27
+ this.data = data;
28
+ this.k = k;
29
+ this.distanceMetric = distanceMetric;
30
+ }
31
+ /**
32
+ * The predict method takes an {@link Instance} as an input and finds the nearest neighbors of given instance. Then
33
+ * it returns the first possible class label as the predicted class.
34
+ *
35
+ * @param instance {@link Instance} to make prediction.
36
+ * @return The first possible class label as the predicted class.
37
+ */
38
+ predict(instance) {
39
+ let nearestNeighbors = this.nearestNeighbors(instance);
40
+ let predictedClass;
41
+ if (instance instanceof CompositeInstance_1.CompositeInstance && nearestNeighbors.size() == 0) {
42
+ predictedClass = instance.getPossibleClassLabels()[0];
43
+ }
44
+ else {
45
+ predictedClass = Model_1.Model.getMaximum(nearestNeighbors.getClassLabels());
46
+ }
47
+ return predictedClass;
48
+ }
49
+ predictProbability(instance) {
50
+ let nearestNeighbors = this.nearestNeighbors(instance);
51
+ return nearestNeighbors.classDistribution().getProbabilityDistribution();
52
+ }
53
+ /**
54
+ * The nearestNeighbors method takes an {@link Instance} as an input. First it gets the possible class labels, then loops
55
+ * through the data {@link InstanceList} and creates new {@link Array} of {@link KnnInstance}s and adds the corresponding data with
56
+ * the distance between data and given instance. After sorting this newly created ArrayList, it loops k times and
57
+ * returns the first k instances as an {@link InstanceList}.
58
+ *
59
+ * @param instance {@link Instance} to find nearest neighbors/
60
+ * @return The first k instances which are nearest to the given instance as an {@link InstanceList}.
61
+ */
62
+ nearestNeighbors(instance) {
63
+ let result = new InstanceList_1.InstanceList();
64
+ let instances = new Array();
65
+ let possibleClassLabels = undefined;
66
+ if (instance instanceof CompositeInstance_1.CompositeInstance) {
67
+ possibleClassLabels = instance.getPossibleClassLabels();
68
+ }
69
+ for (let i = 0; i < this.data.size(); i++) {
70
+ if (!(instance instanceof CompositeInstance_1.CompositeInstance) || possibleClassLabels.includes(this.data.get(i).getClassLabel())) {
71
+ instances.push(new KnnInstance_1.KnnInstance(this.data.get(i), this.distanceMetric.distance(this.data.get(i), instance)));
72
+ }
73
+ }
74
+ instances.sort((a, b) => a.getDistance() < b.getDistance() ? -1 : a.getDistance() > b.getDistance() ? 1 : 0);
75
+ for (let i = 0; i < Math.min(this.k, instances.length); i++) {
76
+ result.add(instances[i].getInstance());
77
+ }
78
+ return result;
79
+ }
80
+ }
81
+ exports.KnnModel = KnnModel;
82
+ });
83
+ //# sourceMappingURL=KnnModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KnnModel.js","sourceRoot":"","sources":["../../source/Model/KnnModel.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,mCAA8B;IAC9B,+DAA0D;IAG1D,qEAAgE;IAChE,+CAA0C;IAE1C,MAAa,QAAS,SAAQ,aAAK;QAM/B;;;;;;WAMG;QACH,YAAY,IAAkB,EAAE,CAAS,EAAE,cAA8B;YACrE,KAAK,EAAE,CAAC;YACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;YAChB,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;YACV,IAAI,CAAC,cAAc,GAAG,cAAc,CAAA;QACxC,CAAC;QAED;;;;;;WAMG;QACH,OAAO,CAAC,QAAkB;YACtB,IAAI,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;YACvD,IAAI,cAAc,CAAA;YAClB,IAAI,QAAQ,YAAY,qCAAiB,IAAI,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;gBACvE,cAAc,GAAwB,QAAS,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC,CAAC;aAC/E;iBAAM;gBACH,cAAc,GAAG,aAAK,CAAC,UAAU,CAAC,gBAAgB,CAAC,cAAc,EA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,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA,CAAC,CAAC,CAAC,CAAC,CAAC;YACtI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE;gBACzD,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;aAC1C;YACD,OAAO,MAAM,CAAC;QAClB,CAAC;KACJ;IAtED,4BAsEC"}
@@ -0,0 +1,25 @@
1
+ import { GaussianModel } from "./GaussianModel";
2
+ import { Vector } from "nlptoolkit-math/dist/Vector";
3
+ import { DiscreteDistribution } from "nlptoolkit-math/dist/DiscreteDistribution";
4
+ import { Instance } from "../Instance/Instance";
5
+ export declare class LdaModel extends GaussianModel {
6
+ protected w0: Map<string, number>;
7
+ protected w: Map<string, Vector>;
8
+ /**
9
+ * A constructor which sets the priorDistribution, w and w0 according to given inputs.
10
+ *
11
+ * @param priorDistribution {@link DiscreteDistribution} input.
12
+ * @param w {@link HashMap} of String and Vectors.
13
+ * @param w0 {@link HashMap} of String and Double.
14
+ */
15
+ constructor(priorDistribution: DiscreteDistribution, w: Map<string, Vector>, w0: Map<string, number>);
16
+ /**
17
+ * The calculateMetric method takes an {@link Instance} and a String as inputs. It returns the dot product of given Instance
18
+ * and wi plus w0i.
19
+ *
20
+ * @param instance {@link Instance} input.
21
+ * @param Ci String input.
22
+ * @return The dot product of given Instance and wi plus w0i.
23
+ */
24
+ calculateMetric(instance: Instance, Ci: string): number;
25
+ }
@@ -0,0 +1,45 @@
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.LdaModel = void 0;
13
+ const GaussianModel_1 = require("./GaussianModel");
14
+ class LdaModel extends GaussianModel_1.GaussianModel {
15
+ /**
16
+ * A constructor which sets the priorDistribution, w and w0 according to given inputs.
17
+ *
18
+ * @param priorDistribution {@link DiscreteDistribution} input.
19
+ * @param w {@link HashMap} of String and Vectors.
20
+ * @param w0 {@link HashMap} of String and Double.
21
+ */
22
+ constructor(priorDistribution, w, w0) {
23
+ super();
24
+ this.priorDistribution = priorDistribution;
25
+ this.w = w;
26
+ this.w0 = w0;
27
+ }
28
+ /**
29
+ * The calculateMetric method takes an {@link Instance} and a String as inputs. It returns the dot product of given Instance
30
+ * and wi plus w0i.
31
+ *
32
+ * @param instance {@link Instance} input.
33
+ * @param Ci String input.
34
+ * @return The dot product of given Instance and wi plus w0i.
35
+ */
36
+ calculateMetric(instance, Ci) {
37
+ let xi = instance.toVector();
38
+ let wi = this.w.get(Ci);
39
+ let w0i = this.w0.get(Ci);
40
+ return wi.dotProduct(xi) + w0i;
41
+ }
42
+ }
43
+ exports.LdaModel = LdaModel;
44
+ });
45
+ //# sourceMappingURL=LdaModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LdaModel.js","sourceRoot":"","sources":["../../source/Model/LdaModel.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,mDAA8C;IAK9C,MAAa,QAAS,SAAQ,6BAAa;QAKvC;;;;;;WAMG;QACH,YAAY,iBAAuC,EAAE,CAAsB,EAAE,EAAuB;YAChG,KAAK,EAAE,CAAC;YACR,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;YAC3C,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;YACX,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACjB,CAAC;QAED;;;;;;;WAOG;QACH,eAAe,CAAC,QAAkB,EAAE,EAAU;YAC1C,IAAI,EAAE,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAC7B,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACxB,IAAI,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC1B,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC;QACnC,CAAC;KACJ;IAjCD,4BAiCC"}
@@ -0,0 +1,21 @@
1
+ import { NeuralNetworkModel } from "./NeuralNetworkModel";
2
+ import { Matrix } from "nlptoolkit-math/dist/Matrix";
3
+ import { InstanceList } from "../InstanceList/InstanceList";
4
+ import { LinearPerceptronParameter } from "../Parameter/LinearPerceptronParameter";
5
+ export declare class LinearPerceptronModel extends NeuralNetworkModel {
6
+ protected W: Matrix;
7
+ /**
8
+ * Constructor that takes {@link InstanceList}s as trainsSet and validationSet. Initially it allocates layer weights,
9
+ * then creates an input vector by using given trainSet and finds error. Via the validationSet it finds the classification
10
+ * performance and at the end it reassigns the allocated weight Matrix with the matrix that has the best accuracy.
11
+ *
12
+ * @param trainSet InstanceList that is used to train.
13
+ * @param validationSet InstanceList that is used to validate.
14
+ * @param parameters Linear perceptron parameters; learningRate, etaDecrease, crossValidationRatio, epoch.
15
+ */
16
+ constructor(trainSet: InstanceList, validationSet?: InstanceList, parameters?: LinearPerceptronParameter);
17
+ /**
18
+ * The calculateOutput method calculates the {@link Matrix} y by multiplying Matrix W with {@link Vector} x.
19
+ */
20
+ protected calculateOutput(): void;
21
+ }
@@ -0,0 +1,62 @@
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", "../Performance/ClassificationPerformance"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.LinearPerceptronModel = void 0;
13
+ const NeuralNetworkModel_1 = require("./NeuralNetworkModel");
14
+ const Matrix_1 = require("nlptoolkit-math/dist/Matrix");
15
+ const ClassificationPerformance_1 = require("../Performance/ClassificationPerformance");
16
+ class LinearPerceptronModel extends NeuralNetworkModel_1.NeuralNetworkModel {
17
+ /**
18
+ * Constructor that takes {@link InstanceList}s as trainsSet and validationSet. Initially it allocates layer weights,
19
+ * then creates an input vector by using given trainSet and finds error. Via the validationSet it finds the classification
20
+ * performance and at the end it reassigns the allocated weight Matrix with the matrix that has the best accuracy.
21
+ *
22
+ * @param trainSet InstanceList that is used to train.
23
+ * @param validationSet InstanceList that is used to validate.
24
+ * @param parameters Linear perceptron parameters; learningRate, etaDecrease, crossValidationRatio, epoch.
25
+ */
26
+ constructor(trainSet, validationSet, parameters) {
27
+ super(trainSet);
28
+ if (validationSet != undefined) {
29
+ let W = this.allocateLayerWeights(this.K, this.d + 1);
30
+ let bestW = W.clone();
31
+ let bestClassificationPerformance = new ClassificationPerformance_1.ClassificationPerformance(0.0);
32
+ let epoch = parameters.getEpoch();
33
+ let learningRate = parameters.getLearningRate();
34
+ for (let i = 0; i < epoch; i++) {
35
+ trainSet.shuffle(parameters.getSeed());
36
+ for (let j = 0; j < trainSet.size(); j++) {
37
+ this.createInputVector(trainSet.get(j));
38
+ let rMinusY = this.calculateRMinusY(trainSet.get(j), this.x, W);
39
+ let deltaW = new Matrix_1.Matrix(rMinusY, this.x);
40
+ deltaW.multiplyWithConstant(learningRate);
41
+ W.add(deltaW);
42
+ }
43
+ let currentClassificationPerformance = this.testClassifier(validationSet);
44
+ if (currentClassificationPerformance.getAccuracy() > bestClassificationPerformance.getAccuracy()) {
45
+ bestClassificationPerformance = currentClassificationPerformance;
46
+ bestW = W.clone();
47
+ }
48
+ learningRate *= parameters.getEtaDecrease();
49
+ }
50
+ W = bestW;
51
+ }
52
+ }
53
+ /**
54
+ * The calculateOutput method calculates the {@link Matrix} y by multiplying Matrix W with {@link Vector} x.
55
+ */
56
+ calculateOutput() {
57
+ this.y = this.W.multiplyWithVectorFromRight(this.x);
58
+ }
59
+ }
60
+ exports.LinearPerceptronModel = LinearPerceptronModel;
61
+ });
62
+ //# sourceMappingURL=LinearPerceptronModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinearPerceptronModel.js","sourceRoot":"","sources":["../../source/Model/LinearPerceptronModel.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,6DAAwD;IACxD,wDAAmD;IAGnD,wFAAmF;IAEnF,MAAa,qBAAsB,SAAQ,uCAAkB;QAIzD;;;;;;;;WAQG;QACH,YAAY,QAAsB,EAAE,aAA4B,EAAE,UAAsC;YACpG,KAAK,CAAC,QAAQ,CAAC,CAAC;YAChB,IAAI,aAAa,IAAI,SAAS,EAAC;gBAC3B,IAAI,CAAC,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;gBACtD,IAAI,KAAK,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;gBACtB,IAAI,6BAA6B,GAAG,IAAI,qDAAyB,CAAC,GAAG,CAAC,CAAC;gBACvE,IAAI,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;gBAClC,IAAI,YAAY,GAAG,UAAU,CAAC,eAAe,EAAE,CAAC;gBAChD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE;oBAC5B,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;oBACvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;wBACtC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;wBACxC,IAAI,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;wBAChE,IAAI,MAAM,GAAG,IAAI,eAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;wBACzC,MAAM,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC;wBAC1C,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;qBACjB;oBACD,IAAI,gCAAgC,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;oBAC1E,IAAI,gCAAgC,CAAC,WAAW,EAAE,GAAG,6BAA6B,CAAC,WAAW,EAAE,EAAE;wBAC9F,6BAA6B,GAAG,gCAAgC,CAAC;wBACjE,KAAK,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;qBACrB;oBACD,YAAY,IAAI,UAAU,CAAC,cAAc,EAAE,CAAC;iBAC/C;gBACD,CAAC,GAAG,KAAK,CAAC;aACb;QACL,CAAC;QAED;;WAEG;QACO,eAAe;YACrB,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACxD,CAAC;KAEJ;IAhDD,sDAgDC"}
@@ -0,0 +1,12 @@
1
+ import { Instance } from "../Instance/Instance";
2
+ export declare abstract class Model {
3
+ abstract predict(instance: Instance): string;
4
+ abstract predictProbability(instance: Instance): Map<string, number>;
5
+ /**
6
+ * Given an array of class labels, returns the maximum occurred one.
7
+ *
8
+ * @param classLabels An array of class labels.
9
+ * @return The class label that occurs most in the array of class labels (mod of class label list).
10
+ */
11
+ static getMaximum(classLabels: Array<string>): string;
12
+ }
@@ -0,0 +1,31 @@
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", "nlptoolkit-datastructure/dist/CounterHashMap"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Model = void 0;
13
+ const CounterHashMap_1 = require("nlptoolkit-datastructure/dist/CounterHashMap");
14
+ class Model {
15
+ /**
16
+ * Given an array of class labels, returns the maximum occurred one.
17
+ *
18
+ * @param classLabels An array of class labels.
19
+ * @return The class label that occurs most in the array of class labels (mod of class label list).
20
+ */
21
+ static getMaximum(classLabels) {
22
+ let frequencies = new CounterHashMap_1.CounterHashMap();
23
+ for (let label of classLabels) {
24
+ frequencies.put(label);
25
+ }
26
+ return frequencies.max();
27
+ }
28
+ }
29
+ exports.Model = Model;
30
+ });
31
+ //# sourceMappingURL=Model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Model.js","sourceRoot":"","sources":["../../source/Model/Model.ts"],"names":[],"mappings":";;;;;;;;;;;;IACA,iFAA4E;IAE5E,MAAsB,KAAK;QAKvB;;;;;WAKG;QACH,MAAM,CAAC,UAAU,CAAC,WAA0B;YACxC,IAAI,WAAW,GAAG,IAAI,+BAAc,EAAU,CAAC;YAC/C,KAAK,IAAI,KAAK,IAAI,WAAW,EAAE;gBAC3B,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;aAC1B;YACD,OAAO,WAAW,CAAC,GAAG,EAAE,CAAC;QAC7B,CAAC;KACJ;IAlBD,sBAkBC"}
@@ -0,0 +1,29 @@
1
+ import { LinearPerceptronModel } from "./LinearPerceptronModel";
2
+ import { ActivationFunction } from "../Parameter/ActivationFunction";
3
+ import { InstanceList } from "../InstanceList/InstanceList";
4
+ import { MultiLayerPerceptronParameter } from "../Parameter/MultiLayerPerceptronParameter";
5
+ export declare class MultiLayerPerceptronModel extends LinearPerceptronModel {
6
+ private V;
7
+ protected activationFunction: ActivationFunction;
8
+ /**
9
+ * The allocateWeights method allocates layers' weights of Matrix W and V.
10
+ *
11
+ * @param H Integer value for weights.
12
+ */
13
+ private allocateWeights;
14
+ /**
15
+ * A constructor that takes {@link InstanceList}s as trainsSet and validationSet. It sets the {@link NeuralNetworkModel}
16
+ * nodes with given {@link InstanceList} then creates an input vector by using given trainSet and finds error.
17
+ * Via the validationSet it finds the classification performance and reassigns the allocated weight Matrix with the matrix
18
+ * that has the best accuracy and the Matrix V with the best Vector input.
19
+ *
20
+ * @param trainSet InstanceList that is used to train.
21
+ * @param validationSet InstanceList that is used to validate.
22
+ * @param parameters Multi layer perceptron parameters; seed, learningRate, etaDecrease, crossValidationRatio, epoch, hiddenNodes.
23
+ */
24
+ constructor(trainSet: InstanceList, validationSet: InstanceList, parameters: MultiLayerPerceptronParameter);
25
+ /**
26
+ * The calculateOutput method calculates the forward single hidden layer by using Matrices W and V.
27
+ */
28
+ protected calculateOutput(): void;
29
+ }
@@ -0,0 +1,101 @@
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", "./LinearPerceptronModel", "nlptoolkit-math/dist/Matrix", "../Parameter/ActivationFunction", "../Performance/ClassificationPerformance", "nlptoolkit-math/dist/Vector"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MultiLayerPerceptronModel = void 0;
13
+ const LinearPerceptronModel_1 = require("./LinearPerceptronModel");
14
+ const Matrix_1 = require("nlptoolkit-math/dist/Matrix");
15
+ const ActivationFunction_1 = require("../Parameter/ActivationFunction");
16
+ const ClassificationPerformance_1 = require("../Performance/ClassificationPerformance");
17
+ const Vector_1 = require("nlptoolkit-math/dist/Vector");
18
+ class MultiLayerPerceptronModel extends LinearPerceptronModel_1.LinearPerceptronModel {
19
+ /**
20
+ * A constructor that takes {@link InstanceList}s as trainsSet and validationSet. It sets the {@link NeuralNetworkModel}
21
+ * nodes with given {@link InstanceList} then creates an input vector by using given trainSet and finds error.
22
+ * Via the validationSet it finds the classification performance and reassigns the allocated weight Matrix with the matrix
23
+ * that has the best accuracy and the Matrix V with the best Vector input.
24
+ *
25
+ * @param trainSet InstanceList that is used to train.
26
+ * @param validationSet InstanceList that is used to validate.
27
+ * @param parameters Multi layer perceptron parameters; seed, learningRate, etaDecrease, crossValidationRatio, epoch, hiddenNodes.
28
+ */
29
+ constructor(trainSet, validationSet, parameters) {
30
+ super(trainSet);
31
+ this.activationFunction = parameters.getActivationFunction();
32
+ this.allocateWeights(parameters.getHiddenNodes());
33
+ let bestW = this.W.clone();
34
+ let bestV = this.V.clone();
35
+ let bestClassificationPerformance = new ClassificationPerformance_1.ClassificationPerformance(0.0);
36
+ let epoch = parameters.getEpoch();
37
+ let learningRate = parameters.getLearningRate();
38
+ for (let i = 0; i < epoch; i++) {
39
+ trainSet.shuffle(parameters.getSeed());
40
+ for (let j = 0; j < trainSet.size(); j++) {
41
+ this.createInputVector(trainSet.get(j));
42
+ let hidden = this.calculateHidden(this.x, this.W, this.activationFunction);
43
+ let hiddenBiased = hidden.biased();
44
+ let rMinusY = this.calculateRMinusY(trainSet.get(j), hiddenBiased, this.V);
45
+ let deltaV = new Matrix_1.Matrix(rMinusY, hiddenBiased);
46
+ let tmph = this.V.multiplyWithVectorFromLeft(rMinusY);
47
+ tmph.remove(0);
48
+ let activationDerivative;
49
+ switch (this.activationFunction) {
50
+ case ActivationFunction_1.ActivationFunction.SIGMOID:
51
+ default:
52
+ let oneMinusHidden = this.calculateOneMinusHidden(hidden);
53
+ activationDerivative = oneMinusHidden.elementProduct(hidden);
54
+ break;
55
+ case ActivationFunction_1.ActivationFunction.TANH:
56
+ let one = new Vector_1.Vector(hidden.size(), 1.0);
57
+ hidden.tanh();
58
+ activationDerivative = one.difference(hidden.elementProduct(hidden));
59
+ break;
60
+ case ActivationFunction_1.ActivationFunction.RELU:
61
+ hidden.reluDerivative();
62
+ activationDerivative = hidden;
63
+ break;
64
+ }
65
+ let tmpHidden = tmph.elementProduct(activationDerivative);
66
+ let deltaW = new Matrix_1.Matrix(tmpHidden, this.x);
67
+ deltaV.multiplyWithConstant(learningRate);
68
+ this.V.add(deltaV);
69
+ deltaW.multiplyWithConstant(learningRate);
70
+ this.W.add(deltaW);
71
+ }
72
+ let currentClassificationPerformance = this.testClassifier(validationSet);
73
+ if (currentClassificationPerformance.getAccuracy() > bestClassificationPerformance.getAccuracy()) {
74
+ bestClassificationPerformance = currentClassificationPerformance;
75
+ bestW = this.W.clone();
76
+ bestV = this.V.clone();
77
+ }
78
+ learningRate *= parameters.getEtaDecrease();
79
+ }
80
+ this.W = bestW;
81
+ this.V = bestV;
82
+ }
83
+ /**
84
+ * The allocateWeights method allocates layers' weights of Matrix W and V.
85
+ *
86
+ * @param H Integer value for weights.
87
+ */
88
+ allocateWeights(H) {
89
+ this.W = this.allocateLayerWeights(H, this.d + 1);
90
+ this.V = this.allocateLayerWeights(this.K, H + 1);
91
+ }
92
+ /**
93
+ * The calculateOutput method calculates the forward single hidden layer by using Matrices W and V.
94
+ */
95
+ calculateOutput() {
96
+ this.calculateForwardSingleHiddenLayer(this.W, this.V, this.activationFunction);
97
+ }
98
+ }
99
+ exports.MultiLayerPerceptronModel = MultiLayerPerceptronModel;
100
+ });
101
+ //# sourceMappingURL=MultiLayerPerceptronModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MultiLayerPerceptronModel.js","sourceRoot":"","sources":["../../source/Model/MultiLayerPerceptronModel.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,mEAA8D;IAC9D,wDAAmD;IACnD,wEAAmE;IAGnE,wFAAmF;IACnF,wDAAmD;IAEnD,MAAa,yBAA0B,SAAQ,6CAAqB;QAehE;;;;;;;;;WASG;QACH,YAAY,QAAsB,EAAE,aAA2B,EAAE,UAAyC;YACtG,KAAK,CAAC,QAAQ,CAAC,CAAC;YA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AE,GAAG,6BAA6B,CAAC,WAAW,EAAE,EAAE;oBAC9F,6BAA6B,GAAG,gCAAgC,CAAC;oBACjE,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;oBACvB,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;iBAC1B;gBACD,YAAY,IAAI,UAAU,CAAC,cAAc,EAAE,CAAC;aAC/C;YACD,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC;YACf,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC;QACnB,CAAC;QAzED;;;;WAIG;QACK,eAAe,CAAC,CAAS;YAC7B,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,oBAAoB,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAClD,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACtD,CAAC;QAmED;;WAEG;QACO,eAAe;YACrB,IAAI,CAAC,iCAAiC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACpF,CAAC;KACJ;IAtFD,8DAsFC"}
@@ -0,0 +1,47 @@
1
+ import { GaussianModel } from "./GaussianModel";
2
+ import { Instance } from "../Instance/Instance";
3
+ import { Vector } from "nlptoolkit-math/dist/Vector";
4
+ import { DiscreteDistribution } from "nlptoolkit-math/dist/DiscreteDistribution";
5
+ export declare class NaiveBayesModel extends GaussianModel {
6
+ private classMeans;
7
+ private classDeviations;
8
+ private readonly classAttributeDistributions;
9
+ /**
10
+ * A constructor that sets the priorDistribution, classMeans and classDeviations.
11
+ *
12
+ * @param priorDistribution {@link DiscreteDistribution} input.
13
+ * @param classMeans A {@link Map} of String and {@link Vector}.
14
+ * @param classDeviations A {@link Map} of String and {@link Vector}.
15
+ */
16
+ constructor(priorDistribution: DiscreteDistribution, classMeans: any, classDeviations?: Map<string, Vector>);
17
+ /**
18
+ * The calculateMetric method takes an {@link Instance} and a String as inputs, and it returns the log likelihood of
19
+ * these inputs.
20
+ *
21
+ * @param instance {@link Instance} input.
22
+ * @param Ci String input.
23
+ * @return The log likelihood of inputs.
24
+ */
25
+ calculateMetric(instance: Instance, Ci: string): number;
26
+ /**
27
+ * The logLikelihoodContinuous method takes an {@link Instance} and a class label as inputs. First it gets the logarithm
28
+ * of given class label's probability via prior distribution as logLikelihood. Then it loops times of given instance attribute size, and accumulates the
29
+ * logLikelihood by calculating -0.5 * ((xi - mi) / si )** 2).
30
+ *
31
+ * @param classLabel String input class label.
32
+ * @param instance {@link Instance} input.
33
+ * @return The log likelihood of given class label and {@link Instance}.
34
+ */
35
+ private logLikelihoodContinuous;
36
+ /**
37
+ * The logLikelihoodDiscrete method takes an {@link Instance} and a class label as inputs. First it gets the logarithm
38
+ * of given class label's probability via prior distribution as logLikelihood and gets the class attribute distribution of given class label.
39
+ * Then it loops times of given instance attribute size, and accumulates the logLikelihood by calculating the logarithm of
40
+ * corresponding attribute distribution's smoothed probability by using laplace smoothing on xi.
41
+ *
42
+ * @param classLabel String input class label.
43
+ * @param instance {@link Instance} input.
44
+ * @return The log likelihood of given class label and {@link Instance}.
45
+ */
46
+ private logLikelihoodDiscrete;
47
+ }
@@ -0,0 +1,95 @@
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.NaiveBayesModel = void 0;
13
+ const GaussianModel_1 = require("./GaussianModel");
14
+ class NaiveBayesModel extends GaussianModel_1.GaussianModel {
15
+ /**
16
+ * A constructor that sets the priorDistribution, classMeans and classDeviations.
17
+ *
18
+ * @param priorDistribution {@link DiscreteDistribution} input.
19
+ * @param classMeans A {@link Map} of String and {@link Vector}.
20
+ * @param classDeviations A {@link Map} of String and {@link Vector}.
21
+ */
22
+ constructor(priorDistribution, classMeans, classDeviations) {
23
+ super();
24
+ this.classMeans = undefined;
25
+ this.classDeviations = undefined;
26
+ this.classAttributeDistributions = undefined;
27
+ this.priorDistribution = priorDistribution;
28
+ if (classDeviations != undefined) {
29
+ this.classMeans = classMeans;
30
+ this.classDeviations = classDeviations;
31
+ }
32
+ else {
33
+ this.classAttributeDistributions = classMeans;
34
+ }
35
+ }
36
+ /**
37
+ * The calculateMetric method takes an {@link Instance} and a String as inputs, and it returns the log likelihood of
38
+ * these inputs.
39
+ *
40
+ * @param instance {@link Instance} input.
41
+ * @param Ci String input.
42
+ * @return The log likelihood of inputs.
43
+ */
44
+ calculateMetric(instance, Ci) {
45
+ if (this.classAttributeDistributions == undefined) {
46
+ return this.logLikelihoodContinuous(Ci, instance);
47
+ }
48
+ else {
49
+ return this.logLikelihoodDiscrete(Ci, instance);
50
+ }
51
+ }
52
+ /**
53
+ * The logLikelihoodContinuous method takes an {@link Instance} and a class label as inputs. First it gets the logarithm
54
+ * of given class label's probability via prior distribution as logLikelihood. Then it loops times of given instance attribute size, and accumulates the
55
+ * logLikelihood by calculating -0.5 * ((xi - mi) / si )** 2).
56
+ *
57
+ * @param classLabel String input class label.
58
+ * @param instance {@link Instance} input.
59
+ * @return The log likelihood of given class label and {@link Instance}.
60
+ */
61
+ logLikelihoodContinuous(classLabel, instance) {
62
+ let logLikelihood = Math.log(this.priorDistribution.getProbability(classLabel));
63
+ for (let i = 0; i < instance.attributeSize(); i++) {
64
+ let xi = instance.getAttribute(i).getValue();
65
+ let mi = this.classMeans.get(classLabel).getValue(i);
66
+ let si = this.classDeviations.get(classLabel).getValue(i);
67
+ if (si != 0) {
68
+ logLikelihood += -0.5 * Math.pow((xi - mi) / si, 2);
69
+ }
70
+ }
71
+ return logLikelihood;
72
+ }
73
+ /**
74
+ * The logLikelihoodDiscrete method takes an {@link Instance} and a class label as inputs. First it gets the logarithm
75
+ * of given class label's probability via prior distribution as logLikelihood and gets the class attribute distribution of given class label.
76
+ * Then it loops times of given instance attribute size, and accumulates the logLikelihood by calculating the logarithm of
77
+ * corresponding attribute distribution's smoothed probability by using laplace smoothing on xi.
78
+ *
79
+ * @param classLabel String input class label.
80
+ * @param instance {@link Instance} input.
81
+ * @return The log likelihood of given class label and {@link Instance}.
82
+ */
83
+ logLikelihoodDiscrete(classLabel, instance) {
84
+ let logLikelihood = Math.log(this.priorDistribution.getProbability(classLabel));
85
+ let attributeDistributions = this.classAttributeDistributions.get(classLabel);
86
+ for (let i = 0; i < instance.attributeSize(); i++) {
87
+ let xi = instance.getAttribute(i).getValue();
88
+ logLikelihood += Math.log(attributeDistributions[i].getProbabilityLaplaceSmoothing(xi));
89
+ }
90
+ return logLikelihood;
91
+ }
92
+ }
93
+ exports.NaiveBayesModel = NaiveBayesModel;
94
+ });
95
+ //# sourceMappingURL=NaiveBayesModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NaiveBayesModel.js","sourceRoot":"","sources":["../../source/Model/NaiveBayesModel.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,mDAA8C;IAO9C,MAAa,eAAgB,SAAQ,6BAAa;QAM9C;;;;;;WAMG;QACH,YAAY,iBAAuC,EAAE,UAAe,EAAE,eAAqC;YACvG,KAAK,EAAE,CAAC;YAZJ,eAAU,GAAwB,SAAS,CAAA;YAC3C,oBAAe,GAAwB,SAAS,CAAA;YACvC,gCAA2B,GAA6C,SAAS,CAAA;YAW9F,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;YAC1C,IAAI,eAAe,IAAI,SAAS,EAAC;gBAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;gBAC5B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;aACzC;iBAAM;gBACH,IAAI,CAAC,2BAA2B,G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