Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Revert "Updated Ch5 to Python3"
This reverts commit d661e63.
  • Loading branch information
mmargenot committed Sep 20, 2016
commit fae5ebdb1fb4d5678ce76a1d49d76ea20caae232
238 changes: 120 additions & 118 deletions Chapter5_LossFunctions/Chapter5.ipynb

Large diffs are not rendered by default.

27 changes: 14 additions & 13 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 range(num_halos): #loop through all the true halos with the
for j in xrange(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 range(n):
for i in xrange(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 range(nhalo):
for i in xrange(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,9 +316,10 @@ 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 @@ -330,7 +331,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 @@ -341,7 +342,7 @@ def main(user_fname, fname):

x_predicted=np.array([],dtype=float)
y_predicted=np.array([],dtype=float)
for i in range(nhalo):
for i in xrange(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 @@ -408,9 +409,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
4 changes: 2 additions & 2 deletions Chapter5_LossFunctions/draw_sky2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
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 range(n):
for i in xrange(n):
_g = galaxies[i,:]
x,y = _g[0], _g[1]
d = np.sqrt( _g[2]**2 + _g[3]**2 )
Expand Down