Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
321abed
Updated Ch1 to use Python3
mmargenot Sep 12, 2016
5d3487a
Updated Ch2 to use Python3
mmargenot Sep 12, 2016
45323f8
Updated Ch3 to use Python3
mmargenot Sep 16, 2016
61767bc
Updated Ch4 to Python3, updated reddit example
mmargenot Sep 16, 2016
d661e63
Updated Ch5 to Python3
mmargenot Sep 16, 2016
e956329
Updated Ch6 to Python3
mmargenot Sep 20, 2016
fae5ebd
Revert "Updated Ch5 to Python3"
mmargenot Sep 20, 2016
3c2a5db
Revert "Updated Ch6 to Python3"
mmargenot Sep 20, 2016
d07d42b
Re-updated Ch5 and Ch6 to Python3
mmargenot Sep 20, 2016
f92a79b
Merge pull request #9 from quantopian/python3-update
mmargenot Sep 20, 2016
76dfa8c
Combined pymc2/pymc3 Ch1
mmargenot Sep 26, 2016
a517f32
Changed file conventions
mmargenot Sep 26, 2016
f055688
Combined pymc2/pymc3 Ch2
mmargenot Sep 26, 2016
a84b808
Combined pymc2/pymc3 Ch3
mmargenot Sep 26, 2016
0ec8e76
Combined pymc2/pymc3 Ch4
mmargenot Sep 26, 2016
4e36149
Combined pymc2/pymc3 Ch5
mmargenot Sep 26, 2016
d89757b
Combined pymc2/pymc3 Ch6
mmargenot Sep 26, 2016
23414c6
Changed naming convention again
mmargenot Sep 26, 2016
4a9b564
Merge pull request #11 from quantopian/combine-pymc2-pymc3
twiecki Sep 26, 2016
833391e
Updated positional arguments in keeping with PyMC3 changes for Ch2
mmargenot Sep 28, 2016
cd3de59
Updated positional arguments in keeping with PyMC3 changes for Ch3
mmargenot Sep 28, 2016
383ada9
Updated positional arguments in keeping with PyMC3 changes for Ch5
mmargenot Sep 28, 2016
f70149b
Updated positional arguments in keeping with PyMC3 changes for Ch6
mmargenot Sep 28, 2016
dcce3fb
Merge pull request #12 from quantopian/update-positional-arguments-pymc3
mmargenot Sep 28, 2016
e3f5a17
Corrected Cam's name
mmargenot Sep 29, 2016
0c1e084
Merge pull request #13 from quantopian/attribution-correction
mmargenot Sep 29, 2016
48f0b44
Removed unnecessary code comments from scipts
mmargenot Sep 29, 2016
027aa62
Caught one last straggler
mmargenot Sep 29, 2016
e4f7a72
Merge pull request #14 from quantopian/remove-unnecessary-comments
mmargenot Sep 29, 2016
601ed55
Changed style for Ch1 plots
mmargenot Sep 29, 2016
1f0535b
Changed style for Ch3 plots
mmargenot Sep 29, 2016
6537890
Changed style for Ch2 plots
mmargenot Sep 29, 2016
ec2cafc
Changed style for Ch5 plots
mmargenot Sep 29, 2016
9743714
Changed style for Ch6 PyMC3 plots and removed style code from Ch2 and…
mmargenot Sep 29, 2016
fe34bea
Changed style for Ch4 plots, changed subreddit example to showerthoughts
mmargenot Sep 29, 2016
4131e4c
Removed style code from Ch4 PyMC2
mmargenot Sep 29, 2016
d8215d8
Merge pull request #15 from quantopian/pretty-plots
mmargenot Sep 29, 2016
cf3ca13
Reword explanation of model binding in a context
jbn Oct 1, 2016
56c1fc8
Merge pull request #16 from jbn/master
mmargenot Oct 3, 2016
a1b90c2
Modified rewording of model binding text to be more in line with the …
mmargenot Oct 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,135 changes: 1,135 additions & 0 deletions Chapter1_Introduction/Ch1_Introduction_PyMC2.ipynb

Large diffs are not rendered by default.

1,068 changes: 1,068 additions & 0 deletions Chapter1_Introduction/Ch1_Introduction_PyMC3.ipynb

Large diffs are not rendered by default.

1,134 changes: 0 additions & 1,134 deletions Chapter1_Introduction/Chapter1.ipynb

This file was deleted.

