nlptoolkit-classification 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/Attribute/Attribute.js +6 -16
- package/dist/Attribute/Attribute.js.map +1 -1
- package/dist/Attribute/AttributeType.js +22 -32
- package/dist/Attribute/AttributeType.js.map +1 -1
- package/dist/Attribute/BinaryAttribute.js +14 -24
- package/dist/Attribute/BinaryAttribute.js.map +1 -1
- package/dist/Attribute/ContinuousAttribute.js +46 -55
- package/dist/Attribute/ContinuousAttribute.js.map +1 -1
- package/dist/Attribute/DiscreteAttribute.d.ts +1 -1
- package/dist/Attribute/DiscreteAttribute.js +38 -48
- package/dist/Attribute/DiscreteAttribute.js.map +1 -1
- package/dist/Attribute/DiscreteIndexedAttribute.d.ts +2 -2
- package/dist/Attribute/DiscreteIndexedAttribute.js +47 -55
- package/dist/Attribute/DiscreteIndexedAttribute.js.map +1 -1
- package/dist/DataSet/DataDefinition.d.ts +11 -0
- package/dist/DataSet/DataDefinition.js +115 -112
- package/dist/DataSet/DataDefinition.js.map +1 -1
- package/dist/DataSet/DataSet.js +268 -245
- package/dist/DataSet/DataSet.js.map +1 -1
- package/dist/DistanceMetric/DistanceMetric.js +2 -12
- package/dist/DistanceMetric/EuclidianDistance.js +27 -37
- package/dist/DistanceMetric/EuclidianDistance.js.map +1 -1
- package/dist/DistanceMetric/MahalanobisDistance.js +27 -36
- package/dist/DistanceMetric/MahalanobisDistance.js.map +1 -1
- package/dist/Experiment/BootstrapRun.js +31 -40
- package/dist/Experiment/BootstrapRun.js.map +1 -1
- package/dist/Experiment/Experiment.d.ts +7 -7
- package/dist/Experiment/Experiment.js +46 -53
- package/dist/Experiment/Experiment.js.map +1 -1
- package/dist/Experiment/KFoldRun.d.ts +17 -2
- package/dist/Experiment/KFoldRun.js +45 -39
- package/dist/Experiment/KFoldRun.js.map +1 -1
- package/dist/Experiment/KFoldRunSeparateTest.d.ts +13 -2
- package/dist/Experiment/KFoldRunSeparateTest.js +48 -47
- package/dist/Experiment/KFoldRunSeparateTest.js.map +1 -1
- package/dist/Experiment/MultipleRun.js +2 -12
- package/dist/Experiment/MxKFoldRun.js +31 -40
- package/dist/Experiment/MxKFoldRun.js.map +1 -1
- package/dist/Experiment/MxKFoldRunSeparateTest.js +35 -44
- package/dist/Experiment/MxKFoldRunSeparateTest.js.map +1 -1
- package/dist/Experiment/SingleRun.js +2 -12
- package/dist/Experiment/SingleRunWithK.d.ts +18 -3
- package/dist/Experiment/SingleRunWithK.js +39 -33
- package/dist/Experiment/SingleRunWithK.js.map +1 -1
- package/dist/Experiment/StratifiedKFoldRun.js +26 -36
- package/dist/Experiment/StratifiedKFoldRun.js.map +1 -1
- package/dist/Experiment/StratifiedKFoldRunSeparateTest.js +30 -40
- package/dist/Experiment/StratifiedKFoldRunSeparateTest.js.map +1 -1
- package/dist/Experiment/StratifiedMxKFoldRun.js +29 -39
- package/dist/Experiment/StratifiedMxKFoldRun.js.map +1 -1
- package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js +34 -43
- package/dist/Experiment/StratifiedMxKFoldRunSeparateTest.js.map +1 -1
- package/dist/Experiment/StratifiedSingleRunWithK.js +27 -36
- package/dist/Experiment/StratifiedSingleRunWithK.js.map +1 -1
- package/dist/FeatureSelection/BackwardSelection.js +26 -36
- package/dist/FeatureSelection/BackwardSelection.js.map +1 -1
- package/dist/FeatureSelection/FeatureSubSet.js +72 -82
- package/dist/FeatureSelection/FeatureSubSet.js.map +1 -1
- package/dist/FeatureSelection/FloatingSelection.js +25 -35
- package/dist/FeatureSelection/FloatingSelection.js.map +1 -1
- package/dist/FeatureSelection/ForwardSelection.js +25 -35
- package/dist/FeatureSelection/ForwardSelection.js.map +1 -1
- package/dist/FeatureSelection/SubSetSelection.js +69 -78
- package/dist/FeatureSelection/SubSetSelection.js.map +1 -1
- package/dist/Filter/DiscreteToContinuous.js +50 -60
- package/dist/Filter/DiscreteToContinuous.js.map +1 -1
- package/dist/Filter/DiscreteToIndexed.js +40 -50
- package/dist/Filter/DiscreteToIndexed.js.map +1 -1
- package/dist/Filter/FeatureFilter.js +23 -32
- package/dist/Filter/FeatureFilter.js.map +1 -1
- package/dist/Filter/LaryFilter.d.ts +1 -1
- package/dist/Filter/LaryFilter.js +46 -55
- package/dist/Filter/LaryFilter.js.map +1 -1
- package/dist/Filter/LaryToBinary.js +48 -58
- package/dist/Filter/LaryToBinary.js.map +1 -1
- package/dist/Filter/Normalize.js +33 -41
- package/dist/Filter/Normalize.js.map +1 -1
- package/dist/Filter/Pca.js +86 -96
- package/dist/Filter/Pca.js.map +1 -1
- package/dist/Filter/TrainedFeatureFilter.d.ts +1 -1
- package/dist/Filter/TrainedFeatureFilter.js +14 -24
- package/dist/Filter/TrainedFeatureFilter.js.map +1 -1
- package/dist/Instance/CompositeInstance.js +46 -56
- package/dist/Instance/CompositeInstance.js.map +1 -1
- package/dist/Instance/Instance.js +145 -154
- package/dist/Instance/Instance.js.map +1 -1
- package/dist/InstanceList/InstanceList.js +466 -443
- package/dist/InstanceList/InstanceList.js.map +1 -1
- package/dist/InstanceList/InstanceListOfSameClass.js +23 -32
- package/dist/InstanceList/InstanceListOfSameClass.js.map +1 -1
- package/dist/InstanceList/Partition.d.ts +45 -0
- package/dist/InstanceList/Partition.js +176 -131
- package/dist/InstanceList/Partition.js.map +1 -1
- package/dist/Model/DecisionTree/DecisionCondition.d.ts +8 -0
- package/dist/Model/DecisionTree/DecisionCondition.js +71 -72
- package/dist/Model/DecisionTree/DecisionCondition.js.map +1 -1
- package/dist/Model/DecisionTree/DecisionNode.d.ts +38 -1
- package/dist/Model/DecisionTree/DecisionNode.js +302 -275
- package/dist/Model/DecisionTree/DecisionNode.js.map +1 -1
- package/dist/Model/DecisionTree/DecisionStump.d.ts +17 -0
- package/dist/Model/DecisionTree/DecisionStump.js +25 -0
- package/dist/Model/DecisionTree/DecisionStump.js.map +1 -0
- package/dist/Model/DecisionTree/DecisionTree.d.ts +24 -9
- package/dist/Model/DecisionTree/DecisionTree.js +90 -76
- package/dist/Model/DecisionTree/DecisionTree.js.map +1 -1
- package/dist/Model/DummyModel.d.ts +28 -3
- package/dist/Model/DummyModel.js +64 -50
- package/dist/Model/DummyModel.js.map +1 -1
- package/dist/{Classifier/Bagging.d.ts → Model/Ensemble/BaggingModel.d.ts} +8 -4
- package/dist/Model/Ensemble/BaggingModel.js +37 -0
- package/dist/Model/Ensemble/BaggingModel.js.map +1 -0
- package/dist/{Classifier/RandomForest.d.ts → Model/Ensemble/RandomForestModel.d.ts} +8 -4
- package/dist/Model/Ensemble/RandomForestModel.js +34 -0
- package/dist/Model/Ensemble/RandomForestModel.js.map +1 -0
- package/dist/Model/Ensemble/TreeEnsembleModel.d.ts +32 -0
- package/dist/Model/Ensemble/TreeEnsembleModel.js +61 -0
- package/dist/Model/Ensemble/TreeEnsembleModel.js.map +1 -0
- package/dist/Model/Model.d.ts +50 -0
- package/dist/Model/Model.js +131 -72
- package/dist/Model/Model.js.map +1 -1
- package/dist/Model/NeuralNetwork/DeepNetworkModel.d.ts +47 -0
- package/dist/Model/NeuralNetwork/DeepNetworkModel.js +180 -0
- package/dist/Model/NeuralNetwork/DeepNetworkModel.js.map +1 -0
- package/dist/Model/NeuralNetwork/LinearPerceptronModel.d.ts +31 -0
- package/dist/Model/NeuralNetwork/LinearPerceptronModel.js +75 -0
- package/dist/Model/NeuralNetwork/LinearPerceptronModel.js.map +1 -0
- package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.d.ts +39 -0
- package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.js +119 -0
- package/dist/Model/NeuralNetwork/MultiLayerPerceptronModel.js.map +1 -0
- package/dist/Model/{NeuralNetworkModel.d.ts → NeuralNetwork/NeuralNetworkModel.d.ts} +19 -5
- package/dist/Model/NeuralNetwork/NeuralNetworkModel.js +211 -0
- package/dist/Model/NeuralNetwork/NeuralNetworkModel.js.map +1 -0
- package/dist/Model/{KnnInstance.d.ts → NonParametric/KnnInstance.d.ts} +1 -1
- package/dist/Model/NonParametric/KnnInstance.js +25 -0
- package/dist/Model/NonParametric/KnnInstance.js.map +1 -0
- package/dist/Model/{KnnModel.d.ts → NonParametric/KnnModel.d.ts} +30 -6
- package/dist/Model/NonParametric/KnnModel.js +111 -0
- package/dist/Model/NonParametric/KnnModel.js.map +1 -0
- package/dist/Model/{GaussianModel.d.ts → Parametric/GaussianModel.d.ts} +20 -2
- package/dist/Model/Parametric/GaussianModel.js +95 -0
- package/dist/Model/Parametric/GaussianModel.js.map +1 -0
- package/dist/Model/Parametric/KMeansModel.d.ts +36 -0
- package/dist/Model/Parametric/KMeansModel.js +65 -0
- package/dist/Model/Parametric/KMeansModel.js.map +1 -0
- package/dist/Model/Parametric/LdaModel.d.ts +44 -0
- package/dist/Model/Parametric/LdaModel.js +90 -0
- package/dist/Model/Parametric/LdaModel.js.map +1 -0
- package/dist/Model/{NaiveBayesModel.d.ts → Parametric/NaiveBayesModel.d.ts} +30 -10
- package/dist/Model/Parametric/NaiveBayesModel.js +131 -0
- package/dist/Model/Parametric/NaiveBayesModel.js.map +1 -0
- package/dist/Model/Parametric/QdaModel.d.ts +30 -0
- package/dist/Model/Parametric/QdaModel.js +75 -0
- package/dist/Model/Parametric/QdaModel.js.map +1 -0
- package/dist/Model/RandomModel.d.ts +32 -2
- package/dist/Model/RandomModel.js +85 -60
- package/dist/Model/RandomModel.js.map +1 -1
- package/dist/Model/ValidatedModel.js +21 -31
- package/dist/Model/ValidatedModel.js.map +1 -1
- package/dist/Parameter/ActivationFunction.js +9 -19
- package/dist/Parameter/ActivationFunction.js.map +1 -1
- package/dist/Parameter/BaggingParameter.js +24 -33
- package/dist/Parameter/BaggingParameter.js.map +1 -1
- package/dist/Parameter/C45Parameter.d.ts +2 -2
- package/dist/Parameter/C45Parameter.js +34 -42
- package/dist/Parameter/C45Parameter.js.map +1 -1
- package/dist/Parameter/DeepNetworkParameter.d.ts +2 -2
- package/dist/Parameter/DeepNetworkParameter.js +48 -56
- package/dist/Parameter/DeepNetworkParameter.js.map +1 -1
- package/dist/Parameter/KMeansParameter.js +29 -38
- package/dist/Parameter/KMeansParameter.js.map +1 -1
- package/dist/Parameter/KnnParameter.d.ts +1 -1
- package/dist/Parameter/KnnParameter.js +25 -34
- package/dist/Parameter/KnnParameter.js.map +1 -1
- package/dist/Parameter/LinearPerceptronParameter.d.ts +4 -4
- package/dist/Parameter/LinearPerceptronParameter.js +56 -62
- package/dist/Parameter/LinearPerceptronParameter.js.map +1 -1
- package/dist/Parameter/MultiLayerPerceptronParameter.d.ts +2 -2
- package/dist/Parameter/MultiLayerPerceptronParameter.js +38 -46
- package/dist/Parameter/MultiLayerPerceptronParameter.js.map +1 -1
- package/dist/Parameter/Parameter.d.ts +1 -1
- package/dist/Parameter/Parameter.js +21 -30
- package/dist/Parameter/Parameter.js.map +1 -1
- package/dist/Parameter/RandomForestParameter.js +25 -34
- package/dist/Parameter/RandomForestParameter.js.map +1 -1
- package/dist/Performance/ClassificationPerformance.js +24 -33
- package/dist/Performance/ClassificationPerformance.js.map +1 -1
- package/dist/Performance/ConfusionMatrix.d.ts +1 -1
- package/dist/Performance/ConfusionMatrix.js +149 -158
- package/dist/Performance/ConfusionMatrix.js.map +1 -1
- package/dist/Performance/DetailedClassificationPerformance.js +23 -32
- package/dist/Performance/DetailedClassificationPerformance.js.map +1 -1
- package/dist/Performance/ExperimentPerformance.js +184 -161
- package/dist/Performance/ExperimentPerformance.js.map +1 -1
- package/dist/Performance/Performance.js +21 -30
- package/dist/Performance/Performance.js.map +1 -1
- package/dist/StatisticalTest/Combined5x2F.d.ts +12 -0
- package/dist/StatisticalTest/Combined5x2F.js +41 -39
- package/dist/StatisticalTest/Combined5x2F.js.map +1 -1
- package/dist/StatisticalTest/Combined5x2t.d.ts +13 -0
- package/dist/StatisticalTest/Combined5x2t.js +42 -39
- package/dist/StatisticalTest/Combined5x2t.js.map +1 -1
- package/dist/StatisticalTest/Paired5x2t.d.ts +12 -0
- package/dist/StatisticalTest/Paired5x2t.js +40 -38
- package/dist/StatisticalTest/Paired5x2t.js.map +1 -1
- package/dist/StatisticalTest/PairedTest.d.ts +12 -0
- package/dist/StatisticalTest/PairedTest.js +31 -29
- package/dist/StatisticalTest/PairedTest.js.map +1 -1
- package/dist/StatisticalTest/Pairedt.d.ts +12 -0
- package/dist/StatisticalTest/Pairedt.js +38 -36
- package/dist/StatisticalTest/Pairedt.js.map +1 -1
- package/dist/StatisticalTest/Sign.d.ts +17 -0
- package/dist/StatisticalTest/Sign.js +50 -43
- package/dist/StatisticalTest/Sign.js.map +1 -1
- package/dist/StatisticalTest/StatisticalTestResult.d.ts +30 -0
- package/dist/StatisticalTest/StatisticalTestResult.js +65 -43
- package/dist/StatisticalTest/StatisticalTestResult.js.map +1 -1
- package/dist/StatisticalTest/StatisticalTestResultType.js +11 -21
- package/dist/StatisticalTest/StatisticalTestResultType.js.map +1 -1
- package/dist/index.d.ts +88 -0
- package/dist/index.js +105 -0
- package/dist/index.js.map +1 -0
- package/package.json +9 -8
- package/source/Attribute/DiscreteAttribute.ts +1 -1
- package/source/Attribute/DiscreteIndexedAttribute.ts +2 -2
- package/source/DataSet/DataDefinition.ts +11 -0
- package/source/Experiment/BootstrapRun.ts +2 -2
- package/source/Experiment/Experiment.ts +10 -10
- package/source/Experiment/KFoldRun.ts +20 -5
- package/source/Experiment/KFoldRunSeparateTest.ts +16 -5
- package/source/Experiment/MxKFoldRun.ts +1 -1
- package/source/Experiment/MxKFoldRunSeparateTest.ts +1 -1
- package/source/Experiment/SingleRunWithK.ts +20 -5
- package/source/Experiment/StratifiedKFoldRun.ts +1 -1
- package/source/Experiment/StratifiedKFoldRunSeparateTest.ts +1 -1
- package/source/Experiment/StratifiedMxKFoldRun.ts +1 -1
- package/source/Experiment/StratifiedMxKFoldRunSeparateTest.ts +3 -3
- package/source/Experiment/StratifiedSingleRunWithK.ts +1 -1
- package/source/Filter/LaryFilter.ts +1 -1
- package/source/Filter/TrainedFeatureFilter.ts +1 -1
- package/source/InstanceList/Partition.ts +125 -65
- package/source/Model/DecisionTree/DecisionCondition.ts +8 -0
- package/source/Model/DecisionTree/DecisionNode.ts +56 -20
- package/source/Model/DecisionTree/DecisionStump.ts +26 -0
- package/source/Model/DecisionTree/DecisionTree.ts +44 -15
- package/source/Model/DummyModel.ts +40 -10
- package/source/{Classifier/Bagging.ts → Model/Ensemble/BaggingModel.ts} +15 -12
- package/source/{Classifier/RandomForest.ts → Model/Ensemble/RandomForestModel.ts} +14 -12
- package/source/Model/{TreeEnsembleModel.ts → Ensemble/TreeEnsembleModel.ts} +26 -18
- package/source/Model/Model.ts +77 -0
- package/source/Model/{DeepNetworkModel.ts → NeuralNetwork/DeepNetworkModel.ts} +59 -56
- package/source/Model/NeuralNetwork/LinearPerceptronModel.ts +81 -0
- package/source/Model/{MultiLayerPerceptronModel.ts → NeuralNetwork/MultiLayerPerceptronModel.ts} +46 -39
- package/source/Model/{NeuralNetworkModel.ts → NeuralNetwork/NeuralNetworkModel.ts} +20 -7
- package/source/Model/{KnnInstance.ts → NonParametric/KnnInstance.ts} +1 -1
- package/source/Model/{KnnModel.ts → NonParametric/KnnModel.ts} +48 -19
- package/source/Model/{GaussianModel.ts → Parametric/GaussianModel.ts} +21 -3
- package/source/Model/Parametric/KMeansModel.ts +72 -0
- package/source/Model/Parametric/LdaModel.ts +98 -0
- package/source/Model/{NaiveBayesModel.ts → Parametric/NaiveBayesModel.ts} +68 -25
- package/source/Model/Parametric/QdaModel.ts +83 -0
- package/source/Model/RandomModel.ts +54 -16
- package/source/Parameter/C45Parameter.ts +2 -2
- package/source/Parameter/DeepNetworkParameter.ts +2 -2
- package/source/Parameter/KnnParameter.ts +1 -1
- package/source/Parameter/LinearPerceptronParameter.ts +4 -4
- package/source/Parameter/MultiLayerPerceptronParameter.ts +2 -2
- package/source/Parameter/Parameter.ts +1 -1
- package/source/Performance/ConfusionMatrix.ts +1 -1
- package/source/StatisticalTest/Combined5x2F.ts +12 -0
- package/source/StatisticalTest/Combined5x2t.ts +13 -0
- package/source/StatisticalTest/Paired5x2t.ts +12 -0
- package/source/StatisticalTest/PairedTest.ts +12 -0
- package/source/StatisticalTest/Pairedt.ts +12 -0
- package/source/StatisticalTest/Sign.ts +17 -0
- package/source/StatisticalTest/StatisticalTestResult.ts +30 -0
- package/source/index.ts +88 -0
- package/tests/Classifier/C45Test.ts +2 -2
- package/tests/Classifier/DeepNetworkTest.ts +3 -5
- package/tests/Classifier/DummyTest.ts +2 -2
- package/tests/Classifier/KMeansTest.ts +2 -2
- package/tests/Classifier/KnnTest.ts +2 -2
- package/tests/Classifier/LdaTest.ts +2 -2
- package/tests/Classifier/LinearPerceptronTest.ts +2 -2
- package/tests/Classifier/MultiLayerPerceptronTest.ts +2 -3
- package/tests/Classifier/NaiveBayesTest.ts +2 -2
- package/tests/Classifier/QdaTest.ts +2 -2
- package/tests/Classifier/RandomForestTest.ts +2 -2
- package/tsconfig.json +4 -4
- package/dist/Classifier/Bagging.js +0 -45
- package/dist/Classifier/Bagging.js.map +0 -1
- package/dist/Classifier/C45.d.ts +0 -14
- package/dist/Classifier/C45.js +0 -43
- package/dist/Classifier/C45.js.map +0 -1
- package/dist/Classifier/C45Stump.d.ts +0 -13
- package/dist/Classifier/C45Stump.js +0 -32
- package/dist/Classifier/C45Stump.js.map +0 -1
- package/dist/Classifier/Classifier.d.ts +0 -40
- package/dist/Classifier/Classifier.js +0 -72
- package/dist/Classifier/Classifier.js.map +0 -1
- package/dist/Classifier/DeepNetwork.d.ts +0 -14
- package/dist/Classifier/DeepNetwork.js +0 -34
- package/dist/Classifier/DeepNetwork.js.map +0 -1
- package/dist/Classifier/Dummy.d.ts +0 -14
- package/dist/Classifier/Dummy.js +0 -32
- package/dist/Classifier/Dummy.js.map +0 -1
- package/dist/Classifier/KMeans.d.ts +0 -13
- package/dist/Classifier/KMeans.js +0 -39
- package/dist/Classifier/KMeans.js.map +0 -1
- package/dist/Classifier/Knn.d.ts +0 -14
- package/dist/Classifier/Knn.js +0 -32
- package/dist/Classifier/Knn.js.map +0 -1
- package/dist/Classifier/Lda.d.ts +0 -13
- package/dist/Classifier/Lda.js +0 -55
- package/dist/Classifier/Lda.js.map +0 -1
- package/dist/Classifier/LinearPerceptron.d.ts +0 -15
- package/dist/Classifier/LinearPerceptron.js +0 -35
- package/dist/Classifier/LinearPerceptron.js.map +0 -1
- package/dist/Classifier/MultiLayerPerceptron.d.ts +0 -15
- package/dist/Classifier/MultiLayerPerceptron.js +0 -35
- package/dist/Classifier/MultiLayerPerceptron.js.map +0 -1
- package/dist/Classifier/NaiveBayes.d.ts +0 -26
- package/dist/Classifier/NaiveBayes.js +0 -70
- package/dist/Classifier/NaiveBayes.js.map +0 -1
- package/dist/Classifier/Qda.d.ts +0 -13
- package/dist/Classifier/Qda.js +0 -53
- package/dist/Classifier/Qda.js.map +0 -1
- package/dist/Classifier/RandomClassifier.d.ts +0 -13
- package/dist/Classifier/RandomClassifier.js +0 -35
- package/dist/Classifier/RandomClassifier.js.map +0 -1
- package/dist/Classifier/RandomForest.js +0 -42
- package/dist/Classifier/RandomForest.js.map +0 -1
- package/dist/Model/DeepNetworkModel.d.ts +0 -45
- package/dist/Model/DeepNetworkModel.js +0 -187
- package/dist/Model/DeepNetworkModel.js.map +0 -1
- package/dist/Model/GaussianModel.js +0 -86
- package/dist/Model/GaussianModel.js.map +0 -1
- package/dist/Model/KMeansModel.d.ts +0 -28
- package/dist/Model/KMeansModel.js +0 -61
- package/dist/Model/KMeansModel.js.map +0 -1
- package/dist/Model/KnnInstance.js +0 -33
- package/dist/Model/KnnInstance.js.map +0 -1
- package/dist/Model/KnnModel.js +0 -95
- package/dist/Model/KnnModel.js.map +0 -1
- package/dist/Model/LdaModel.d.ts +0 -28
- package/dist/Model/LdaModel.js +0 -67
- package/dist/Model/LdaModel.js.map +0 -1
- package/dist/Model/LinearPerceptronModel.d.ts +0 -24
- package/dist/Model/LinearPerceptronModel.js +0 -91
- package/dist/Model/LinearPerceptronModel.js.map +0 -1
- package/dist/Model/MultiLayerPerceptronModel.d.ts +0 -33
- package/dist/Model/MultiLayerPerceptronModel.js +0 -123
- package/dist/Model/MultiLayerPerceptronModel.js.map +0 -1
- package/dist/Model/NaiveBayesModel.js +0 -107
- package/dist/Model/NaiveBayesModel.js.map +0 -1
- package/dist/Model/NeuralNetworkModel.js +0 -202
- package/dist/Model/NeuralNetworkModel.js.map +0 -1
- package/dist/Model/QdaModel.d.ts +0 -27
- package/dist/Model/QdaModel.js +0 -63
- package/dist/Model/QdaModel.js.map +0 -1
- package/dist/Model/TreeEnsembleModel.d.ts +0 -22
- package/dist/Model/TreeEnsembleModel.js +0 -64
- package/dist/Model/TreeEnsembleModel.js.map +0 -1
- package/index.js +0 -100
- package/source/Classifier/C45.ts +0 -34
- package/source/Classifier/C45Stump.ts +0 -23
- package/source/Classifier/Classifier.ts +0 -72
- package/source/Classifier/DeepNetwork.ts +0 -26
- package/source/Classifier/Dummy.ts +0 -23
- package/source/Classifier/KMeans.ts +0 -30
- package/source/Classifier/Knn.ts +0 -25
- package/source/Classifier/Lda.ts +0 -47
- package/source/Classifier/LinearPerceptron.ts +0 -27
- package/source/Classifier/MultiLayerPerceptron.ts +0 -27
- package/source/Classifier/NaiveBayes.ts +0 -66
- package/source/Classifier/Qda.ts +0 -46
- package/source/Classifier/RandomClassifier.ts +0 -26
- package/source/Model/KMeansModel.ts +0 -56
- package/source/Model/LdaModel.ts +0 -62
- package/source/Model/LinearPerceptronModel.ts +0 -83
- package/source/Model/QdaModel.ts +0 -57
- package/source/tsconfig.json +0 -13
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
constructor1(trainSet: InstanceList, validationSet?: InstanceList, parameters?: LinearPerceptronParameter): void;
|
|
8
|
-
constructor2(fileName: string): void;
|
|
9
|
-
/**
|
|
10
|
-
* Constructor that takes {@link InstanceList}s as trainsSet and validationSet. Initially it allocates layer weights,
|
|
11
|
-
* then creates an input vector by using given trainSet and finds error. Via the validationSet it finds the classification
|
|
12
|
-
* performance and at the end it reassigns the allocated weight Matrix with the matrix that has the best accuracy.
|
|
13
|
-
*
|
|
14
|
-
* @param trainSetOrFileName InstanceList that is used to train.
|
|
15
|
-
* @param validationSet InstanceList that is used to validate.
|
|
16
|
-
* @param parameters Linear perceptron parameters; learningRate, etaDecrease, crossValidationRatio, epoch.
|
|
17
|
-
*/
|
|
18
|
-
constructor(trainSetOrFileName?: InstanceList | string, validationSet?: InstanceList, parameters?: LinearPerceptronParameter);
|
|
19
|
-
/**
|
|
20
|
-
* The calculateOutput method calculates the {@link Matrix} y by multiplying Matrix W with {@link Vector} x.
|
|
21
|
-
*/
|
|
22
|
-
protected calculateOutput(): void;
|
|
23
|
-
saveTxt(fileName: string): void;
|
|
24
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
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", "../InstanceList/InstanceList", "../Performance/ClassificationPerformance", "nlptoolkit-util/dist/Random", "nlptoolkit-util/dist/FileContents"], 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 InstanceList_1 = require("../InstanceList/InstanceList");
|
|
16
|
-
const ClassificationPerformance_1 = require("../Performance/ClassificationPerformance");
|
|
17
|
-
const Random_1 = require("nlptoolkit-util/dist/Random");
|
|
18
|
-
const FileContents_1 = require("nlptoolkit-util/dist/FileContents");
|
|
19
|
-
class LinearPerceptronModel extends NeuralNetworkModel_1.NeuralNetworkModel {
|
|
20
|
-
/**
|
|
21
|
-
* Constructor that takes {@link InstanceList}s as trainsSet and validationSet. Initially it allocates layer weights,
|
|
22
|
-
* then creates an input vector by using given trainSet and finds error. Via the validationSet it finds the classification
|
|
23
|
-
* performance and at the end it reassigns the allocated weight Matrix with the matrix that has the best accuracy.
|
|
24
|
-
*
|
|
25
|
-
* @param trainSetOrFileName InstanceList that is used to train.
|
|
26
|
-
* @param validationSet InstanceList that is used to validate.
|
|
27
|
-
* @param parameters Linear perceptron parameters; learningRate, etaDecrease, crossValidationRatio, epoch.
|
|
28
|
-
*/
|
|
29
|
-
constructor(trainSetOrFileName, validationSet, parameters) {
|
|
30
|
-
if (trainSetOrFileName instanceof InstanceList_1.InstanceList) {
|
|
31
|
-
if (validationSet != undefined) {
|
|
32
|
-
super(trainSetOrFileName);
|
|
33
|
-
this.constructor1(trainSetOrFileName, validationSet, parameters);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
super(trainSetOrFileName);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
if (trainSetOrFileName != undefined) {
|
|
41
|
-
super();
|
|
42
|
-
this.constructor2(trainSetOrFileName);
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
super();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
constructor1(trainSet, validationSet, parameters) {
|
|
50
|
-
if (validationSet != undefined) {
|
|
51
|
-
this.W = this.allocateLayerWeights(this.K, this.d + 1, new Random_1.Random(parameters.getSeed()));
|
|
52
|
-
let bestW = this.W.clone();
|
|
53
|
-
let bestClassificationPerformance = new ClassificationPerformance_1.ClassificationPerformance(0.0);
|
|
54
|
-
let epoch = parameters.getEpoch();
|
|
55
|
-
let learningRate = parameters.getLearningRate();
|
|
56
|
-
for (let i = 0; i < epoch; i++) {
|
|
57
|
-
trainSet.shuffle(new Random_1.Random(parameters.getSeed()));
|
|
58
|
-
for (let j = 0; j < trainSet.size(); j++) {
|
|
59
|
-
this.createInputVector(trainSet.get(j));
|
|
60
|
-
let rMinusY = this.calculateRMinusY(trainSet.get(j), this.x, this.W);
|
|
61
|
-
let deltaW = new Matrix_1.Matrix(rMinusY, this.x);
|
|
62
|
-
deltaW.multiplyWithConstant(learningRate);
|
|
63
|
-
this.W.add(deltaW);
|
|
64
|
-
}
|
|
65
|
-
let currentClassificationPerformance = this.testClassifier(validationSet);
|
|
66
|
-
if (currentClassificationPerformance.getAccuracy() > bestClassificationPerformance.getAccuracy()) {
|
|
67
|
-
bestClassificationPerformance = currentClassificationPerformance;
|
|
68
|
-
bestW = this.W.clone();
|
|
69
|
-
}
|
|
70
|
-
learningRate *= parameters.getEtaDecrease();
|
|
71
|
-
}
|
|
72
|
-
this.W = bestW;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
constructor2(fileName) {
|
|
76
|
-
let input = new FileContents_1.FileContents(fileName);
|
|
77
|
-
this.loadClassLabels(input);
|
|
78
|
-
this.W = this.loadMatrix(input);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* The calculateOutput method calculates the {@link Matrix} y by multiplying Matrix W with {@link Vector} x.
|
|
82
|
-
*/
|
|
83
|
-
calculateOutput() {
|
|
84
|
-
this.y = this.W.multiplyWithVectorFromRight(this.x);
|
|
85
|
-
}
|
|
86
|
-
saveTxt(fileName) {
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports.LinearPerceptronModel = LinearPerceptronModel;
|
|
90
|
-
});
|
|
91
|
-
//# sourceMappingURL=LinearPerceptronModel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LinearPerceptronModel.js","sourceRoot":"","sources":["../../source/Model/LinearPerceptronModel.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,6DAAwD;IACxD,wDAAmD;IACnD,+DAA0D;IAE1D,wFAAmF;IACnF,wDAAmD;IACnD,oEAA+D;IAE/D,MAAa,qBAAsB,SAAQ,uCAAkB;QAqCzD;;;;;;;;WAQG;QACH,YAAY,kBAA0C,EAAE,aAA4B,EAAE,UAAsC;YACxH,IAAI,kBAAkB,YAAY,2BAAY,EAAC;gBAC3C,IAAI,aAAa,IAAI,SAAS,EAAC;oBAC3B,KAAK,CAAC,kBAAkB,CAAC,CAAA;oBACzB,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,aAAa,EAAE,UAAU,CAAC,CAAA;iBACnE;qBAAM;oBACH,KAAK,CAAC,kBAAkB,CAAC,CAAA;iBAC5B;aACJ;iBAAM;gBACH,IAAI,kBAAkB,IAAI,SAAS,EAAC;oBAChC,KAAK,EAAE,CAAA;oBACP,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,CAAA;iBACxC;qBAAM;oBACH,KAAK,EAAE,CAAA;iBACV;aACJ;QACL,CAAC;QA1DD,YAAY,CAAC,QAAsB,EAAE,aAA4B,EAAE,UAAsC;YACrG,IAAI,aAAa,IAAI,SAAS,EAAC;gBAC3B,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,eAAM,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBACzF,IAAI,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;gBAC3B,IAAI,6BAA6B,GAAG,IAAI,qDAAyB,CAAC,G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CAAC,QAAgB;YACzB,IAAI,KAAK,GAAG,IAAI,2BAAY,CAAC,QAAQ,CAAC,CAAA;YACtC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;YAC3B,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;QACnC,CAAC;QA6BD;;WAEG;QACO,eAAe;YACrB,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACxD,CAAC;QAED,OAAO,CAAC,QAAgB;QACxB,CAAC;KAEJ;IA1ED,sDA0EC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
* @param random Random function to set weights.
|
|
13
|
-
*/
|
|
14
|
-
private allocateWeights;
|
|
15
|
-
constructor1(trainSet: InstanceList, validationSet?: InstanceList, parameters?: MultiLayerPerceptronParameter): void;
|
|
16
|
-
constructor2(fileName: string): void;
|
|
17
|
-
/**
|
|
18
|
-
* A constructor that takes {@link InstanceList}s as trainsSet and validationSet. It sets the {@link NeuralNetworkModel}
|
|
19
|
-
* nodes with given {@link InstanceList} then creates an input vector by using given trainSet and finds error.
|
|
20
|
-
* Via the validationSet it finds the classification performance and reassigns the allocated weight Matrix with the matrix
|
|
21
|
-
* that has the best accuracy and the Matrix V with the best Vector input.
|
|
22
|
-
*
|
|
23
|
-
* @param trainSetOrFileName InstanceList that is used to train.
|
|
24
|
-
* @param validationSet InstanceList that is used to validate.
|
|
25
|
-
* @param parameters Multi layer perceptron parameters; seed, learningRate, etaDecrease, crossValidationRatio, epoch, hiddenNodes.
|
|
26
|
-
*/
|
|
27
|
-
constructor(trainSetOrFileName: InstanceList | string, validationSet?: InstanceList, parameters?: MultiLayerPerceptronParameter);
|
|
28
|
-
/**
|
|
29
|
-
* The calculateOutput method calculates the forward single hidden layer by using Matrices W and V.
|
|
30
|
-
*/
|
|
31
|
-
protected calculateOutput(): void;
|
|
32
|
-
saveTxt(fileName: string): void;
|
|
33
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
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", "../InstanceList/InstanceList", "../Performance/ClassificationPerformance", "nlptoolkit-math/dist/Vector", "nlptoolkit-util/dist/Random", "nlptoolkit-util/dist/FileContents"], 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 InstanceList_1 = require("../InstanceList/InstanceList");
|
|
17
|
-
const ClassificationPerformance_1 = require("../Performance/ClassificationPerformance");
|
|
18
|
-
const Vector_1 = require("nlptoolkit-math/dist/Vector");
|
|
19
|
-
const Random_1 = require("nlptoolkit-util/dist/Random");
|
|
20
|
-
const FileContents_1 = require("nlptoolkit-util/dist/FileContents");
|
|
21
|
-
class MultiLayerPerceptronModel extends LinearPerceptronModel_1.LinearPerceptronModel {
|
|
22
|
-
/**
|
|
23
|
-
* A constructor that takes {@link InstanceList}s as trainsSet and validationSet. It sets the {@link NeuralNetworkModel}
|
|
24
|
-
* nodes with given {@link InstanceList} then creates an input vector by using given trainSet and finds error.
|
|
25
|
-
* Via the validationSet it finds the classification performance and reassigns the allocated weight Matrix with the matrix
|
|
26
|
-
* that has the best accuracy and the Matrix V with the best Vector input.
|
|
27
|
-
*
|
|
28
|
-
* @param trainSetOrFileName InstanceList that is used to train.
|
|
29
|
-
* @param validationSet InstanceList that is used to validate.
|
|
30
|
-
* @param parameters Multi layer perceptron parameters; seed, learningRate, etaDecrease, crossValidationRatio, epoch, hiddenNodes.
|
|
31
|
-
*/
|
|
32
|
-
constructor(trainSetOrFileName, validationSet, parameters) {
|
|
33
|
-
if (trainSetOrFileName instanceof InstanceList_1.InstanceList) {
|
|
34
|
-
super(trainSetOrFileName);
|
|
35
|
-
this.constructor1(trainSetOrFileName, validationSet, parameters);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
super();
|
|
39
|
-
this.constructor2(trainSetOrFileName);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* The allocateWeights method allocates layers' weights of Matrix W and V.
|
|
44
|
-
*
|
|
45
|
-
* @param H Integer value for weights.
|
|
46
|
-
* @param random Random function to set weights.
|
|
47
|
-
*/
|
|
48
|
-
allocateWeights(H, random) {
|
|
49
|
-
this.W = this.allocateLayerWeights(H, this.d + 1, random);
|
|
50
|
-
this.V = this.allocateLayerWeights(this.K, H + 1, random);
|
|
51
|
-
}
|
|
52
|
-
constructor1(trainSet, validationSet, parameters) {
|
|
53
|
-
this.activationFunction = parameters.getActivationFunction();
|
|
54
|
-
this.allocateWeights(parameters.getHiddenNodes(), new Random_1.Random(parameters.getSeed()));
|
|
55
|
-
let bestW = this.W.clone();
|
|
56
|
-
let bestV = this.V.clone();
|
|
57
|
-
let bestClassificationPerformance = new ClassificationPerformance_1.ClassificationPerformance(0.0);
|
|
58
|
-
let epoch = parameters.getEpoch();
|
|
59
|
-
let learningRate = parameters.getLearningRate();
|
|
60
|
-
for (let i = 0; i < epoch; i++) {
|
|
61
|
-
trainSet.shuffle(new Random_1.Random(parameters.getSeed()));
|
|
62
|
-
for (let j = 0; j < trainSet.size(); j++) {
|
|
63
|
-
this.createInputVector(trainSet.get(j));
|
|
64
|
-
let hidden = this.calculateHidden(this.x, this.W, this.activationFunction);
|
|
65
|
-
let hiddenBiased = hidden.biased();
|
|
66
|
-
let rMinusY = this.calculateRMinusY(trainSet.get(j), hiddenBiased, this.V);
|
|
67
|
-
let deltaV = new Matrix_1.Matrix(rMinusY, hiddenBiased);
|
|
68
|
-
let tmph = this.V.multiplyWithVectorFromLeft(rMinusY);
|
|
69
|
-
tmph.remove(0);
|
|
70
|
-
let activationDerivative;
|
|
71
|
-
switch (this.activationFunction) {
|
|
72
|
-
case ActivationFunction_1.ActivationFunction.SIGMOID:
|
|
73
|
-
default:
|
|
74
|
-
let oneMinusHidden = this.calculateOneMinusHidden(hidden);
|
|
75
|
-
activationDerivative = oneMinusHidden.elementProduct(hidden);
|
|
76
|
-
break;
|
|
77
|
-
case ActivationFunction_1.ActivationFunction.TANH:
|
|
78
|
-
let one = new Vector_1.Vector(hidden.size(), 1.0);
|
|
79
|
-
hidden.tanh();
|
|
80
|
-
activationDerivative = one.difference(hidden.elementProduct(hidden));
|
|
81
|
-
break;
|
|
82
|
-
case ActivationFunction_1.ActivationFunction.RELU:
|
|
83
|
-
hidden.reluDerivative();
|
|
84
|
-
activationDerivative = hidden;
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
let tmpHidden = tmph.elementProduct(activationDerivative);
|
|
88
|
-
let deltaW = new Matrix_1.Matrix(tmpHidden, this.x);
|
|
89
|
-
deltaV.multiplyWithConstant(learningRate);
|
|
90
|
-
this.V.add(deltaV);
|
|
91
|
-
deltaW.multiplyWithConstant(learningRate);
|
|
92
|
-
this.W.add(deltaW);
|
|
93
|
-
}
|
|
94
|
-
let currentClassificationPerformance = this.testClassifier(validationSet);
|
|
95
|
-
if (currentClassificationPerformance.getAccuracy() > bestClassificationPerformance.getAccuracy()) {
|
|
96
|
-
bestClassificationPerformance = currentClassificationPerformance;
|
|
97
|
-
bestW = this.W.clone();
|
|
98
|
-
bestV = this.V.clone();
|
|
99
|
-
}
|
|
100
|
-
learningRate *= parameters.getEtaDecrease();
|
|
101
|
-
}
|
|
102
|
-
this.W = bestW;
|
|
103
|
-
this.V = bestV;
|
|
104
|
-
}
|
|
105
|
-
constructor2(fileName) {
|
|
106
|
-
let input = new FileContents_1.FileContents(fileName);
|
|
107
|
-
this.loadClassLabels(input);
|
|
108
|
-
this.W = this.loadMatrix(input);
|
|
109
|
-
this.V = this.loadMatrix(input);
|
|
110
|
-
this.activationFunction = this.loadActivationFunction(input);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* The calculateOutput method calculates the forward single hidden layer by using Matrices W and V.
|
|
114
|
-
*/
|
|
115
|
-
calculateOutput() {
|
|
116
|
-
this.calculateForwardSingleHiddenLayer(this.W, this.V, this.activationFunction);
|
|
117
|
-
}
|
|
118
|
-
saveTxt(fileName) {
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
exports.MultiLayerPerceptronModel = MultiLayerPerceptronModel;
|
|
122
|
-
});
|
|
123
|
-
//# sourceMappingURL=MultiLayerPerceptronModel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MultiLayerPerceptronModel.js","sourceRoot":"","sources":["../../source/Model/MultiLayerPerceptronModel.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,mEAA8D;IAC9D,wDAAmD;IACnD,wEAAmE;IACnE,+DAA0D;IAE1D,wFAAmF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C,QAAgB;YACzB,IAAI,KAAK,GAAG,IAAI,2BAAY,CAAC,QAAQ,CAAC,CAAA;YACtC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAA;YAC3B,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;YAC/B,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAA;YAC/B,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAA;QAChE,CAAC;QAsBD;;WAEG;QACO,eAAe;YACrB,IAAI,CAAC,iCAAiC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACpF,CAAC;QAED,OAAO,CAAC,QAAgB;QACxB,CAAC;KAEJ;IA5GD,8DA4GC"}
|
|
@@ -1,107 +0,0 @@
|
|
|
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", "nlptoolkit-math/dist/DiscreteDistribution", "nlptoolkit-util/dist/FileContents"], 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
|
-
const DiscreteDistribution_1 = require("nlptoolkit-math/dist/DiscreteDistribution");
|
|
15
|
-
const FileContents_1 = require("nlptoolkit-util/dist/FileContents");
|
|
16
|
-
class NaiveBayesModel extends GaussianModel_1.GaussianModel {
|
|
17
|
-
/**
|
|
18
|
-
* A constructor that sets the priorDistribution, classMeans and classDeviations.
|
|
19
|
-
*
|
|
20
|
-
* @param priorDistribution {@link DiscreteDistribution} input.
|
|
21
|
-
* @param classMeans A {@link Map} of String and {@link Vector}.
|
|
22
|
-
* @param classDeviations A {@link Map} of String and {@link Vector}.
|
|
23
|
-
*/
|
|
24
|
-
constructor(priorDistribution, classMeans, classDeviations) {
|
|
25
|
-
super();
|
|
26
|
-
this.classMeans = undefined;
|
|
27
|
-
this.classDeviations = undefined;
|
|
28
|
-
this.classAttributeDistributions = undefined;
|
|
29
|
-
if (priorDistribution instanceof DiscreteDistribution_1.DiscreteDistribution) {
|
|
30
|
-
this.priorDistribution = priorDistribution;
|
|
31
|
-
if (classDeviations != undefined) {
|
|
32
|
-
this.classMeans = classMeans;
|
|
33
|
-
this.classDeviations = classDeviations;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
this.classAttributeDistributions = classMeans;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
let input = new FileContents_1.FileContents(priorDistribution);
|
|
41
|
-
let size = this.loadPriorDistribution(input);
|
|
42
|
-
this.classMeans = this.loadVectors(input, size);
|
|
43
|
-
this.classDeviations = this.loadVectors(input, size);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* The calculateMetric method takes an {@link Instance} and a String as inputs, and it returns the log likelihood of
|
|
48
|
-
* these inputs.
|
|
49
|
-
*
|
|
50
|
-
* @param instance {@link Instance} input.
|
|
51
|
-
* @param Ci String input.
|
|
52
|
-
* @return The log likelihood of inputs.
|
|
53
|
-
*/
|
|
54
|
-
calculateMetric(instance, Ci) {
|
|
55
|
-
if (this.classAttributeDistributions == undefined) {
|
|
56
|
-
return this.logLikelihoodContinuous(Ci, instance);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
return this.logLikelihoodDiscrete(Ci, instance);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* The logLikelihoodContinuous method takes an {@link Instance} and a class label as inputs. First it gets the logarithm
|
|
64
|
-
* of given class label's probability via prior distribution as logLikelihood. Then it loops times of given instance attribute size, and accumulates the
|
|
65
|
-
* logLikelihood by calculating -0.5 * ((xi - mi) / si )** 2).
|
|
66
|
-
*
|
|
67
|
-
* @param classLabel String input class label.
|
|
68
|
-
* @param instance {@link Instance} input.
|
|
69
|
-
* @return The log likelihood of given class label and {@link Instance}.
|
|
70
|
-
*/
|
|
71
|
-
logLikelihoodContinuous(classLabel, instance) {
|
|
72
|
-
let logLikelihood = Math.log(this.priorDistribution.getProbability(classLabel));
|
|
73
|
-
for (let i = 0; i < instance.attributeSize(); i++) {
|
|
74
|
-
let xi = instance.getAttribute(i).getValue();
|
|
75
|
-
let mi = this.classMeans.get(classLabel).getValue(i);
|
|
76
|
-
let si = this.classDeviations.get(classLabel).getValue(i);
|
|
77
|
-
if (si != 0) {
|
|
78
|
-
logLikelihood += -0.5 * Math.pow((xi - mi) / si, 2);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return logLikelihood;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* The logLikelihoodDiscrete method takes an {@link Instance} and a class label as inputs. First it gets the logarithm
|
|
85
|
-
* of given class label's probability via prior distribution as logLikelihood and gets the class attribute distribution of given class label.
|
|
86
|
-
* Then it loops times of given instance attribute size, and accumulates the logLikelihood by calculating the logarithm of
|
|
87
|
-
* corresponding attribute distribution's smoothed probability by using laplace smoothing on xi.
|
|
88
|
-
*
|
|
89
|
-
* @param classLabel String input class label.
|
|
90
|
-
* @param instance {@link Instance} input.
|
|
91
|
-
* @return The log likelihood of given class label and {@link Instance}.
|
|
92
|
-
*/
|
|
93
|
-
logLikelihoodDiscrete(classLabel, instance) {
|
|
94
|
-
let logLikelihood = Math.log(this.priorDistribution.getProbability(classLabel));
|
|
95
|
-
let attributeDistributions = this.classAttributeDistributions.get(classLabel);
|
|
96
|
-
for (let i = 0; i < instance.attributeSize(); i++) {
|
|
97
|
-
let xi = instance.getAttribute(i).getValue();
|
|
98
|
-
logLikelihood += Math.log(attributeDistributions[i].getProbabilityLaplaceSmoothing(xi));
|
|
99
|
-
}
|
|
100
|
-
return logLikelihood;
|
|
101
|
-
}
|
|
102
|
-
saveTxt(fileName) {
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
exports.NaiveBayesModel = NaiveBayesModel;
|
|
106
|
-
});
|
|
107
|
-
//# sourceMappingURL=NaiveBayesModel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NaiveBayesModel.js","sourceRoot":"","sources":["../../source/Model/NaiveBayesModel.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,mDAA8C;IAG9C,oFAA+E;IAG/E,oEAA+D;IAE/D,MAAa,eAAgB,SAAQ,6BAAa;QAM9C;;;;;;WAMG;QACH,YAAY,iBAAgD,EAAE,UAAgB,EAAE,eAAqC;YACjH,KAAK,EAAE,CAAA;YAZH,eAAU,GAAwB,SAAS,CAAA;YAC3C,oBAAe,GAAwB,SAAS,CAAA;YACvC,gCAA2B,GAA6C,SAAS,CAAA;YAW9F,IAAI,iBAAiB,YAAY,2CAAoB,EAAC;gBAClD,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;gBAC1C,IAAI,eAAe,IAAI,SAAS,EAAC;oBAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;oBAC5B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAA;iBACzC;qBAAM;oBACH,IAAI,CAAC,2BAA2B,GAAG,UAAU,CAAA;iBAChD;aACJ;iBAAM;gBACH,IAAI,KAAK,GAAG,IAAI,2BAAY,CAAC,iBAAiB,CAAC,CAAA;gBAC/C,IAAI,IAAI,GAAG,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAA;gBAC5C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;gBAC/C,I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E,IAAI,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;YAChF,IAAI,sBAAsB,GAAG,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC9E,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,aAAa,EAAE,EAAE,CAAC,EAAE,EAAE;gBAC/C,IAAI,EAAE,GAAwB,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAE,CAAC,QAAQ,EAAE,CAAC;gBACnE,aAAa,IAAI,IAAI,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,8BAA8B,CAAC,EAAE,CAAC,CAAC,CAAC;aAC3F;YACD,OAAO,aAAa,CAAC;QACzB,CAAC;QAED,OAAO,CAAC,QAAgB;QACxB,CAAC;KAEJ;IA5FD,0CA4FC"}
|
|
@@ -1,202 +0,0 @@
|
|
|
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", "nlptoolkit-math/dist/Vector", "nlptoolkit-math/dist/Matrix", "../Parameter/ActivationFunction", "../Instance/CompositeInstance"], factory);
|
|
8
|
-
}
|
|
9
|
-
})(function (require, exports) {
|
|
10
|
-
"use strict";
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.NeuralNetworkModel = void 0;
|
|
13
|
-
const ValidatedModel_1 = require("./ValidatedModel");
|
|
14
|
-
const Vector_1 = require("nlptoolkit-math/dist/Vector");
|
|
15
|
-
const Matrix_1 = require("nlptoolkit-math/dist/Matrix");
|
|
16
|
-
const ActivationFunction_1 = require("../Parameter/ActivationFunction");
|
|
17
|
-
const CompositeInstance_1 = require("../Instance/CompositeInstance");
|
|
18
|
-
class NeuralNetworkModel extends ValidatedModel_1.ValidatedModel {
|
|
19
|
-
/**
|
|
20
|
-
* Constructor that sets the class labels, their sizes as K and the size of the continuous attributes as d.
|
|
21
|
-
*
|
|
22
|
-
* @param trainSet {@link InstanceList} to use as train set.
|
|
23
|
-
*/
|
|
24
|
-
constructor(trainSet) {
|
|
25
|
-
super();
|
|
26
|
-
if (trainSet != undefined) {
|
|
27
|
-
this.classLabels = trainSet.getDistinctClassLabels();
|
|
28
|
-
this.K = this.classLabels.length;
|
|
29
|
-
this.d = trainSet.get(0).continuousAttributeSize();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* The allocateLayerWeights method returns a new {@link Matrix} with random weights.
|
|
34
|
-
*
|
|
35
|
-
* @param row Number of rows.
|
|
36
|
-
* @param column Number of columns.
|
|
37
|
-
* @param random Random function to set weights.
|
|
38
|
-
* @return Matrix with random weights.
|
|
39
|
-
*/
|
|
40
|
-
allocateLayerWeights(row, column, random) {
|
|
41
|
-
return new Matrix_1.Matrix(row, column, -0.01, +0.01, random);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* The normalizeOutput method takes an input {@link Vector} o, gets the result for e^o of each element of o,
|
|
45
|
-
* then sums them up. At the end, divides each e^o by the summation.
|
|
46
|
-
*
|
|
47
|
-
* @param o Vector to normalize.
|
|
48
|
-
* @return Normalized vector.
|
|
49
|
-
*/
|
|
50
|
-
normalizeOutput(o) {
|
|
51
|
-
let sum = 0.0;
|
|
52
|
-
let values = new Array();
|
|
53
|
-
for (let i = 0; i < o.size(); i++) {
|
|
54
|
-
sum += Math.exp(o.getValue(i));
|
|
55
|
-
}
|
|
56
|
-
for (let i = 0; i < o.size(); i++) {
|
|
57
|
-
values.push(Math.exp(o.getValue(i)) / sum);
|
|
58
|
-
}
|
|
59
|
-
return new Vector_1.Vector(values);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* The createInputVector method takes an {@link Instance} as an input. It converts given Instance to the {@link Vector}
|
|
63
|
-
* and insert 1.0 to the first element.
|
|
64
|
-
*
|
|
65
|
-
* @param instance Instance to insert 1.0.
|
|
66
|
-
*/
|
|
67
|
-
createInputVector(instance) {
|
|
68
|
-
this.x = instance.toVector();
|
|
69
|
-
this.x.insert(0, 1.0);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* The calculateHidden method takes a {@link Vector} input and {@link Matrix} weights, It multiplies the weights
|
|
73
|
-
* Matrix with given input Vector than applies the sigmoid function and returns the result.
|
|
74
|
-
*
|
|
75
|
-
* @param input Vector to multiply weights.
|
|
76
|
-
* @param weights Matrix is multiplied with input Vector.
|
|
77
|
-
* @param activationFunction Activation function.
|
|
78
|
-
* @return Result of sigmoid function.
|
|
79
|
-
*/
|
|
80
|
-
calculateHidden(input, weights, activationFunction) {
|
|
81
|
-
let z = weights.multiplyWithVectorFromRight(input);
|
|
82
|
-
switch (activationFunction) {
|
|
83
|
-
case ActivationFunction_1.ActivationFunction.SIGMOID:
|
|
84
|
-
default:
|
|
85
|
-
z.sigmoid();
|
|
86
|
-
break;
|
|
87
|
-
case ActivationFunction_1.ActivationFunction.TANH:
|
|
88
|
-
z.tanh();
|
|
89
|
-
break;
|
|
90
|
-
case ActivationFunction_1.ActivationFunction.RELU:
|
|
91
|
-
z.relu();
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
return z;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* The calculateOneMinusHidden method takes a {@link Vector} as input. It creates a Vector of ones and
|
|
98
|
-
* returns the difference between given Vector.
|
|
99
|
-
*
|
|
100
|
-
* @param hidden Vector to find difference.
|
|
101
|
-
* @return Returns the difference between one's Vector and input Vector.
|
|
102
|
-
*/
|
|
103
|
-
calculateOneMinusHidden(hidden) {
|
|
104
|
-
let one = new Vector_1.Vector(hidden.size(), 1.0);
|
|
105
|
-
return one.difference(hidden);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* The calculateForwardSingleHiddenLayer method takes two matrices W and V. First it multiplies W with x, then
|
|
109
|
-
* multiplies V with the result of the previous multiplication.
|
|
110
|
-
*
|
|
111
|
-
* @param W Matrix to multiply with x.
|
|
112
|
-
* @param V Matrix to multiply.
|
|
113
|
-
* @param activationFunction Activation function.
|
|
114
|
-
*/
|
|
115
|
-
calculateForwardSingleHiddenLayer(W, V, activationFunction) {
|
|
116
|
-
let hidden = this.calculateHidden(this.x, W, activationFunction);
|
|
117
|
-
let hiddenBiased = hidden.biased();
|
|
118
|
-
this.y = V.multiplyWithVectorFromRight(hiddenBiased);
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* The calculateRMinusY method creates a new {@link Vector} with given Instance, then it multiplies given
|
|
122
|
-
* input Vector with given weights Matrix. After normalizing the output, it returns the difference between the newly created
|
|
123
|
-
* Vector and normalized output.
|
|
124
|
-
*
|
|
125
|
-
* @param instance Instance is used to get class labels.
|
|
126
|
-
* @param input Vector to multiply weights.
|
|
127
|
-
* @param weights Matrix of weights/
|
|
128
|
-
* @return Difference between newly created Vector and normalized output.
|
|
129
|
-
*/
|
|
130
|
-
calculateRMinusY(instance, input, weights) {
|
|
131
|
-
this.r = new Vector_1.Vector(this.K, 1.0, this.classLabels.indexOf(instance.getClassLabel()));
|
|
132
|
-
let o = weights.multiplyWithVectorFromRight(input);
|
|
133
|
-
this.y = this.normalizeOutput(o);
|
|
134
|
-
return this.r.difference(this.y);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* The predictWithCompositeInstance method takes an ArrayList possibleClassLabels. It returns the class label
|
|
138
|
-
* which has the maximum value of y.
|
|
139
|
-
*
|
|
140
|
-
* @param possibleClassLabels ArrayList that has the class labels.
|
|
141
|
-
* @return The class label which has the maximum value of y.
|
|
142
|
-
*/
|
|
143
|
-
predictWithCompositeInstance(possibleClassLabels) {
|
|
144
|
-
let predictedClass = possibleClassLabels[0];
|
|
145
|
-
let maxY = Number.NEGATIVE_INFINITY;
|
|
146
|
-
for (let i = 0; i < this.classLabels.length; i++) {
|
|
147
|
-
if (possibleClassLabels.includes(this.classLabels[i]) && this.y.getValue(i) > maxY) {
|
|
148
|
-
maxY = this.y.getValue(i);
|
|
149
|
-
predictedClass = this.classLabels[i];
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return predictedClass;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* The predict method takes an {@link Instance} as an input, converts it to a Vector and calculates the {@link Matrix} y by
|
|
156
|
-
* multiplying Matrix W with {@link Vector} x. Then it returns the class label which has the maximum y value.
|
|
157
|
-
*
|
|
158
|
-
* @param instance Instance to predict.
|
|
159
|
-
* @return The class label which has the maximum y.
|
|
160
|
-
*/
|
|
161
|
-
predict(instance) {
|
|
162
|
-
this.createInputVector(instance);
|
|
163
|
-
this.calculateOutput();
|
|
164
|
-
if (instance instanceof CompositeInstance_1.CompositeInstance) {
|
|
165
|
-
return this.predictWithCompositeInstance(instance.getPossibleClassLabels());
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
return this.classLabels[this.y.maxIndex()];
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
predictProbability(instance) {
|
|
172
|
-
this.createInputVector(instance);
|
|
173
|
-
this.calculateOutput();
|
|
174
|
-
let result = new Map();
|
|
175
|
-
for (let i = 0; i < this.classLabels.length; i++) {
|
|
176
|
-
result.set(this.classLabels[i], this.y.getValue(i));
|
|
177
|
-
}
|
|
178
|
-
return result;
|
|
179
|
-
}
|
|
180
|
-
loadClassLabels(input) {
|
|
181
|
-
let items = input.readLine().split(" ");
|
|
182
|
-
this.K = parseInt(items[0]);
|
|
183
|
-
this.d = parseInt(items[1]);
|
|
184
|
-
this.classLabels = new Array();
|
|
185
|
-
for (let i = 0; i < this.K; i++) {
|
|
186
|
-
this.classLabels.push(input.readLine());
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
loadActivationFunction(input) {
|
|
190
|
-
switch (input.readLine()) {
|
|
191
|
-
case "TANH":
|
|
192
|
-
return ActivationFunction_1.ActivationFunction.TANH;
|
|
193
|
-
case "RELU":
|
|
194
|
-
return ActivationFunction_1.ActivationFunction.RELU;
|
|
195
|
-
default:
|
|
196
|
-
return ActivationFunction_1.ActivationFunction.SIGMOID;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
exports.NeuralNetworkModel = NeuralNetworkModel;
|
|
201
|
-
});
|
|
202
|
-
//# sourceMappingURL=NeuralNetworkModel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NeuralNetworkModel.js","sourceRoot":"","sources":["../../source/Model/NeuralNetworkModel.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,qDAAgD;IAChD,wDAAmD;IAEnD,wDAAmD;IAEnD,wEAAmE;IACnE,qEAAgE;IAIhE,MAAsB,kBAAmB,SAAQ,+BAAc;QAW3D;;;;WAIG;QACH,YAAsB,QAAuB;YACzC,KAAK,EAAE,CAAC;YACR,IAAI,QAAQ,IAAI,SAAS,EAAC;gBACtB,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC,sBAAsB,EAAE,CAAA;gBACpD,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAA;gBAChC,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,uBAAuB,EAAE,CAAA;aACrD;QACL,CAAC;QAED;;;;;;;WAOG;QACO,oBAAoB,CAAC,GAAW,EAAE,MAAc,EAAE,MAAc;YACtE,OAAO,IAAI,eAAM,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACzD,CAAC;QAED;;;;;;WAMG;QACO,eAAe,CAAC,CAAS;YAC/B,IAAI,GAAG,GAAG,GAAG,CAAC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CAAC,CAAA;YACvC,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;YAC3B,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;YAC3B,IAAI,CAAC,WAAW,GAAG,IAAI,KAAK,EAAU,CAAA;YACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EAAC;gBAC5B,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;aAC1C;QACL,CAAC;QAED,sBAAsB,CAAC,KAAmB;YACtC,QAAQ,KAAK,CAAC,QAAQ,EAAE,EAAC;gBACrB,KAAK,MAAM;oBACP,OAAO,uCAAkB,CAAC,IAAI,CAAA;gBAClC,KAAK,MAAM;oBACP,OAAO,uCAAkB,CAAC,IAAI,CAAA;gBAClC;oBACI,OAAO,uCAAkB,CAAC,OAAO,CAAA;aACxC;QACL,CAAC;KACJ;IA1MD,gDA0MC"}
|
package/dist/Model/QdaModel.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { LdaModel } from "./LdaModel";
|
|
2
|
-
import { Matrix } from "nlptoolkit-math/dist/Matrix";
|
|
3
|
-
import { DiscreteDistribution } from "nlptoolkit-math/dist/DiscreteDistribution";
|
|
4
|
-
import { Vector } from "nlptoolkit-math/dist/Vector";
|
|
5
|
-
import { Instance } from "../Instance/Instance";
|
|
6
|
-
export declare class QdaModel extends LdaModel {
|
|
7
|
-
private W;
|
|
8
|
-
/**
|
|
9
|
-
* The constructor which sets the priorDistribution, w w1 and HashMap of String Matrix.
|
|
10
|
-
*
|
|
11
|
-
* @param priorDistributionOrFileName {@link DiscreteDistribution} input.
|
|
12
|
-
* @param W {@link HashMap} of String and Matrix.
|
|
13
|
-
* @param w {@link HashMap} of String and Vectors.
|
|
14
|
-
* @param w0 {@link HashMap} of String and Double.
|
|
15
|
-
*/
|
|
16
|
-
constructor(priorDistributionOrFileName: DiscreteDistribution | string, W?: Map<string, Matrix>, w?: Map<string, Vector>, w0?: Map<string, number>);
|
|
17
|
-
/**
|
|
18
|
-
* The calculateMetric method takes an {@link Instance} and a String as inputs. It multiplies Matrix Wi with Vector xi
|
|
19
|
-
* then calculates the dot product of it with xi. Then, again it finds the dot product of wi and xi and returns the summation with w0i.
|
|
20
|
-
*
|
|
21
|
-
* @param instance {@link Instance} input.
|
|
22
|
-
* @param Ci String input.
|
|
23
|
-
* @return The result of Wi.multiplyWithVectorFromLeft(xi).dotProduct(xi) + wi.dotProduct(xi) + w0i.
|
|
24
|
-
*/
|
|
25
|
-
calculateMetric(instance: Instance, Ci: string): number;
|
|
26
|
-
saveTxt(fileName: string): void;
|
|
27
|
-
}
|