Skip to content

Commit

Permalink
auto commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispiech committed Oct 31, 2023
1 parent 60b7a55 commit 63baca5
Show file tree
Hide file tree
Showing 87 changed files with 182 additions and 67 deletions.
Binary file modified chapters/examples/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion chapters/part1/bayes_theorem/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
</p>

<p>A common scenario for applying the Bayes' Rule formula is when you want to know the probability of
something “unobservable” given an “observed” event. For example, you want to know the probability that a
something “unobservable” given an “observed” event! For example, you want to know the probability that a
student understands a concept, given that you observed them solving a particular problem. It turns out it is
much easier to first estimate the probability that a student can solve a problem given that they understand the
concept and then to apply Bayes' Theorem. Intuitively, you can think about this as updating a belief given
Expand Down
Binary file modified en/ProbabilityForComputerScientists.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion en/part1/bayes_theorem/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@
</p>

<p>A common scenario for applying the Bayes' Rule formula is when you want to know the probability of
something “unobservable” given an “observed” event. For example, you want to know the probability that a
something “unobservable” given an “observed” event! For example, you want to know the probability that a
student understands a concept, given that you observed them solving a particular problem. It turns out it is
much easier to first estimate the probability that a student can solve a problem given that they understand the
concept and then to apply Bayes' Theorem. Intuitively, you can think about this as updating a belief given
Expand Down
81 changes: 81 additions & 0 deletions print/hash_values.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"../en/intro/notation/index.html": "80ce2a0c31d5958062a9e36ee6778986",
"../en/intro/core_probability_ref/index.html": "40c849fe059aa68d3e46322d59e0b6ee",
"../en/intro/all_distributions/index.html": "3041852c774c3bf1855bb94aa96b7e5e",
"../en/intro/python/index.html": "ff192d5c8732ad219e111d3ef4bdc26e",
"../en/intro/calculators/index.html": "15ad7186354bc063b6926a3e26abc0d3",
"../en/part1/counting/index.html": "3050001946dede5ef354ba2583aec7cc",
"../en/part1/combinatorics/index.html": "980e8d6fd32d78749d18397334b01c05",
"../en/part1/probability/index.html": "98412776cf5aab1c729c9296d321ab1a",
"../en/part1/equally_likely/index.html": "48948dc08a21b4a59181fad6d84179bd",
"../en/part1/prob_or/index.html": "5446ea3bd04f6afb8225dc2e0869be5a",
"../en/part1/cond_prob/index.html": "e190909f054bea9c5520c826afa9a4ef",
"../en/part1/independence/index.html": "69809940c0504eab3d83a00335f0c17e",
"../en/part1/prob_and/index.html": "fca8896bbc25933676feb3add45215f2",
"../en/part1/law_total/index.html": "a347842034fb2f613577520245ea96be",
"../en/part1/bayes_theorem/index.html": "06bc8984b77561e5a492a12a473f09d6",
"../en/part1/log_probabilities/index.html": "30d664a90c840d89028138f2a15f9b20",
"../en/part1/many_flips/index.html": "ca9a6b1ace9bb33932b8b9df41d7c0d1",
"../en/part2/rvs/index.html": "0b0a02f4fd4d2eedb364067bb42a4017",
"../en/part2/pmf/index.html": "1df626ec09fc868d51eea50be9e323ef",
"../en/part2/expectation/index.html": "f5f3f086629632ec508f118f3904e7e0",
"../en/part2/variance/index.html": "9cdfbca1fe5ccdb2f1db2597f805fe55",
"../en/part2/bernoulli/index.html": "5d900a9189ee40704652dfc8a98829a6",
"../en/part2/binomial/index.html": "c1c48696b4bc3b5d227e625a97f3bfcd",
"../en/part2/poisson/index.html": "abfa2e2b3bc6036def132404f2fa5b80",
"../en/part2/continuous/index.html": "e6aab286a8ec3d1692dd7a20b06c30bd",
"../en/part2/uniform/index.html": "aef7728d4067430daf7ab845b47fb150",
"../en/part2/exponential/index.html": "293c9bf211ab18aaa97405d8563aebcb",
"../en/part2/normal/index.html": "104742361b8d1b301f65911533aeca17",
"../en/part2/binomial_approx/index.html": "fbc8904aa5fffd864d8b93522e581f2d",
"../en/part3/joint/index.html": "c4bf9a82dce0bff524aa4d346fb24630",
"../en/part3/multinomial/index.html": "4d1efa18cda9604eefd376e658700e65",
"../en/part3/continuous_joint/index.html": "a3d1582697d1498237279d1aef481090",
"../en/part3/inference/index.html": "a1a6b92f3f296d4a9ae824eafd6d8fdf",
"../en/part3/bayesian_networks/index.html": "ab652d1ca64d12553562a0a69cdedad0",
"../en/part3/independent_vars/index.html": "cb0e98b009940291baa2df472d9a5dfd",
"../en/part3/correlation/index.html": "28686b4e41b6a7455fcab09cf622685b",
"../en/part3/computational_inference/index.html": "e64e0329ce941690a3fa0010af0972bd",
"../en/part4/beta/index.html": "011f60d1b84968a61fcc383324fc1ab1",
"../en/part4/summation_vars/index.html": "e417c194a7db4c82256794e83de4e015",
"../en/part4/clt/index.html": "9acf281e179adb877faa125c6357b33f",
"../en/part4/samples/index.html": "447a1388c39b9dd30ef10439f31c6283",
"../en/part4/bootstrapping/index.html": "61ffde20ca6259d9498b772c81822bd3",
"../en/part4/algorithmic_analysis/index.html": "a144057c9e461828eb0810da20def509",
"../en/part5/parameter_estimation/index.html": "663a7b969e328c599284e681bb061cbb",
"../en/part5/mle/index.html": "ccf756bb2e6fb28115cbcae305439f69",
"../en/part5/map/index.html": "bd2ba4199c1cfe848feab49a79722938",
"../en/part5/machine_learning/index.html": "52d9f4d520e100b8d9cc9f09950c42ea",
"../en/part5/naive_bayes/index.html": "1f14ae36921d1613c1d573af95f51764",
"../en/part5/log_regression/index.html": "378d0f59da28c00a45d8753ecefbf3a9",
"../en/examples/enigma/index.html": "afd97e5dacb9ce1d5c99dc57413a30a4",
"../en/examples/serendipity/index.html": "7ed5e95e76e022f73301508dedc50e3b",
"../en/examples/random_shuffles/index.html": "9af14913ec75f347f8dacff9bc7502de",
"../en/examples/counting_graphs/index.html": "17e2d92a722d3f352adfa5de066bf9c8",
"../en/examples/bacteria_evolution/index.html": "c0e54908b2e3b953a470db76bbab97d5",
"../en/examples/100_binomial_problems/index.html": "931319539da54851ed9776edd0b36f65",
"../en/examples/winning_series/index.html": "e2fdec78561e68b51b4369ab235cb4b8",
"../en/examples/approximate_counting/index.html": "a8435db01dfb766177412971de483fb6",
"../en/examples/jury/index.html": "c23c32d6ec53946077ad41821d40275f",
"../en/examples/prob_baby_delivery/index.html": "43b5904dcb4a64344f203053fdd72736",
"../en/examples/grading_eye_inflammation/index.html": "57eefdc10ed61dc20ea115e9856bd1f5",
"../en/examples/grades_not_normal/index.html": "aeb3700aaf5cdb90d9373b258ffbaa18",
"../en/examples/curse_of_dimensionality/index.html": "ec7d406a6878fca840f8d842eb0f950b",
"../en/examples/algorithmic_art/index.html": "151ae1632171939057b639f8de6cc339",
"../en/examples/fairness/index.html": "81c8368b171eba43521024aa7e5b9a40",
"../en/examples/federalist/index.html": "a04081aab1d7fd3775f00c128387449c",
"../en/examples/name2age/index.html": "2d8018282c547cc510e59c3df2175185",
"../en/examples/bayesian_carbon_dating/index.html": "b0e770ebeb3cdeabfd4f0d2b6e07949b",
"../en/examples/digital_vision_test/index.html": "4984c76554fcff2a38a6bda8d17c06c3",
"../en/examples/bridge_distribution/index.html": "3d4e0500b2f49a5bcd5aa3a06c2a2220",
"../en/examples/bayesian_viral_load_test/index.html": "5484a94acadef7ae6dc20a09e468135e",
"../en/examples/dart_logo/index.html": "c140d81c37f03ca7e26d07a3d8467e48",
"../en/examples/tracking_in_2D/index.html": "fbc47eeb24db26e94586cdd95313710d",
"../en/examples/thompson/index.html": "d79bc3b51a6cde0dc97eaff6b9513867",
"../en/examples/night_sight/index.html": "9b37b6c30e195ac54af6053085b978dd",
"../en/examples/p_hacking/index.html": "8b1141fa7ac25b4fbdfca46ef604c556",
"../en/examples/differential_privacy/index.html": "4cfb8805a4bb42d908aaaf9efe179ef2",
"../en/examples/mle_demo/index.html": "b26b666d3b7124cbedc81cbd819c6c99",
"../en/examples/mle_pareto/index.html": "408438fe6a9a56c890605636eaf46fce",
"../en/examples/mixture_models/index.html": "55f6390b3ce3ed1c1846af3f887a6129"
}
Binary file modified print/pdfs/100_binomial_problems.pdf
Binary file not shown.
Binary file modified print/pdfs/algorithmic_analysis.pdf
Binary file not shown.
Binary file added print/pdfs/algorithmic_art.pdf
Binary file not shown.
Binary file modified print/pdfs/all_distributions.pdf
Binary file not shown.
Binary file added print/pdfs/approximate_counting.pdf
Binary file not shown.
Binary file modified print/pdfs/bacteria_evolution.pdf
Binary file not shown.
Binary file modified print/pdfs/bayes_theorem.pdf
Binary file not shown.
Binary file modified print/pdfs/bayesian_carbon_dating.pdf
Binary file not shown.
Binary file modified print/pdfs/bayesian_networks.pdf
Binary file not shown.
Binary file added print/pdfs/bayesian_viral_load_test.pdf
Binary file not shown.
Binary file modified print/pdfs/bernoulli.pdf
Binary file not shown.
Binary file modified print/pdfs/beta.pdf
Binary file not shown.
Binary file modified print/pdfs/binomial.pdf
Binary file not shown.
Binary file modified print/pdfs/binomial_approx.pdf
Binary file not shown.
Binary file modified print/pdfs/bootstrapping.pdf
Binary file not shown.
Binary file modified print/pdfs/bridge_distribution.pdf
Binary file not shown.
Binary file modified print/pdfs/calculators.pdf
Binary file not shown.
Binary file modified print/pdfs/clt.pdf
Binary file not shown.
Binary file modified print/pdfs/combinatorics.pdf
Binary file not shown.
Binary file modified print/pdfs/computational_inference.pdf
Binary file not shown.
Binary file modified print/pdfs/cond_prob.pdf
Binary file not shown.
Binary file modified print/pdfs/continuous.pdf
Binary file not shown.
Binary file modified print/pdfs/continuous_joint.pdf
Binary file not shown.
Binary file modified print/pdfs/core_probability_ref.pdf
Binary file not shown.
Binary file modified print/pdfs/correlation.pdf
Binary file not shown.
Binary file modified print/pdfs/counting.pdf
Binary file not shown.
Binary file added print/pdfs/counting_graphs.pdf
Binary file not shown.
Binary file modified print/pdfs/curse_of_dimensionality.pdf
Binary file not shown.
Binary file modified print/pdfs/dart_logo.pdf
Binary file not shown.
Binary file modified print/pdfs/differential_privacy.pdf
Binary file not shown.
Binary file modified print/pdfs/digital_vision_test.pdf
Binary file not shown.
Binary file modified print/pdfs/enigma.pdf
Binary file not shown.
Binary file modified print/pdfs/equally_likely.pdf
Binary file not shown.
Binary file modified print/pdfs/expectation.pdf
Binary file not shown.
Binary file modified print/pdfs/exponential.pdf
Binary file not shown.
Binary file modified print/pdfs/fairness.pdf
Binary file not shown.
Binary file modified print/pdfs/federalist.pdf
Binary file not shown.
Binary file modified print/pdfs/grades_not_normal.pdf
Binary file not shown.
Binary file modified print/pdfs/grading_eye_inflammation.pdf
Binary file not shown.
Binary file modified print/pdfs/independence.pdf
Binary file not shown.
Binary file modified print/pdfs/independent_vars.pdf
Binary file not shown.
Binary file modified print/pdfs/inference.pdf
Binary file not shown.
Binary file modified print/pdfs/joint.pdf
Binary file not shown.
Binary file modified print/pdfs/jury.pdf
Binary file not shown.
Binary file modified print/pdfs/law_total.pdf
Binary file not shown.
Binary file modified print/pdfs/log_probabilities.pdf
Binary file not shown.
Binary file modified print/pdfs/log_regression.pdf
Binary file not shown.
Binary file modified print/pdfs/machine_learning.pdf
Binary file not shown.
Binary file modified print/pdfs/many_flips.pdf
Binary file not shown.
Binary file modified print/pdfs/map.pdf
Binary file not shown.
Binary file modified print/pdfs/mixture_models.pdf
Binary file not shown.
Binary file modified print/pdfs/mle.pdf
Binary file not shown.
Binary file modified print/pdfs/mle_demo.pdf
Binary file not shown.
Binary file modified print/pdfs/mle_pareto.pdf
Binary file not shown.
Binary file modified print/pdfs/multinomial.pdf
Binary file not shown.
Binary file modified print/pdfs/naive_bayes.pdf
Binary file not shown.
Binary file modified print/pdfs/name2age.pdf
Binary file not shown.
Binary file modified print/pdfs/night_sight.pdf
Binary file not shown.
Binary file modified print/pdfs/normal.pdf
Binary file not shown.
Binary file modified print/pdfs/notation.pdf
Binary file not shown.
Binary file modified print/pdfs/p_hacking.pdf
Binary file not shown.
Binary file modified print/pdfs/parameter_estimation.pdf
Binary file not shown.
Binary file modified print/pdfs/pmf.pdf
Binary file not shown.
Binary file modified print/pdfs/poisson.pdf
Binary file not shown.
Binary file modified print/pdfs/prob_and.pdf
Binary file not shown.
Binary file modified print/pdfs/prob_baby_delivery.pdf
Binary file not shown.
Binary file modified print/pdfs/prob_or.pdf
Binary file not shown.
Binary file modified print/pdfs/probability.pdf
Binary file not shown.
Binary file modified print/pdfs/python.pdf
Binary file not shown.
Binary file modified print/pdfs/random_shuffles.pdf
Binary file not shown.
Binary file modified print/pdfs/rvs.pdf
Binary file not shown.
Binary file modified print/pdfs/samples.pdf
Binary file not shown.
Binary file modified print/pdfs/serendipity.pdf
Binary file not shown.
Binary file modified print/pdfs/summation_vars.pdf
Binary file not shown.
Binary file modified print/pdfs/thompson.pdf
Binary file not shown.
Binary file modified print/pdfs/titlepage.pdf
Binary file not shown.
Binary file modified print/pdfs/tracking_in_2D.pdf
Binary file not shown.
Binary file modified print/pdfs/uniform.pdf
Binary file not shown.
Binary file modified print/pdfs/variance.pdf
Binary file not shown.
Binary file modified print/pdfs/winning_series.pdf
Binary file not shown.
162 changes: 98 additions & 64 deletions print/printbook.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import hjson
import json
import PyPDF2
import pdfgenerator
import re
import os
from tqdm import tqdm
import hashlib

