Skip to content

Commit

Permalink
updates to lab 7 and HW 7
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicalundquist committed Nov 14, 2021
1 parent 5cf13c5 commit ae0a8d5
Show file tree
Hide file tree
Showing 3 changed files with 397 additions and 50 deletions.
12 changes: 8 additions & 4 deletions modules/lab7/lab7-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
"\n",
"Take one step through the Markov chain. What fraction of people live in the city after one step?\n",
"\n",
"This can be defined as the fraction of people who live in the city and stay in the city + the fraction of people who lived in the suburbs but move into the city.\n",
"\n",
"$p_{city,1}$ = 0.95 * 0.6 + 0.03 * 0.4"
]
},
Expand Down Expand Up @@ -182,6 +184,8 @@
"source": [
"What fraction of people live in the suburbs?\n",
"\n",
"Similar to above, this is the fraction of people who lived in the city and moved to the suburbs plus the fraction of people who live in the suburbs and stay in the suburbs.\n",
"\n",
"$p_{suburb,1}$ = 0.05 * 0.6 + 0.97 * 0.4"
]
},
Expand Down Expand Up @@ -313,7 +317,7 @@
}
],
"source": [
"# three steps all at once by taking our Pmarkov matrix to the 3rd power, then multipying by our original populaiton percentage vector\n",
"# three steps all at once by taking our Pmarkov matrix to the 3rd power, then multipying by our original population percentage vector\n",
"percent3 = np.dot(percent0, np.linalg.matrix_power(Pmarkov,3))\n",
"print(percent3)\n",
"\n",
Expand Down Expand Up @@ -543,7 +547,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 22,
"metadata": {},
"outputs": [
{
Expand All @@ -560,7 +564,7 @@
],
"source": [
"# This counts the transitions from each state to the next and marks that count\n",
"S = sparse.csr_matrix((np.ones_like(data[:-1]), (data[:-1], data[1:])), dtype=np.float)\n",
"S = sparse.csr_matrix((np.ones_like(data[:-1]), (data[:-1], data[1:])), dtype=float)\n",
"\n",
"# This converts those counts to matrix form\n",
"tm = S.todense()\n",
Expand Down Expand Up @@ -704,7 +708,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.8.12"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit ae0a8d5

Please sign in to comment.