2,515 changes: 2,515 additions & 0 deletions Chapter2_MorePyMC/Ch2_MorePyMC_PyMC2.ipynb

Large diffs are not rendered by default.

2,580 changes: 2,580 additions & 0 deletions Chapter2_MorePyMC/Ch2_MorePyMC_PyMC3.ipynb

Large diffs are not rendered by default.

2,643 changes: 0 additions & 2,643 deletions Chapter2_MorePyMC/Chapter2.ipynb

This file was deleted.

5 changes: 1 addition & 4 deletions Chapter2_MorePyMC/separation_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ def separation_plot( p, y, **kwargs ):
p = p.reshape( n, 1 )
M = p.shape[1]

#colors = np.array( ["#fdf2db", "#e44a32"] )
colors_bmh = np.array( ["#eeeeee", "#348ABD"] )


fig = plt.figure( )#figsize = (8, 1.3*M) )
fig = plt.figure( )

for i in range(M):
ax = fig.add_subplot(M, 1, i+1)
Expand All @@ -43,8 +42,6 @@ def separation_plot( p, y, **kwargs ):
linewidth = 1.,drawstyle="steps-post" )
#create expected value bar.
ax.vlines( [(1-p[ix,i]).sum()], [0], [1] )
#ax.grid(False)
#ax.axis('off')
plt.xlim( 0, n)

plt.tight_layout()
Expand Down
1,413 changes: 1,413 additions & 0 deletions Chapter3_MCMC/Ch3_IntroMCMC_PyMC2.ipynb

Large diffs are not rendered by default.

1,325 changes: 1,325 additions & 0 deletions Chapter3_MCMC/Ch3_IntroMCMC_PyMC3.ipynb

Large diffs are not rendered by default.

1,460 changes: 0 additions & 1,460 deletions Chapter3_MCMC/Chapter3.ipynb

This file was deleted.

1,204 changes: 1,204 additions & 0 deletions Chapter4_TheGreatestTheoremNeverTold/Ch4_LawOfLargeNumbers_PyMC2.ipynb

Large diffs are not rendered by default.

1,199 changes: 1,199 additions & 0 deletions Chapter4_TheGreatestTheoremNeverTold/Ch4_LawOfLargeNumbers_PyMC3.ipynb

Large diffs are not rendered by default.

1,226 changes: 0 additions & 1,226 deletions Chapter4_TheGreatestTheoremNeverTold/Chapter4.ipynb

This file was deleted.

63 changes: 0 additions & 63 deletions Chapter4_TheGreatestTheoremNeverTold/top_pic_comments.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys

import numpy as np
from IPython.core.display import Image

import praw


reddit = praw.Reddit("BayesianMethodsForHackers")
subreddit = reddit.get_subreddit("showerthoughts")

top_submissions = subreddit.get_top(limit=100)

n_sub = int( sys.argv[1] ) if sys.argv[1] else 1

i = 0
while i < n_sub:
top_submission = next(top_submissions)
i+=1

top_post = top_submission.title

upvotes = []
downvotes = []
contents = []

for sub in top_submissions:
try:
ratio = reddit.get_submission(sub.permalink).upvote_ratio
ups = int(round((ratio*sub.score)/(2*ratio - 1)) if ratio != 0.5 else round(sub.score/2))
upvotes.append(ups)
downvotes.append(ups - sub.score)
contents.append(sub.title)
except Exception as e:
continue
votes = np.array( [ upvotes, downvotes] ).T
1,481 changes: 1,481 additions & 0 deletions Chapter5_LossFunctions/Ch5_LossFunctions_PyMC2.ipynb

Large diffs are not rendered by default.

1,537 changes: 1,537 additions & 0 deletions Chapter5_LossFunctions/Ch5_LossFunctions_PyMC3.ipynb

Large diffs are not rendered by default.

1,482 changes: 0 additions & 1,482 deletions Chapter5_LossFunctions/Chapter5.ipynb

This file was deleted.

27 changes: 13 additions & 14 deletions Chapter5_LossFunctions/DarkWorldsMetric.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def calc_delta_r(x_predicted,y_predicted,x_true,y_true):
for perm in it.permutations(a[num_halos-2],num_halos):
which_true_halos=[]
which_predicted_halos=[]
for j in xrange(num_halos): #loop through all the true halos with the
for j in range(num_halos): #loop through all the true halos with the