# def create_pdfs():

# Opening JSON file
f = open("../bookOutline.hjson")
# returns JSON object as a dictionary
Expand All @@ -31,77 +33,109 @@

# get pdf_name and pdf_link for book from bookOutline and store in pdf_files
pdf_files = {}
# load the hash values
# if the file does not exist, hash_values is {}
if not os.path.exists('hash_values.json'):
hash_values = {}
else:
hash_values = json.load(open('hash_values.json', 'r'))

def print_page(part, page):
pdf_name = page + '.pdf'
pdf_link = base + part + '/' + page
file_link = f'../en/{part}/{page}/index.html'
raw_file_html = open(file_link, 'r').read()
hash = compute_md5(raw_file_html)
if file_link in hash_values.keys() and hash_values[file_link] == hash:
return
# store pdf_name and title
# generate pdf file
print(pdf_link)
pdf_file = pdfgenerator.PdfGenerator([pdf_link]).main()
# save pdf to file
with open(os.path.join('pdfs', pdf_name), "wb") as outfile:
outfile.write(pdf_file[0].getbuffer())
save_hash_value(hash, file_link)

for part in tqdm(data, desc="Outer Loop"):
pdf_files[part] = {'sections':{}}
for page in data[part]['sections']:
title = data[part]['sections'][page]
pdf_name = page + '.pdf'
pdf_link = base + part + '/' + page
# store pdf_name and title
pdf_files[part]['sections'][pdf_name] = title
# generate pdf file
pdf_file = pdfgenerator.PdfGenerator([pdf_link]).main()
# save pdf to file
with open(os.path.join('pdfs', pdf_name), "wb") as outfile:
outfile.write(pdf_file[0].getbuffer())
# print(pdf_name)
if 'examples' in data[part].keys():
pdf_files[part]['examples'] = {}
for page in data[part]['examples']:
title = data[part]['examples'][page]
def print_book():
for part in tqdm(data, desc="Sections"):
pdf_files[part] = {'sections':{}}
for page in data[part]['sections']:
print_page(part, page)

