noshot 0.1.0__py3-none-any.whl
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.
- noshot/__init__.py +1 -0
- noshot/data/AIDS CN NLP/AIDS/1. Implement Basic Search Strategies/(A) Breadth First Search.ipynb +112 -0
- noshot/data/AIDS CN NLP/AIDS/1. Implement Basic Search Strategies/(B) Depth First Search.ipynb +111 -0
- noshot/data/AIDS CN NLP/AIDS/1. Implement Basic Search Strategies/(C) Uniform Cost Search.ipynb +134 -0
- noshot/data/AIDS CN NLP/AIDS/1. Implement Basic Search Strategies/(D) Depth Limites Search.ipynb +115 -0
- noshot/data/AIDS CN NLP/AIDS/1. Implement Basic Search Strategies/(E) Iterative Deepening DFS.ipynb +123 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/2_ANOVA.csv +769 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/One Way ANOVA (Repeated Measure).ipynb +126 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/One Way ANOVA.ipynb +134 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/Sample 1 Way ANOVA Test.ipynb +119 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/Two Way ANOVA.ipynb +138 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/reaction_time.csv +5 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/sample_data.csv +16 -0
- noshot/data/AIDS CN NLP/AIDS/10. ANOVA/sleep_deprivation.csv +4 -0
- noshot/data/AIDS CN NLP/AIDS/11. Linear Regression/3_Linear.csv +4802 -0
- noshot/data/AIDS CN NLP/AIDS/11. Linear Regression/Linear Regression LAB.ipynb +113 -0
- noshot/data/AIDS CN NLP/AIDS/11. Linear Regression/Linear Regression New- sklearn.ipynb +118 -0
- noshot/data/AIDS CN NLP/AIDS/11. Linear Regression/Linear Regression.ipynb +148 -0
- noshot/data/AIDS CN NLP/AIDS/11. Linear Regression/house_rate.csv +22 -0
- noshot/data/AIDS CN NLP/AIDS/12. Logistic Regression/Logistic Regression New- sklearn.ipynb +128 -0
- noshot/data/AIDS CN NLP/AIDS/12. Logistic Regression/Logistic Regression.ipynb +145 -0
- noshot/data/AIDS CN NLP/AIDS/12. Logistic Regression/default.csv +1001 -0
- noshot/data/AIDS CN NLP/AIDS/12. Logistic Regression/hours_scores_records.csv +101 -0
- noshot/data/AIDS CN NLP/AIDS/2. Implement A Star And MA Star/(A) Astar.ipynb +256 -0
- noshot/data/AIDS CN NLP/AIDS/2. Implement A Star And MA Star/(B) IDAstar.ipynb +157 -0
- noshot/data/AIDS CN NLP/AIDS/2. Implement A Star And MA Star/(C) SMAstar.ipynb +178 -0
- noshot/data/AIDS CN NLP/AIDS/3. Genetic Algorithm/Genetic.ipynb +95 -0
- noshot/data/AIDS CN NLP/AIDS/4. Simulated Annealing/Simulated Annealing.ipynb +74 -0
- noshot/data/AIDS CN NLP/AIDS/4. Simulated Annealing/Sudoku Simulated Annealing.ipynb +103 -0
- noshot/data/AIDS CN NLP/AIDS/5. Alpha Beta Pruning/AlphaBetaPruning.ipynb +182 -0
- noshot/data/AIDS CN NLP/AIDS/6. Consraint Satisfaction Problems (CSP)/(A) CSP House Allocation.ipynb +120 -0
- noshot/data/AIDS CN NLP/AIDS/6. Consraint Satisfaction Problems (CSP)/(B) CSP Map Coloring.ipynb +125 -0
- noshot/data/AIDS CN NLP/AIDS/7. Random Sampling/Random Sampling.ipynb +73 -0
- noshot/data/AIDS CN NLP/AIDS/7. Random Sampling/height_weight_bmi.csv +8389 -0
- noshot/data/AIDS CN NLP/AIDS/8. Z Test/Z Test Hash Function.ipynb +141 -0
- noshot/data/AIDS CN NLP/AIDS/8. Z Test/Z Test.ipynb +151 -0
- noshot/data/AIDS CN NLP/AIDS/8. Z Test/height_weight_bmi.csv +8389 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/1_heart.csv +304 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/Independent T Test.ipynb +119 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/Paired T Test.ipynb +118 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/T Test Hash Function.ipynb +142 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/T Test.ipynb +158 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/height_weight_bmi.csv +8389 -0
- noshot/data/AIDS CN NLP/AIDS/9. T Test/iq_test.csv +0 -0
- noshot/data/AIDS CN NLP/AIDS/Others (AllinOne)/All In One.ipynb +4581 -0
- noshot/data/AIDS CN NLP/CN/1. Chat Application/chat.java +81 -0
- noshot/data/AIDS CN NLP/CN/1. Chat Application/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/1. Chat Application/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/10. Ethernet LAN IEEE 802.3/LAN.tcl +65 -0
- noshot/data/AIDS CN NLP/CN/10. Ethernet LAN IEEE 802.3/analysis.awk +44 -0
- noshot/data/AIDS CN NLP/CN/10. Ethernet LAN IEEE 802.3/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/10. Ethernet LAN IEEE 802.3/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/11. Wireless LAN IEEE 802.11/complexdcf.tcl +229 -0
- noshot/data/AIDS CN NLP/CN/11. Wireless LAN IEEE 802.11/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/11. Wireless LAN IEEE 802.11/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/2. File Transfer/file_to_send.txt +2 -0
- noshot/data/AIDS CN NLP/CN/2. File Transfer/filetransfer.java +119 -0
- noshot/data/AIDS CN NLP/CN/2. File Transfer/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/2. File Transfer/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/3. RMI (Remote Method Invocation)/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/3. RMI (Remote Method Invocation)/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/3. RMI (Remote Method Invocation)/rmi.java +56 -0
- noshot/data/AIDS CN NLP/CN/4. Wired Network/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/4. Wired Network/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/4. Wired Network/wired.awk +25 -0
- noshot/data/AIDS CN NLP/CN/4. Wired Network/wired.tcl +81 -0
- noshot/data/AIDS CN NLP/CN/5. Wireless Network/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/5. Wireless Network/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/5. Wireless Network/wireless.awk +27 -0
- noshot/data/AIDS CN NLP/CN/5. Wireless Network/wireless.tcl +153 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Sack And Vegas/analysis.awk +27 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Sack And Vegas/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Sack And Vegas/sack.tcl +86 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Sack And Vegas/vegas.tcl +86 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Tahoe And Reno/analysis.awk +28 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Tahoe And Reno/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Tahoe And Reno/reno.tcl +78 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Congestion Control/Tahoe And Reno/tahoe.tcl +79 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Flow Control/analysis.awk +27 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Flow Control/flow.tcl +163 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/TCP Flow Control/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/6. TCP Flow And Congestion Control/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/7. Link State And Distance Vector Routing/DV.tcl +111 -0
- noshot/data/AIDS CN NLP/CN/7. Link State And Distance Vector Routing/LS.tcl +106 -0
- noshot/data/AIDS CN NLP/CN/7. Link State And Distance Vector Routing/analysis.awk +36 -0
- noshot/data/AIDS CN NLP/CN/7. Link State And Distance Vector Routing/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/7. Link State And Distance Vector Routing/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/8. Multicast And Broadcast Routing/analysis.awk +20 -0
- noshot/data/AIDS CN NLP/CN/8. Multicast And Broadcast Routing/broadcast.tcl +76 -0
- noshot/data/AIDS CN NLP/CN/8. Multicast And Broadcast Routing/multicast.tcl +103 -0
- noshot/data/AIDS CN NLP/CN/8. Multicast And Broadcast Routing/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/8. Multicast And Broadcast Routing/procedure.png +0 -0
- noshot/data/AIDS CN NLP/CN/9. DHCP/DHCP.java +125 -0
- noshot/data/AIDS CN NLP/CN/9. DHCP/output.png +0 -0
- noshot/data/AIDS CN NLP/CN/9. DHCP/procedure.png +0 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/1-Prereqs.py +18 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/2-Chi2test.py +83 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/2-T-test.py +79 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/3-WSD-nb.py +53 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/4-Hindle-Rooth.py +53 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/5-HMM-Trellis.py +82 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/6-HMM-Viterbi.py +16 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/7-PCFG-parsetree.py +15 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Chi2test.ipynb +285 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Hindle-Rooth.ipynb +179 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Lab 10 - Text generator using LSTM.ipynb +1461 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Lab 11 NMT.ipynb +2307 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/PCFG.ipynb +134 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Prereqs.ipynb +131 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/T test.ipynb +252 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/TFIDF BOW.ipynb +171 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Trellis.ipynb +244 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/WSD.ipynb +645 -0
- noshot/data/AIDS CN NLP/NLP/NLP 1/Word2Vec.ipynb +93 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab01(tokenizer)/tokenizer.ipynb +370 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab01(tokenizer)/training_tokenizer.txt +6 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab02(stemming)/exp0.ipynb +274 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab02(stemming)/lab2.ipynb +905 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab02(stemming)/test.txt +1 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab02(stemming)/tokenizing.ipynb +272 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab03(parse-tree)/collocation.ipynb +332 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab03(parse-tree)/lab3.ipynb +549 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab03(parse-tree)/nlp.txt +1 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab04(collocation)/Lab4-NLP-Exp-2.ipynb +817 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab04(collocation)/collocation.ipynb +332 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab05(WSD)/NLP-Lab-5-Exp3.ipynb +231 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab05(WSD)/word-sense-disambiguation.ipynb +507 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab06(additional-exercise)/lab6.ipynb +134 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab07(HMM,Viterbi)/NLP Exp 4.ipynb +255 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab07(HMM,Viterbi)/NLP_Exp_5.ipynb +159 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab08(PCFG)/PCFG.ipynb +282 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab09-Hindle-rooth&MLP/Lab 9 - MLP classifier.ipynb +670 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab09-Hindle-rooth&MLP/MLP-alternative-code.ipynb +613 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab09-Hindle-rooth&MLP/hindle-rooth-algorithm.ipynb +74 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab10(LSTM)/Lab_10_Text_generator_using_LSTM.ipynb +480 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/Machine-translation.ipynb +445 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/Viterbi-PCFG.ipynb +105 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/corpora_tools.py +87 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/data_utils.py +11 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab11(Viterbi-PCFG,Machine-translation)/train_translator.py +83 -0
- noshot/data/AIDS CN NLP/NLP/NLP 2/Lab12(Information-Extraction)/Information_Extraction.ipynb +201 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/Backtrack-without-Verbitri.ipynb +185 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/Backward-Procedure.ipynb +597 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/Bag_of.ipynb +1422 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/CYK-algorithm.ipynb +1067 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/Forward-Procedure.ipynb +477 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/LSTM.ipynb +1290 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/Lab 10 - Text generator using LSTM.ipynb +1461 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/Lab 11 NMT.ipynb +2307 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/NLP-LAB-4.ipynb +216 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/NLP-LAB-5.ipynb +216 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/abc.txt +6 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/ex-1-nltk.ipynb +711 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/ex-2-nlp.ipynb +267 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/exp8&9.ipynb +305 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/hind.ipynb +287 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/lab66.ipynb +752 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/leb_3.ipynb +612 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/naive_bayes_classifier.pkl +0 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/nlp_leb_1.ipynb +3008 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/nlp_leb_2.ipynb +3095 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/nlplab-9.ipynb +295 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/nltk-ex-4.ipynb +506 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/text1.txt +48 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/text2.txt +8 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/text3.txt +48 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/translation-rnn.ipynb +812 -0
- noshot/data/AIDS CN NLP/NLP/NLP 3/word2vector.ipynb +173 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Backward Procedure Algorithm.ipynb +179 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Chi Square Collocation.ipynb +208 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Collocation (T test).ipynb +188 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Experiment 1.ipynb +437 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Forward Procedure Algorithm.ipynb +132 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Hindle Rooth.ipynb +414 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/MachineTranslation.ipynb +368 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Multi Layer Perceptron using MLPClassifier.ipynb +86 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Multi Layer Perceptron using Tensorflow.ipynb +112 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/PCFG Inside Probability.ipynb +451 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Text Generation using LSTM.ipynb +297 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Viterbi.ipynb +310 -0
- noshot/data/AIDS CN NLP/NLP/NLP 4/Word Sense Disambiguation.ipynb +335 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/10.Text Generation using LSTM.ipynb +316 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/11.Machine Translation.ipynb +868 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/2.T and Chi2 Test.ipynb +204 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/3.Word Sense Diambiguation.ipynb +234 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/4.Hinddle and Rooth.ipynb +128 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/5.Forward and Backward.ipynb +149 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/6.Viterbi.ipynb +111 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/7.PCFG Parse Tree.ipynb +134 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/7.PCFG using cyk.ipynb +101 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/8.Bag of words and TF-IDF.ipynb +310 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/9.Word2Vector.ipynb +78 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/NLP ALL In One.ipynb +2619 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/sample1.txt +15 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/sample2.txt +4 -0
- noshot/data/AIDS CN NLP/NLP/NLP 5/word2vec_model.bin +0 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/1. Tokenize, Tagging, NER, Parse Tree.ipynb +312 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/2. T Test and Chi2 Test.ipynb +185 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/3. Naive Bayes WSD.ipynb +199 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/4. Hinddle and Rooth.ipynb +151 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/5 and 6 FWD, BWD, Viterbi.ipynb +164 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/7. PCFG using CYK.ipynb +383 -0
- noshot/data/AIDS CN NLP/NLP/NLP 6/8. BOW and TF-IDF.ipynb +252 -0
- noshot/data/AIDS CN NLP/Ubuntu CN Lab.iso +0 -0
- noshot/main.py +47 -0
- noshot-0.1.0.dist-info/LICENSE.txt +21 -0
- noshot-0.1.0.dist-info/METADATA +65 -0
- noshot-0.1.0.dist-info/RECORD +210 -0
- noshot-0.1.0.dist-info/WHEEL +5 -0
- noshot-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,597 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": 1,
|
6
|
+
"id": "8d2eeff8-b13a-497d-a879-98946745f92e",
|
7
|
+
"metadata": {},
|
8
|
+
"outputs": [
|
9
|
+
{
|
10
|
+
"name": "stdin",
|
11
|
+
"output_type": "stream",
|
12
|
+
"text": [
|
13
|
+
"Enter the states (comma-separated): cp,ip\n",
|
14
|
+
"Enter the possible observations (comma-separated): lem,icet,cola\n",
|
15
|
+
"Enter the observation sequence as space-separated names (options: ['lem', 'icet', 'cola']): lem icet cola\n"
|
16
|
+
]
|
17
|
+
},
|
18
|
+
{
|
19
|
+
"name": "stdout",
|
20
|
+
"output_type": "stream",
|
21
|
+
"text": [
|
22
|
+
"\n",
|
23
|
+
"Enter the state transition probabilities:\n"
|
24
|
+
]
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"name": "stdin",
|
28
|
+
"output_type": "stream",
|
29
|
+
"text": [
|
30
|
+
"P(cp | cp): 0.7\n",
|
31
|
+
"P(ip | cp): 0.5\n",
|
32
|
+
"P(cp | ip): 0.3\n",
|
33
|
+
"P(ip | ip): 0.5\n"
|
34
|
+
]
|
35
|
+
},
|
36
|
+
{
|
37
|
+
"name": "stdout",
|
38
|
+
"output_type": "stream",
|
39
|
+
"text": [
|
40
|
+
"\n",
|
41
|
+
"Enter the emission probabilities:\n"
|
42
|
+
]
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"name": "stdin",
|
46
|
+
"output_type": "stream",
|
47
|
+
"text": [
|
48
|
+
"P(lem | cp): 0.3\n",
|
49
|
+
"P(icet | cp): 0.1\n",
|
50
|
+
"P(cola | cp): 0.6\n",
|
51
|
+
"P(lem | ip): 0.2\n",
|
52
|
+
"P(icet | ip): 0.7\n",
|
53
|
+
"P(cola | ip): 0.1\n"
|
54
|
+
]
|
55
|
+
},
|
56
|
+
{
|
57
|
+
"name": "stdout",
|
58
|
+
"output_type": "stream",
|
59
|
+
"text": [
|
60
|
+
"\n",
|
61
|
+
"Enter the initial state probabilities (comma-separated):\n"
|
62
|
+
]
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"name": "stdin",
|
66
|
+
"output_type": "stream",
|
67
|
+
"text": [
|
68
|
+
"Enter initial probabilities for ['cp', 'ip']: 1.0,0.0\n"
|
69
|
+
]
|
70
|
+
},
|
71
|
+
{
|
72
|
+
"name": "stdout",
|
73
|
+
"output_type": "stream",
|
74
|
+
"text": [
|
75
|
+
"\n",
|
76
|
+
"Backward Matrix:\n",
|
77
|
+
" [[0.1134 0.47 1. ]\n",
|
78
|
+
" [0.0946 0.23 1. ]]\n",
|
79
|
+
"Probability of the observation sequence (using backward procedure): 0.03401999999999999\n",
|
80
|
+
"\n",
|
81
|
+
"Viterbi Matrix:\n",
|
82
|
+
" [[0.3 0.021 0.0189 ]\n",
|
83
|
+
" [0. 0.105 0.00525]]\n",
|
84
|
+
"Most probable state sequence: ['cp', 'ip', 'cp']\n"
|
85
|
+
]
|
86
|
+
}
|
87
|
+
],
|
88
|
+
"source": [
|
89
|
+
"import numpy as np\n",
|
90
|
+
"\n",
|
91
|
+
"# Step 1: Define states and observations based on user input\n",
|
92
|
+
"states = list(map(str.strip, input(\"Enter the states (comma-separated): \").split(',')))\n",
|
93
|
+
"observations = list(map(str.strip, input(\"Enter the possible observations (comma-separated): \").split(',')))\n",
|
94
|
+
"\n",
|
95
|
+
"# Step 2: Get user input for the observation sequence\n",
|
96
|
+
"observation_seq = list(map(str.strip, input(f\"Enter the observation sequence as space-separated names (options: {observations}): \").split()))\n",
|
97
|
+
"\n",
|
98
|
+
"# Step 3: Convert observation sequence to indices\n",
|
99
|
+
"try:\n",
|
100
|
+
" observation_indices = [observations.index(obs) for obs in observation_seq]\n",
|
101
|
+
"except ValueError as e:\n",
|
102
|
+
" print(f\"Error: {e}. Please make sure your observation sequence contains only valid options: {observations}.\")\n",
|
103
|
+
" exit()\n",
|
104
|
+
"\n",
|
105
|
+
"# Step 4: Get user input for the transition matrix\n",
|
106
|
+
"print(\"\\nEnter the state transition probabilities:\")\n",
|
107
|
+
"transition_matrix = np.zeros((len(states), len(states)))\n",
|
108
|
+
"for i in range(len(states)):\n",
|
109
|
+
" for j in range(len(states)):\n",
|
110
|
+
" transition_matrix[i, j] = float(input(f\"P({states[j]} | {states[i]}): \"))\n",
|
111
|
+
"\n",
|
112
|
+
"# Step 5: Get user input for the emission matrix\n",
|
113
|
+
"print(\"\\nEnter the emission probabilities:\")\n",
|
114
|
+
"emission_matrix = np.zeros((len(states), len(observations)))\n",
|
115
|
+
"for i in range(len(states)):\n",
|
116
|
+
" for j in range(len(observations)):\n",
|
117
|
+
" emission_matrix[i, j] = float(input(f\"P({observations[j]} | {states[i]}): \"))\n",
|
118
|
+
"\n",
|
119
|
+
"# Step 6: Set initial state probabilities (ask the user to input them)\n",
|
120
|
+
"initial_probabilities = np.zeros(len(states))\n",
|
121
|
+
"print(\"\\nEnter the initial state probabilities (comma-separated):\")\n",
|
122
|
+
"initial_probabilities = list(map(float, input(f\"Enter initial probabilities for {states}: \").split(',')))\n",
|
123
|
+
"\n",
|
124
|
+
"# Step 7: Backward Procedure\n",
|
125
|
+
"def backward_procedure(observation_seq, transition_matrix, emission_matrix):\n",
|
126
|
+
" num_states = len(transition_matrix)\n",
|
127
|
+
" num_observations = len(observation_seq)\n",
|
128
|
+
" \n",
|
129
|
+
" # Initialize the backward matrix\n",
|
130
|
+
" backward_matrix = np.zeros((num_states, num_observations))\n",
|
131
|
+
" \n",
|
132
|
+
" # Initialization step: Fill the last column with 1 (termination condition)\n",
|
133
|
+
" backward_matrix[:, num_observations - 1] = 1\n",
|
134
|
+
" \n",
|
135
|
+
" # Recursion step\n",
|
136
|
+
" for t in range(num_observations - 2, -1, -1):\n",
|
137
|
+
" for i in range(num_states):\n",
|
138
|
+
" backward_matrix[i, t] = sum(transition_matrix[i, j] * emission_matrix[j, observation_seq[t + 1]] * backward_matrix[j, t + 1] for j in range(num_states))\n",
|
139
|
+
" \n",
|
140
|
+
" # Compute the probability of the observation sequence\n",
|
141
|
+
" prob_observation = sum(initial_probabilities[i] * emission_matrix[i, observation_seq[0]] * backward_matrix[i, 0] for i in range(num_states))\n",
|
142
|
+
" \n",
|
143
|
+
" return backward_matrix, prob_observation\n",
|
144
|
+
"\n",
|
145
|
+
"# Step 8: Viterbi Algorithm (to find the best state sequence)\n",
|
146
|
+
"def viterbi_algorithm(observation_seq, transition_matrix, emission_matrix, initial_probabilities):\n",
|
147
|
+
" num_states = len(transition_matrix)\n",
|
148
|
+
" num_observations = len(observation_seq)\n",
|
149
|
+
" \n",
|
150
|
+
" # Initialize the Viterbi matrix and the backpointer matrix\n",
|
151
|
+
" viterbi_matrix = np.zeros((num_states, num_observations))\n",
|
152
|
+
" backpointer = np.zeros((num_states, num_observations), dtype=int)\n",
|
153
|
+
" \n",
|
154
|
+
" # Initialization step\n",
|
155
|
+
" for i in range(num_states):\n",
|
156
|
+
" viterbi_matrix[i, 0] = initial_probabilities[i] * emission_matrix[i, observation_seq[0]]\n",
|
157
|
+
" \n",
|
158
|
+
" # Recursion step\n",
|
159
|
+
" for t in range(1, num_observations):\n",
|
160
|
+
" for j in range(num_states):\n",
|
161
|
+
" probabilities = [viterbi_matrix[i, t - 1] * transition_matrix[i, j] * emission_matrix[j, observation_seq[t]] for i in range(num_states)]\n",
|
162
|
+
" viterbi_matrix[j, t] = max(probabilities)\n",
|
163
|
+
" backpointer[j, t] = np.argmax(probabilities)\n",
|
164
|
+
" \n",
|
165
|
+
" # Termination step\n",
|
166
|
+
" best_last_state = np.argmax(viterbi_matrix[:, num_observations - 1])\n",
|
167
|
+
" \n",
|
168
|
+
" # Backtrack to find the most probable state sequence\n",
|
169
|
+
" best_path = [best_last_state]\n",
|
170
|
+
" for t in range(num_observations - 1, 0, -1):\n",
|
171
|
+
" best_last_state = backpointer[best_last_state, t]\n",
|
172
|
+
" best_path.insert(0, best_last_state)\n",
|
173
|
+
" \n",
|
174
|
+
" best_state_sequence = [states[state_index] for state_index in best_path]\n",
|
175
|
+
" \n",
|
176
|
+
" return best_state_sequence, viterbi_matrix\n",
|
177
|
+
"\n",
|
178
|
+
"# Step 9: Compute the backward matrix and the probability of the observation sequence\n",
|
179
|
+
"backward_matrix, prob_observation_backward = backward_procedure(observation_indices, transition_matrix, emission_matrix)\n",
|
180
|
+
"print(\"\\nBackward Matrix:\\n\", backward_matrix)\n",
|
181
|
+
"print(\"Probability of the observation sequence (using backward procedure):\", prob_observation_backward)\n",
|
182
|
+
"\n",
|
183
|
+
"# Step 10: Compute the most probable state sequence using Viterbi algorithm\n",
|
184
|
+
"best_state_sequence, viterbi_matrix = viterbi_algorithm(observation_indices, transition_matrix, emission_matrix, initial_probabilities)\n",
|
185
|
+
"print(\"\\nViterbi Matrix:\\n\", viterbi_matrix)\n",
|
186
|
+
"print(\"Most probable state sequence:\", best_state_sequence)\n"
|
187
|
+
]
|
188
|
+
},
|
189
|
+
{
|
190
|
+
"cell_type": "code",
|
191
|
+
"execution_count": 1,
|
192
|
+
"id": "2acfa85e-c9f1-41ce-9ebf-6283066554cc",
|
193
|
+
"metadata": {},
|
194
|
+
"outputs": [
|
195
|
+
{
|
196
|
+
"name": "stdin",
|
197
|
+
"output_type": "stream",
|
198
|
+
"text": [
|
199
|
+
"Enter the states (comma-separated): 1,2,3\n",
|
200
|
+
"Enter the possible observations (comma-separated): up,down,unchanged\n",
|
201
|
+
"Enter the observation sequence as space-separated names (options: ['up', 'down', 'unchanged']): up up up up up\n"
|
202
|
+
]
|
203
|
+
},
|
204
|
+
{
|
205
|
+
"name": "stdout",
|
206
|
+
"output_type": "stream",
|
207
|
+
"text": [
|
208
|
+
"\n",
|
209
|
+
"Enter the state transition probabilities:\n"
|
210
|
+
]
|
211
|
+
},
|
212
|
+
{
|
213
|
+
"name": "stdin",
|
214
|
+
"output_type": "stream",
|
215
|
+
"text": [
|
216
|
+
"P(1 | 1): 0.6\n",
|
217
|
+
"P(2 | 1): 0.2\n",
|
218
|
+
"P(3 | 1): 0.2\n",
|
219
|
+
"P(1 | 2): 0.5\n",
|
220
|
+
"P(2 | 2): 0.3\n",
|
221
|
+
"P(3 | 2): 0.2\n",
|
222
|
+
"P(1 | 3): 0.4\n",
|
223
|
+
"P(2 | 3): 0.1\n",
|
224
|
+
"P(3 | 3): 0.5\n"
|
225
|
+
]
|
226
|
+
},
|
227
|
+
{
|
228
|
+
"name": "stdout",
|
229
|
+
"output_type": "stream",
|
230
|
+
"text": [
|
231
|
+
"\n",
|
232
|
+
"Enter the emission probabilities:\n"
|
233
|
+
]
|
234
|
+
},
|
235
|
+
{
|
236
|
+
"name": "stdin",
|
237
|
+
"output_type": "stream",
|
238
|
+
"text": [
|
239
|
+
"P(up | 1): 0.7\n",
|
240
|
+
"P(down | 1): 0.1\n",
|
241
|
+
"P(unchanged | 1): 0.2\n",
|
242
|
+
"P(up | 2): 0.1\n",
|
243
|
+
"P(down | 2): 0.6\n",
|
244
|
+
"P(unchanged | 2): 0.3\n",
|
245
|
+
"P(up | 3): 0.3\n",
|
246
|
+
"P(down | 3): 0.3\n",
|
247
|
+
"P(unchanged | 3): 0.4\n"
|
248
|
+
]
|
249
|
+
},
|
250
|
+
{
|
251
|
+
"name": "stdout",
|
252
|
+
"output_type": "stream",
|
253
|
+
"text": [
|
254
|
+
"\n",
|
255
|
+
"Enter the initial state probabilities (comma-separated):\n"
|
256
|
+
]
|
257
|
+
},
|
258
|
+
{
|
259
|
+
"name": "stdin",
|
260
|
+
"output_type": "stream",
|
261
|
+
"text": [
|
262
|
+
"Enter initial probabilities for ['1', '2', '3']: 0.5,0.2,0.3\n"
|
263
|
+
]
|
264
|
+
},
|
265
|
+
{
|
266
|
+
"name": "stdout",
|
267
|
+
"output_type": "stream",
|
268
|
+
"text": [
|
269
|
+
"\n",
|
270
|
+
"Backward Matrix:\n",
|
271
|
+
" [[0.05859736 0.1199 0.2452 0.5 1. ]\n",
|
272
|
+
" [0.05125318 0.104882 0.2146 0.44 1. ]\n",
|
273
|
+
" [0.04997512 0.102362 0.2104 0.44 1. ]]\n",
|
274
|
+
"Probability of the observation sequence (using backward procedure): 0.026031900399999995\n",
|
275
|
+
"\n",
|
276
|
+
"Viterbi Matrix:\n",
|
277
|
+
" [[0.35 0.147 0.06174 0.0259308 0.01089094]\n",
|
278
|
+
" [0.02 0.007 0.00294 0.0012348 0.00051862]\n",
|
279
|
+
" [0.09 0.021 0.00882 0.0037044 0.00155585]]\n",
|
280
|
+
"Most probable state sequence: ['1', '1', '1', '1', '1']\n"
|
281
|
+
]
|
282
|
+
}
|
283
|
+
],
|
284
|
+
"source": [
|
285
|
+
"import numpy as np\n",
|
286
|
+
"\n",
|
287
|
+
"# Step 1: Define states and observations based on user input\n",
|
288
|
+
"states = list(map(str.strip, input(\"Enter the states (comma-separated): \").split(',')))\n",
|
289
|
+
"observations = list(map(str.strip, input(\"Enter the possible observations (comma-separated): \").split(',')))\n",
|
290
|
+
"\n",
|
291
|
+
"# Step 2: Get user input for the observation sequence\n",
|
292
|
+
"observation_seq = list(map(str.strip, input(f\"Enter the observation sequence as space-separated names (options: {observations}): \").split()))\n",
|
293
|
+
"\n",
|
294
|
+
"# Step 3: Convert observation sequence to indices\n",
|
295
|
+
"try:\n",
|
296
|
+
" observation_indices = [observations.index(obs) for obs in observation_seq]\n",
|
297
|
+
"except ValueError as e:\n",
|
298
|
+
" print(f\"Error: {e}. Please make sure your observation sequence contains only valid options: {observations}.\")\n",
|
299
|
+
" exit()\n",
|
300
|
+
"\n",
|
301
|
+
"# Step 4: Get user input for the transition matrix\n",
|
302
|
+
"print(\"\\nEnter the state transition probabilities:\")\n",
|
303
|
+
"transition_matrix = np.zeros((len(states), len(states)))\n",
|
304
|
+
"for i in range(len(states)):\n",
|
305
|
+
" for j in range(len(states)):\n",
|
306
|
+
" transition_matrix[i, j] = float(input(f\"P({states[j]} | {states[i]}): \"))\n",
|
307
|
+
"\n",
|
308
|
+
"# Step 5: Get user input for the emission matrix\n",
|
309
|
+
"print(\"\\nEnter the emission probabilities:\")\n",
|
310
|
+
"emission_matrix = np.zeros((len(states), len(observations)))\n",
|
311
|
+
"for i in range(len(states)):\n",
|
312
|
+
" for j in range(len(observations)):\n",
|
313
|
+
" emission_matrix[i, j] = float(input(f\"P({observations[j]} | {states[i]}): \"))\n",
|
314
|
+
"\n",
|
315
|
+
"# Step 6: Set initial state probabilities (ask the user to input them)\n",
|
316
|
+
"initial_probabilities = np.zeros(len(states))\n",
|
317
|
+
"print(\"\\nEnter the initial state probabilities (comma-separated):\")\n",
|
318
|
+
"initial_probabilities = list(map(float, input(f\"Enter initial probabilities for {states}: \").split(',')))\n",
|
319
|
+
"\n",
|
320
|
+
"# Step 7: Backward Procedure\n",
|
321
|
+
"def backward_procedure(observation_seq, transition_matrix, emission_matrix):\n",
|
322
|
+
" num_states = len(transition_matrix)\n",
|
323
|
+
" num_observations = len(observation_seq)\n",
|
324
|
+
" \n",
|
325
|
+
" # Initialize the backward matrix\n",
|
326
|
+
" backward_matrix = np.zeros((num_states, num_observations))\n",
|
327
|
+
" \n",
|
328
|
+
" # Initialization step: Fill the last column with 1 (termination condition)\n",
|
329
|
+
" backward_matrix[:, num_observations - 1] = 1\n",
|
330
|
+
" \n",
|
331
|
+
" # Recursion step\n",
|
332
|
+
" for t in range(num_observations - 2, -1, -1):\n",
|
333
|
+
" for i in range(num_states):\n",
|
334
|
+
" backward_matrix[i, t] = sum(transition_matrix[i, j] * emission_matrix[j, observation_seq[t + 1]] * backward_matrix[j, t + 1] for j in range(num_states))\n",
|
335
|
+
" \n",
|
336
|
+
" # Compute the probability of the observation sequence\n",
|
337
|
+
" prob_observation = sum(initial_probabilities[i] * emission_matrix[i, observation_seq[0]] * backward_matrix[i, 0] for i in range(num_states))\n",
|
338
|
+
" \n",
|
339
|
+
" return backward_matrix, prob_observation\n",
|
340
|
+
"\n",
|
341
|
+
"# Step 8: Viterbi Algorithm (to find the best state sequence)\n",
|
342
|
+
"def viterbi_algorithm(observation_seq, transition_matrix, emission_matrix, initial_probabilities):\n",
|
343
|
+
" num_states = len(transition_matrix)\n",
|
344
|
+
" num_observations = len(observation_seq)\n",
|
345
|
+
" \n",
|
346
|
+
" # Initialize the Viterbi matrix and the backpointer matrix\n",
|
347
|
+
" viterbi_matrix = np.zeros((num_states, num_observations))\n",
|
348
|
+
" backpointer = np.zeros((num_states, num_observations), dtype=int)\n",
|
349
|
+
" \n",
|
350
|
+
" # Initialization step\n",
|
351
|
+
" for i in range(num_states):\n",
|
352
|
+
" viterbi_matrix[i, 0] = initial_probabilities[i] * emission_matrix[i, observation_seq[0]]\n",
|
353
|
+
" \n",
|
354
|
+
" # Recursion step\n",
|
355
|
+
" for t in range(1, num_observations):\n",
|
356
|
+
" for j in range(num_states):\n",
|
357
|
+
" probabilities = [viterbi_matrix[i, t - 1] * transition_matrix[i, j] * emission_matrix[j, observation_seq[t]] for i in range(num_states)]\n",
|
358
|
+
" viterbi_matrix[j, t] = max(probabilities)\n",
|
359
|
+
" backpointer[j, t] = np.argmax(probabilities)\n",
|
360
|
+
" \n",
|
361
|
+
" # Termination step\n",
|
362
|
+
" best_last_state = np.argmax(viterbi_matrix[:, num_observations - 1])\n",
|
363
|
+
" \n",
|
364
|
+
" # Backtrack to find the most probable state sequence\n",
|
365
|
+
" best_path = [best_last_state]\n",
|
366
|
+
" for t in range(num_observations - 1, 0, -1):\n",
|
367
|
+
" best_last_state = backpointer[best_last_state, t]\n",
|
368
|
+
" best_path.insert(0, best_last_state)\n",
|
369
|
+
" \n",
|
370
|
+
" best_state_sequence = [states[state_index] for state_index in best_path]\n",
|
371
|
+
" \n",
|
372
|
+
" return best_state_sequence, viterbi_matrix\n",
|
373
|
+
"\n",
|
374
|
+
"# Step 9: Compute the backward matrix and the probability of the observation sequence\n",
|
375
|
+
"backward_matrix, prob_observation_backward = backward_procedure(observation_indices, transition_matrix, emission_matrix)\n",
|
376
|
+
"print(\"\\nBackward Matrix:\\n\", backward_matrix)\n",
|
377
|
+
"print(\"Probability of the observation sequence (using backward procedure):\", prob_observation_backward)\n",
|
378
|
+
"\n",
|
379
|
+
"# Step 10: Compute the most probable state sequence using Viterbi algorithm\n",
|
380
|
+
"best_state_sequence, viterbi_matrix = viterbi_algorithm(observation_indices, transition_matrix, emission_matrix, initial_probabilities)\n",
|
381
|
+
"print(\"\\nViterbi Matrix:\\n\", viterbi_matrix)\n",
|
382
|
+
"print(\"Most probable state sequence:\", best_state_sequence)\n"
|
383
|
+
]
|
384
|
+
},
|
385
|
+
{
|
386
|
+
"cell_type": "code",
|
387
|
+
"execution_count": 2,
|
388
|
+
"id": "47ad375b-4939-4c61-84b9-cff0eb2485c8",
|
389
|
+
"metadata": {},
|
390
|
+
"outputs": [
|
391
|
+
{
|
392
|
+
"name": "stdin",
|
393
|
+
"output_type": "stream",
|
394
|
+
"text": [
|
395
|
+
"Enter the number of states: 2\n",
|
396
|
+
"Enter state 1: cp\n",
|
397
|
+
"Enter state 2: ip\n",
|
398
|
+
"Enter the number of observations: 3\n",
|
399
|
+
"Enter observation 1: lem\n",
|
400
|
+
"Enter observation 2: icet\n",
|
401
|
+
"Enter observation 3: cola\n"
|
402
|
+
]
|
403
|
+
},
|
404
|
+
{
|
405
|
+
"name": "stdout",
|
406
|
+
"output_type": "stream",
|
407
|
+
"text": [
|
408
|
+
"\n",
|
409
|
+
"Enter start probabilities for each state:\n"
|
410
|
+
]
|
411
|
+
},
|
412
|
+
{
|
413
|
+
"name": "stdin",
|
414
|
+
"output_type": "stream",
|
415
|
+
"text": [
|
416
|
+
"Start probability for cp: 1.0\n",
|
417
|
+
"Start probability for ip: 0.0\n"
|
418
|
+
]
|
419
|
+
},
|
420
|
+
{
|
421
|
+
"name": "stdout",
|
422
|
+
"output_type": "stream",
|
423
|
+
"text": [
|
424
|
+
"\n",
|
425
|
+
"Enter transition probabilities (from each state to other states):\n"
|
426
|
+
]
|
427
|
+
},
|
428
|
+
{
|
429
|
+
"name": "stdin",
|
430
|
+
"output_type": "stream",
|
431
|
+
"text": [
|
432
|
+
"Transition probability from cp to cp: 0.7\n",
|
433
|
+
"Transition probability from cp to ip: 0.3\n",
|
434
|
+
"Transition probability from ip to cp: 0.5\n",
|
435
|
+
"Transition probability from ip to ip: 0.5\n"
|
436
|
+
]
|
437
|
+
},
|
438
|
+
{
|
439
|
+
"name": "stdout",
|
440
|
+
"output_type": "stream",
|
441
|
+
"text": [
|
442
|
+
"\n",
|
443
|
+
"Enter emission probabilities (from each state to each observation):\n"
|
444
|
+
]
|
445
|
+
},
|
446
|
+
{
|
447
|
+
"name": "stdin",
|
448
|
+
"output_type": "stream",
|
449
|
+
"text": [
|
450
|
+
"Emission probability of lem from cp: 0.3\n",
|
451
|
+
"Emission probability of icet from cp: 0.1\n",
|
452
|
+
"Emission probability of cola from cp: 0.6\n",
|
453
|
+
"Emission probability of lem from ip: 0.2\n",
|
454
|
+
"Emission probability of icet from ip: 0.7\n",
|
455
|
+
"Emission probability of cola from ip: 0.1\n",
|
456
|
+
"\n",
|
457
|
+
"Enter the observation sequence (space-separated): lem icet cola\n"
|
458
|
+
]
|
459
|
+
},
|
460
|
+
{
|
461
|
+
"name": "stdout",
|
462
|
+
"output_type": "stream",
|
463
|
+
"text": [
|
464
|
+
"\n",
|
465
|
+
"Best state sequence: ['cp', 'ip', 'cp']\n",
|
466
|
+
"Best path probability: 0.0189\n"
|
467
|
+
]
|
468
|
+
}
|
469
|
+
],
|
470
|
+
"source": [
|
471
|
+
"import numpy as np\n",
|
472
|
+
"class HiddenMarkovModel:\n",
|
473
|
+
" def __init__(self, states, observations, start_prob, trans_prob, emission_prob):\n",
|
474
|
+
" self.states = states # Possible hidden states (tags)\n",
|
475
|
+
" self.observations = observations # Possible observations (words)\n",
|
476
|
+
" self.start_prob = start_prob # Initial probabilities of states\n",
|
477
|
+
" self.trans_prob = trans_prob # Transition probabilities between states\n",
|
478
|
+
" self.emission_prob = emission_prob # Emission probabilities of states producing observations\n",
|
479
|
+
"\n",
|
480
|
+
" def viterbi(self, obs_seq):\n",
|
481
|
+
" n_states = len(self.states)\n",
|
482
|
+
" n_observations = len(obs_seq)\n",
|
483
|
+
"\n",
|
484
|
+
" viterbi_table = np.zeros((n_states, n_observations))\n",
|
485
|
+
" backpointer = np.zeros((n_states, n_observations), dtype=int)\n",
|
486
|
+
"\n",
|
487
|
+
" for s in range(n_states):\n",
|
488
|
+
" viterbi_table[s, 0] = self.start_prob[s] * self.emission_prob[s][self.observations.index(obs_seq[0])]\n",
|
489
|
+
" backpointer[s, 0] = 0\n",
|
490
|
+
"\n",
|
491
|
+
" for t in range(1, n_observations):\n",
|
492
|
+
" for s in range(n_states):\n",
|
493
|
+
"\n",
|
494
|
+
" max_prob, max_state = max(\n",
|
495
|
+
" (viterbi_table[prev_s, t-1] * self.trans_prob[prev_s][s] *\n",
|
496
|
+
" self.emission_prob[s][self.observations.index(obs_seq[t])], prev_s)\n",
|
497
|
+
" for prev_s in range(n_states)\n",
|
498
|
+
" )\n",
|
499
|
+
" viterbi_table[s, t] = max_prob\n",
|
500
|
+
" backpointer[s, t] = max_state\n",
|
501
|
+
" \n",
|
502
|
+
" best_path_prob = max(viterbi_table[:, -1])\n",
|
503
|
+
" best_path_pointer = np.argmax(viterbi_table[:, -1])\n",
|
504
|
+
" best_path = [best_path_pointer]\n",
|
505
|
+
" \n",
|
506
|
+
" for t in range(n_observations - 1, 0, -1):\n",
|
507
|
+
" best_path_pointer = backpointer[best_path_pointer, t]\n",
|
508
|
+
" best_path.insert(0, best_path_pointer)\n",
|
509
|
+
" \n",
|
510
|
+
" best_state_sequence = [self.states[i] for i in best_path]\n",
|
511
|
+
" return best_state_sequence, best_path_prob\n",
|
512
|
+
"\n",
|
513
|
+
"\n",
|
514
|
+
"def get_user_input():\n",
|
515
|
+
" num_states = int(input(\"Enter the number of states: \"))\n",
|
516
|
+
" states = []\n",
|
517
|
+
" for i in range(num_states):\n",
|
518
|
+
" state = input(f\"Enter state {i + 1}: \")\n",
|
519
|
+
" states.append(state)\n",
|
520
|
+
" \n",
|
521
|
+
" num_observations = int(input(\"Enter the number of observations: \"))\n",
|
522
|
+
" observations = []\n",
|
523
|
+
" for i in range(num_observations):\n",
|
524
|
+
" observation = input(f\"Enter observation {i + 1}: \")\n",
|
525
|
+
" observations.append(observation)\n",
|
526
|
+
" \n",
|
527
|
+
" print(\"\\nEnter start probabilities for each state:\")\n",
|
528
|
+
" start_prob = []\n",
|
529
|
+
" for state in states:\n",
|
530
|
+
" prob = float(input(f\"Start probability for {state}: \"))\n",
|
531
|
+
" start_prob.append(prob)\n",
|
532
|
+
" \n",
|
533
|
+
" print(\"\\nEnter transition probabilities (from each state to other states):\")\n",
|
534
|
+
" trans_prob = []\n",
|
535
|
+
" for i, from_state in enumerate(states):\n",
|
536
|
+
" trans_row = []\n",
|
537
|
+
" for j, to_state in enumerate(states):\n",
|
538
|
+
" prob = float(input(f\"Transition probability from {from_state} to {to_state}: \"))\n",
|
539
|
+
" trans_row.append(prob)\n",
|
540
|
+
" trans_prob.append(trans_row)\n",
|
541
|
+
" \n",
|
542
|
+
" print(\"\\nEnter emission probabilities (from each state to each observation):\")\n",
|
543
|
+
" emission_prob = []\n",
|
544
|
+
" for i, state in enumerate(states):\n",
|
545
|
+
" emission_row = []\n",
|
546
|
+
" for j, observation in enumerate(observations):\n",
|
547
|
+
" prob = float(input(f\"Emission probability of {observation} from {state}: \"))\n",
|
548
|
+
" emission_row.append(prob)\n",
|
549
|
+
" emission_prob.append(emission_row)\n",
|
550
|
+
" \n",
|
551
|
+
" return states, observations, start_prob, trans_prob, emission_prob\n",
|
552
|
+
"\n",
|
553
|
+
"\n",
|
554
|
+
"if __name__ == \"__main__\":\n",
|
555
|
+
" states, observations, start_prob, trans_prob, emission_prob = get_user_input()\n",
|
556
|
+
"\n",
|
557
|
+
" hmm = HiddenMarkovModel(states, observations, start_prob, trans_prob, emission_prob)\n",
|
558
|
+
"\n",
|
559
|
+
" obs_seq = input(\"\\nEnter the observation sequence (space-separated): \").split()\n",
|
560
|
+
"\n",
|
561
|
+
" best_sequence, best_prob = hmm.viterbi(obs_seq)\n",
|
562
|
+
" print(\"\\nBest state sequence:\", best_sequence)\n",
|
563
|
+
" print(\"Best path probability:\", best_prob)\n",
|
564
|
+
" "
|
565
|
+
]
|
566
|
+
},
|
567
|
+
{
|
568
|
+
"cell_type": "code",
|
569
|
+
"execution_count": null,
|
570
|
+
"id": "a7d52d1f-c7fb-4b4b-acc5-cc8c4ee70dbe",
|
571
|
+
"metadata": {},
|
572
|
+
"outputs": [],
|
573
|
+
"source": []
|
574
|
+
}
|
575
|
+
],
|
576
|
+
"metadata": {
|
577
|
+
"kernelspec": {
|
578
|
+
"display_name": "Python 3 (ipykernel)",
|
579
|
+
"language": "python",
|
580
|
+
"name": "python3"
|
581
|
+
},
|
582
|
+
"language_info": {
|
583
|
+
"codemirror_mode": {
|
584
|
+
"name": "ipython",
|
585
|
+
"version": 3
|
586
|
+
},
|
587
|
+
"file_extension": ".py",
|
588
|
+
"mimetype": "text/x-python",
|
589
|
+
"name": "python",
|
590
|
+
"nbconvert_exporter": "python",
|
591
|
+
"pygments_lexer": "ipython3",
|
592
|
+
"version": "3.11.7"
|
593
|
+
}
|
594
|
+
},
|
595
|
+
"nbformat": 4,
|
596
|
+
"nbformat_minor": 5
|
597
|
+
}
|