Skip to content

Commit fae5ebd

Browse files
committed
Revert "Updated Ch5 to Python3"
This reverts commit d661e63.
1 parent e956329 commit fae5ebd

File tree

3 files changed

+136
-133
lines changed

3 files changed

+136
-133
lines changed

Chapter5_LossFunctions/Chapter5.ipynb

Lines changed: 120 additions & 118 deletions
Large diffs are not rendered by default.

Chapter5_LossFunctions/DarkWorldsMetric.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def calc_delta_r(x_predicted,y_predicted,x_true,y_true):
5858
for perm in it.permutations(a[num_halos-2],num_halos):
5959
which_true_halos=[]
6060
which_predicted_halos=[]
61-
for j in range(num_halos): #loop through all the true halos with the
61+
for j in xrange(num_halos): #loop through all the true halos with the
6262

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

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

279279

@@ -316,9 +316,10 @@ def main(user_fname, fname):
316316
#first input would be
317317
#a float, if succeed it
318318
#is not a header
319-
print('THE INPUT FILE DOES NOT APPEAR TO HAVE A HEADER')
319+
print 'THE INPUT FILE DOES NOT APPEAR TO HAVE A HEADER'
320320
except :
321-
print('THE INPUT FILE APPEARS TO HAVE A HEADER, SKIPPING THE FIRST LINE')
321+
print 'THE INPUT FILE APPEARS TO HAVE A HEADER, SKIPPING THE FIRST LINE'
322+
322323
skip_header = sky_prediction.next()
323324

324325

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

336337

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

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

415416

416417
if __name__ == "__main__":

Chapter5_LossFunctions/draw_sky2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
from matplotlib.patches import Ellipse
33
import numpy as np
44

5-
def draw_sky(galaxies):
5+
def draw_sky( galaxies ):
66
"""adapted from Vishal Goklani"""
77
size_multiplier = 45
88
fig = plt.figure(figsize=(10,10))
99
#fig.patch.set_facecolor("blue")
1010
ax = fig.add_subplot(111, aspect='equal')
1111
n = galaxies.shape[0]
12-
for i in range(n):
12+
for i in xrange(n):
1313
_g = galaxies[i,:]
1414
x,y = _g[0], _g[1]
1515
d = np.sqrt( _g[2]**2 + _g[3]**2 )

0 commit comments

Comments
 (0)