# save for table of contents
title = data[part]['sections'][page]
pdf_name = page + '.pdf'
pdf_link = base + 'examples' + '/' + page
# store pdf_name and title
pdf_files[part]['examples'][pdf_name] = title
# generate pdf file
pdf_file = pdfgenerator.PdfGenerator([pdf_link]).main()
# save pdf to file
with open(os.path.join('pdfs', pdf_name), "wb") as outfile:
outfile.write(pdf_file[0].getbuffer())
# print(pdf_name)

# Output PDF file name
output_pdf = "../en/ProbabilityForComputerScientists.pdf"

# Create a PDF file writer object
pdf_writer = PyPDF2.PdfWriter()

# add title page
pdf_writer.append(os.path.join('pdfs', title_name))

page_num = 1
for part in pdf_files:
title = data[part]['title']
if title is None:
title = "Introduction"
# create outline for parts
part_outline = pdf_writer.add_outline_item(title, page_num)
# add pdf files to table of contents and book
for pdf_file, title in pdf_files[part]['sections'].items():
# Open the pdf
pdf_reader = PyPDF2.PdfReader(open(os.path.join('pdfs', pdf_file), "rb"))
# Create an outline item for the pdf
pdf_outline = pdf_writer.add_outline_item(title, page_num, parent=part_outline)
# add pdf file to book pdf
pdf_writer.append(os.path.join('pdfs', pdf_file))
# start of next pdf
page_num += len(pdf_reader.pages)
if 'examples' in pdf_files[part].keys():
# create outline for examples
examples_outline = pdf_writer.add_outline_item('Applications', page_num, parent=part_outline)
pdf_files[part]['sections'][pdf_name] = title
if 'examples' in data[part].keys():
pdf_files[part]['examples'] = {}
for page in data[part]['examples']:
print_page('examples', page)