distances_perm[count,j]=np.sqrt((x_true[j]-x_predicted[int(perm[j])])**2\
+(y_true[j]-y_predicted[int(perm[j])])**2)
Expand Down Expand Up @@ -141,7 +141,7 @@ def convert_to_360(angle, x_in, y_in):
theta: the angle in the range 0:2pi
"""
n = len(x_in)
for i in xrange(n):
for i in range(n):
if x_in[i] < 0 and y_in[i] > 0:
angle[i] = angle[i]+mt.pi
elif x_in[i] < 0 and y_in[i] < 0:
Expand Down Expand Up @@ -204,7 +204,7 @@ def main_score( nhalo_all, x_true_all, y_true_all, x_ref_all, y_ref_all, sky_pre

x_predicted=np.array([],dtype=float)
y_predicted=np.array([],dtype=float)
for i in xrange(nhalo):
for i in range(nhalo):
x_predicted=np.append(x_predicted,float(sky[0])) #get the predicted values
y_predicted=np.append(y_predicted,float(sky[1]))
#The solution file for the test data provides masses
Expand Down Expand Up @@ -271,9 +271,9 @@ def main_score( nhalo_all, x_true_all, y_true_all, x_ref_all, y_ref_all, sky_pre
W1=1./1000. #Weight the av_r such that < 1 is a good score > 1 is not so good.
W2=1.
metric = W1*av_r + W2*angle_vec #Weighted metric, weights TBD
print 'Your average distance in pixels you are away from the true halo is', av_r
print 'Your average angular vector is', angle_vec
print 'Your score for the training data is', metric
print('Your average distance in pixels you are away from the true halo is', av_r)
print('Your average angular vector is', angle_vec)
print('Your score for the training data is', metric)
return metric


Expand Down Expand Up @@ -316,10 +316,9 @@ def main(user_fname, fname):
#first input would be
#a float, if succeed it
#is not a header
print 'THE INPUT FILE DOES NOT APPEAR TO HAVE A HEADER'
print('THE INPUT FILE DOES NOT APPEAR TO HAVE A HEADER')
except :
print 'THE INPUT FILE APPEARS TO HAVE A HEADER, SKIPPING THE FIRST LINE'

print('THE INPUT FILE APPEARS TO HAVE A HEADER, SKIPPING THE FIRST LINE')
skip_header = sky_prediction.next()


Expand All @@ -331,7 +330,7 @@ def main(user_fname, fname):
if does_it_exist > 0: #If it does then find the matching solutions to the sky_id
selectskyinsolutions=true_sky_id.index(sky_id)-1
else: #Otherwise exit
print 'Sky_id does not exist, formatting problem: ',sky_id
print('Sky_id does not exist, formatting problem: ',sky_id)
sys.exit(2)


Expand All @@ -342,7 +341,7 @@ def main(user_fname, fname):

x_predicted=np.array([],dtype=float)
y_predicted=np.array([],dtype=float)
for i in xrange(nhalo):
for i in range(nhalo):
x_predicted=np.append(x_predicted,float(sky[2*i+1])) #get the predicted values
y_predicted=np.append(y_predicted,float(sky[2*i+2]))
#The solution file for the test data provides masses
Expand Down Expand Up @@ -409,9 +408,9 @@ def main(user_fname, fname):
W1=1./1000. #Weight the av_r such that < 1 is a good score > 1 is not so good.
W2=1.
metric = W1*av_r + W2*angle_vec #Weighted metric, weights TBD
print 'Your average distance in pixels you are away from the true halo is', av_r
print 'Your average angular vector is', angle_vec
print 'Your score for the training data is', metric
print('Your average distance in pixels you are away from the true halo is', av_r)
print('Your average angular vector is', angle_vec)
print('Your score for the training data is', metric)


if __name__ == "__main__":
Expand Down
5 changes: 2 additions & 3 deletions Chapter5_LossFunctions/draw_sky2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
from matplotlib.patches import Ellipse
import numpy as np

def draw_sky( galaxies ):
def draw_sky(galaxies):
"""adapted from Vishal Goklani"""
size_multiplier = 45
fig = plt.figure(figsize=(10,10))
#fig.patch.set_facecolor("blue")
ax = fig.add_subplot(111, aspect='equal')
n = galaxies.shape[0]
for i in xrange(n):
for i in range(n):
_g = galaxies[i,:]
x,y = _g[0], _g[1]
d = np.sqrt( _g[2]**2 + _g[3]**2 )
Expand Down
Loading