Skip to content

Commit

Permalink
updates to 07 and 07b
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmagnuson committed Oct 11, 2024
1 parent a9821e8 commit ec06b89
Show file tree
Hide file tree
Showing 8 changed files with 210,966 additions and 210 deletions.
72 changes: 21 additions & 51 deletions 05-bayes-theorem-rev.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7e17171994c94b3190813b075419b3c8",
"model_id": "af92558895394ab9bf7c5ef0c0fdada2",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -78,7 +78,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "baa7324ff2af466cb613403274340984",
"model_id": "5722da8cf94a48d28f0ce8d4cbdd321d",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -100,7 +100,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e73926eee9ae4bdcbba627e42395b897",
"model_id": "620f7b5fd2ad47f7bb13711fc4ec47ec",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -114,7 +114,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "89e67c19a6264ffaa36d2e6d45eb9b85",
"model_id": "6fa8e5c858824aef96277a598e3c6128",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -275,7 +275,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "1ab2f1d7-b0ec-47ac-8dfe-ced25f344492",
"metadata": {},
"outputs": [
Expand All @@ -298,15 +298,15 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b190557347894fef94c35f67110cb2d0",
"model_id": "ca8a3bff0ec34c0883a7e1ad2fdb25f5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(VBox(children=(FloatSlider(value=0.01, description='Base Rate:', max=1.0, step=0.01), FloatSlid…"
]
},
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -373,12 +373,18 @@
" prob_test_negative = 1 - prob_test_positive\n",
"\n",
" # Bayes' theorem for positive test result\n",
" prob_disease_given_pos_test = (true_positive_rate * base_rate) / prob_test_positive\n",
" print(f\"Probability of having bayesitis given a positive test: {prob_disease_given_pos_test:.4f}\")\n",
" if prob_test_positive > 0:\n",
" prob_disease_given_pos_test = (true_positive_rate * base_rate) / prob_test_positive\n",
" print(f\"Probability of having bayesitis given a positive test: {prob_disease_given_pos_test:.4f}\")\n",
" else: \n",
" print(f\"Probability of having bayesitis given a positive test: NOT DEFINED BECAUSE PROBABILITY OF A POSITIVE TEST IS ZERO\")\n",
"\n",
" # Bayes' theorem for negative test result\n",
" prob_disease_given_neg_test = ((1 - true_positive_rate) * base_rate) / prob_test_negative\n",
" print(f\"Probability of having bayesitis given a negative test: {prob_disease_given_neg_test:.4f}\")\n",
" if prob_test_negative > 0:\n",
" prob_disease_given_neg_test = ((1 - true_positive_rate) * base_rate) / prob_test_negative\n",
" print(f\"Probability of having bayesitis given a negative test: {prob_disease_given_neg_test:.4f}\")\n",
" else: \n",
" print(f\"Probability of having bayesitis given a negative test: NOT DEFINED BECAUSE PROBABILITY OF A NEGATIVE TEST IS ZERO\")\n",
"\n",
"# Create interactive output\n",
"out = widgets.interactive_output(\n",
Expand Down Expand Up @@ -432,30 +438,10 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "2c53fdcb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Haves 10.0, Nots 990.0, p_has 0.15384615384615385, p_not 0.0010090817356205853\n",
"\n",
"We are going to round these numbers now to think about them as individuals. \n",
"\n",
"That is, approximately 10 have it, and approximately 990 do not. \n",
"Among those who have the disease, approximately 9 will test positive. \n",
"Among those who do not have the disease, approximately 50 will also test \n",
"positive.\n",
"\n",
"So while approximately 58 people are expected to test positive, only \n",
"approximately 9 of those have the disease.\n",
"\n",
"So the probability of having the disease is approximately 9/(9 + 50) = 0.1525. \n"
]
}
],
"outputs": [],
"source": [
"# population = 1000\n",
"# base_rate = 0.01\n",
Expand Down Expand Up @@ -527,26 +513,10 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "7fd484bf-b1c7-4e2e-80d8-3d193d6f9700",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "16f6aedbc6ea4a5db8a98746ddb62226",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HBox(children=(FloatSlider(value=0.01, description='Base Rate:', max=1.0, step=0.01), IntSlider…"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"import numpy as np\n",
"import ipywidgets as widgets\n",
Expand Down
6 changes: 3 additions & 3 deletions 05-bayes-theorem.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 1,
"id": "1ab2f1d7-b0ec-47ac-8dfe-ced25f344492",
"metadata": {},
"outputs": [
Expand All @@ -298,15 +298,15 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a9d4442b49574212af4dc57391677bd2",
"model_id": "85e274a17e4248ebbd546908783c6e29",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(VBox(children=(FloatSlider(value=0.01, description='Base Rate:', max=1.0, step=0.01), FloatSlid…"
]
},
"execution_count": 6,
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
Expand Down
272 changes: 117 additions & 155 deletions 07-swr-bayes-004.ipynb

Large diffs are not rendered by default.

343 changes: 343 additions & 0 deletions 07b-alternative-with-features.ipynb

Large diffs are not rendered by default.

100 changes: 100 additions & 0 deletions 08-trace-swr.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "27845fff-e102-416e-a5d7-1949a33fc3ac",
"metadata": {},
"source": [
"### Implementations of the TRACE model\n",
"\n",
"The Magnuson & Crinnion chapter introduces the TRACE model. In this lab, we are going to use a new simulator we are developing in my lab. It is a little bit buggy still, but mostly works very well. \n",
"\n",
"The original TRACE model was written in the programming language C. This was a great choice back in the mid 1980s. C was the most used programming language (it passed Pascal and Fortran in 1985), and remained the most used programming language until 2001, when Java became more widely used. (Java then was the most used language until 2019 when it was passed by javascript, which was shortly passed by Python; see https://www.youtube.com/watch?v=qQXXI5QFUfw). \n",
"\n",
"C is fast, but also pretty complicated. McClelland and Elman made their original C code freely available, but almost no one used it because you really had to be a good programmer to use it. This led to a weird situation where there were many papers where people speculated about what TRACE would do if they tried to simulate their experiment -- *but they did not acutally run any simulations.* And people were wrong a lot! This is a really important thing about modeling. We may have really plausible, logical expectations about what the model *should* do, but a model does not have to be very complex before it surprises us. (If you are interested in some examples, see: Magnuson, J. S., Mirman, D., & Harris, H. D. (2012). Computational models of spoken word recognition. In M. Spivey, K. McRae, & M. Joanisse (Eds.), The Cambridge Handbook of Psycholinguistics, pp. 76-103. Cambridge University Press. [https://magnuson.psy.uconn.edu/wp-content/uploads/sites/1140/2015/01/Magnuson-Mirman-Harris-2012.pdf]). \n",
"\n",
"So back in the early 2000s, I set out to create a new implementation of TRACE in Java. Java was a huge deal back then, because it was the first programming language that strove to be platform independent. With minimal adjustment, Java programs could be run in operating systems ranging from DOS to Windows to OSX to Linux -- and more. That version (jTRACE, for java TRACE) is still available and works great. You can access it here (**but you do not need to even look at this for this lab!**): \n",
"\n",
"https://magnuson.psy.uconn.edu/jtrace/\n",
"\n",
"There was one huge flaw in the Java version. Often, you want to be able to do *batch simulations*. For example, you might want to run a simulation with every word in your lexicon. Or you might want to do that, but with many different parameter settings. We were working on a system for doing this, but we ran out of money, and we were unable to finish it. \n",
"\n",
"However, 3 years ago, I had funding I could use to revisit this. Rather than trying to further improve jTRACE, I decided to port it to javascript. javascript is related to java, but has a ton of Python-like capability. It's much more flexible. I hired a programmer, and it's now 98% done. It has not been released yet, but I'm going to share the preview version with you. A thing that is amazing about doing this in javascript is that we do not have to create our own mini-language or graphical interface for batch scripting. Instead, you just import the libraries and write an actual javascript. \n",
"\n",
"Now we could set things up to run in jupyter, because we can install a javascript kernel, and the latest version of TRACE is in javascript. However, you would have to install a lot of things on your machine, and one of the beauties of developing in javascript is we can easily host an installation that anyone on the internet can use. "
]
},
{
"cell_type": "markdown",
"id": "4bf86b6a-e74b-4c3e-84a1-7efb2ec3ad8c",
"metadata": {},
"source": [
"### jsTRACE\n",
"\n",
"You can run the preview version just by going to this link:\n",
"\n",
"https://andrew0.github.io/tracejs/\n",
"\n",
"This repository now includes a notebook that is just the (draft) manual for jsTRACE (jstrace-user-interface.ipynb). Reading the whole manual would be super boring. However, please read the sections *Introduction* and *A brief overview of TRACE*. You can search the manual for other questions. We will also go through the simulator in class. \n",
"\n",
"**Bugs**. If you discover bugs, please tell me about them. Here are some current ones.\n",
"\n",
"- Jitter -- sometimes the browswer window will jitter like crazy. Resize it (a little smaller or bigger) until that stops. \n",
"\n",
"- Simulation tab fonts and rectangle widths. When you run a simulation animation and click 'Visualize word/phoneme activations' the fonts are stretched out strangely, and the rectangles do not perfectly match temporal alignment yet. Also, the activations in the Chart tab are correct; they are inflated (by about 0.05) in the simulation tab. \n"
]
},
{
"cell_type": "markdown",
"id": "988f877f-4d9d-49de-8d6e-a7f7283cdc1b",
"metadata": {},
"source": [
"### Lab report\n",
"\n",
"1. Explore the interface. At the top of the screen, you will see 'tabs' for Config, Simulation, Chart and Data. Within Config, you have subtabs Parameters, Phonology, and Lexicon. Follow the instructions in the `jstrace-user-interface.ipynb` notebook under 'Quick start' to run a simulation and generate a chart. Paste in a screenshot of the chart from your computer (do not paste in the image from the manual!).\n",
"\n",
"2. On the chart tab, click 'Max (Post-Hoc)' in the Alignment calculation section, and then click Refresh Chart. (If the chart does not refresh, adjust the size of your browser window -- just click and drag to make slightly larger or smaller; this normally refreshses the chart if the button does not do it.) Paste in a screenshot of the new chart. Describe what is different. Do you understand why they are different? Refer to the section around Figure 4 in the manual for an explanation of the 'tiled' slice representations in TRACE. \n",
"\n",
"3. Replot your chart with Content set to Response probabilities (click on Activations to see that option). Insert a screenshot. Describe what you observe. Do you understand what is happening in this plot (simple yes or no is fine)?\n",
"\n",
"4. Set Content back to Activations, and switch Analyze to Phonemes. Insert a screenshot. What do you observe? What happens when you choose Specified Alignment vs. Max post-hoc? \n",
"\n",
"5. Compare to the Bayesian model we used previously. What are some aspects of SWR (spoken word recognition) that TRACE includes that were missing from our Bayesian model? What are some aspects of SWR that the Bayesian model could address that (this version of) TRACE cannot? \n",
"\n",
"6. **Challenge question**: refer to your Bayesian SWR homework and find some words you tested there. Can you test them in TRACE? TRACE only has about 200 words in its lexicon in this simulator, and it only has 14 of the 39 phonemes of English -- so it may be difficult to find specific words. However, consider the issues / concerns you had about the words you tested in the Bayesian model. Does TRACE seem to do better or worse when you consider those issues?\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "da727825-a115-4bca-9ce7-d3e786d7da14",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit ec06b89

Please sign in to comment.