# save for table of contents
title = data[part]['examples'][page]
pdf_name = page + '.pdf'
pdf_files[part]['examples'][pdf_name] = title


# Output PDF file name
output_pdf = "../en/ProbabilityForComputerScientists.pdf"

# Create a PDF file writer object
pdf_writer = PyPDF2.PdfWriter()

# add title page
pdf_writer.append(os.path.join('pdfs', title_name))

page_num = 1
for part in pdf_files:
title = data[part]['title']
if title is None:
title = "Introduction"
# create outline for parts
part_outline = pdf_writer.add_outline_item(title, page_num)
# add pdf files to table of contents and book
for pdf_file, title in pdf_files[part]['examples'].items():
for pdf_file, title in pdf_files[part]['sections'].items():
# Open the pdf
pdf_reader = PyPDF2.PdfReader(open(os.path.join('pdfs', pdf_file), "rb"))
# Create an outline item for the pdf
pdf_outline = pdf_writer.add_outline_item(title, page_num, parent=examples_outline)
pdf_outline = pdf_writer.add_outline_item(title, page_num, parent=part_outline)
# add pdf file to book pdf
pdf_writer.append(os.path.join('pdfs', pdf_file))
# start of next pdf
page_num += len(pdf_reader.pages)
if 'examples' in pdf_files[part].keys():
# create outline for examples
examples_outline = pdf_writer.add_outline_item('Applications', page_num, parent=part_outline)
# add pdf files to table of contents and book
for pdf_file, title in pdf_files[part]['examples'].items():
# Open the pdf
pdf_reader = PyPDF2.PdfReader(open(os.path.join('pdfs', pdf_file), "rb"))
# Create an outline item for the pdf
pdf_outline = pdf_writer.add_outline_item(title, page_num, parent=examples_outline)
pdf_writer.append(os.path.join('pdfs', pdf_file))
# start of next pdf
page_num += len(pdf_reader.pages)

# Save the merged PDF with the TOC
with open(output_pdf, "wb") as output_file:
pdf_writer.write(output_file)

print(f"Merged PDF with Table of Contents saved as {output_pdf}")

def save_hash_value(hash, file_link):

# store the hash value
hash_values[file_link] = hash

# save the hash values to json
with open('hash_values.json', 'w') as fp:
json.dump(hash_values, fp, indent=4)

# Save the merged PDF with the TOC
with open(output_pdf, "wb") as output_file:
pdf_writer.write(output_file)
def compute_md5(text):
m = hashlib.md5()
m.update(text.encode('utf-8'))
return m.hexdigest()

print(f"Merged PDF with Table of Contents saved as {output_pdf}")
if __name__ == "__main__":
print_book()
2 changes: 1 addition & 1 deletion searchIndex.json

Large diffs are not rendered by default.

0 comments on commit 63baca5

Please sign in to comment.