Skip to content

Commit

Permalink
Replace print with print()
Browse files Browse the repository at this point in the history
  • Loading branch information
sakurai committed Apr 20, 2017
1 parent 120b5b6 commit e477e94
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 62 deletions.
4 changes: 2 additions & 2 deletions clustering_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,5 @@ def clustering_loss(x, t, gamma, T=5):

with contexttimer.Timer() as timer:
loss = clustering_loss(_x, _c, gamma)
print timer.elapsed, ' [s]'
print 'loss:', loss.data
print(timer.elapsed, ' [s]')
print('loss:', loss.data)
2 changes: 1 addition & 1 deletion datasets/cars196_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

with contextlib.closing(request.urlopen(url)) as f:
expected_filesize = int(f.headers["content-length"])
print expected_filesize
print(expected_filesize)
time.sleep(5)

widgets = ['{}: '.format(filename), Percentage(), ' ', Bar(), ' ', ETA(),
Expand Down
2 changes: 1 addition & 1 deletion datasets/cub200_2011_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

with contextlib.closing(request.urlopen(url)) as f:
expected_filesize = int(f.headers["content-length"])
print expected_filesize
print(expected_filesize)
time.sleep(5)

widgets = ['{}: '.format(filename), Percentage(), ' ', Bar(), ' ', ETA(),
Expand Down
2 changes: 1 addition & 1 deletion datasets/online_products_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

with contextlib.closing(request.urlopen(url)) as f:
expected_filesize = int(f.headers["content-length"])
print expected_filesize
print(expected_filesize)
time.sleep(5)

widgets = ['{}: '.format(filename), Percentage(), ' ', Bar(), ' ', ETA(),
Expand Down
30 changes: 15 additions & 15 deletions evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ def ap_cluster_k(x, K, preference_init=-1.0, max_iter=30,
p = (p_lower + p_upper) / 2
ap = AffinityPropagation(preference=p).fit(y)
k_current = len(ap.cluster_centers_indices_)
print 'K = {}, k_current = {}, p = {}'.format(K, k_current, p)
print '{}:{}, {}:{}, {}:{}'.format(k_lower, p_lower, k_current, p,
k_upper, p_upper)
print('K = {}, k_current = {}, p = {}'.format(K, k_current, p))
print('{}:{}, {}:{}, {}:{}'.format(k_lower, p_lower, k_current, p,
k_upper, p_upper))

# if the current k goes out of bounds then retry with perturbed p
while k_current < k_lower or k_current > k_upper:
print "retry"
print("retry")
p += np.random.uniform(p_lower, p_upper) / 10
ap = AffinityPropagation(preference=p).fit(y)
k_current = len(ap.cluster_centers_indices_)
print 'K = {}, k_current = {}, p = {}'.format(K, k_current, p)
print '{}:{}, {}:{}, {}:{}'.format(k_lower, p_lower, k_current, p,
k_upper, p_upper)
print('K = {}, k_current = {}, p = {}'.format(K, k_current, p))
print('{}:{}, {}:{}, {}:{}'.format(k_lower, p_lower, k_current, p,
k_upper, p_upper))

if k_current < K:
p_lower = p
Expand All @@ -88,12 +88,12 @@ def ap_cluster_k(x, K, preference_init=-1.0, max_iter=30,
# Search further better preference in terms of NMI score by random search
p_best = p
score_best = normalized_mutual_info_score(c, ap.predict(y))
print 'initial score:', score_best
print
print('initial score:', score_best)
print()
for i in range(iter_finetune):
p = np.random.normal(p_best, (p_upper - p_lower) / 2)
if p < p_lower or p > p_upper: # where p is rejected
print 'reject'
print('reject')
continue
ap = AffinityPropagation(preference=p).fit(y)
k_current = len(ap.cluster_centers_indices_)
Expand All @@ -104,12 +104,12 @@ def ap_cluster_k(x, K, preference_init=-1.0, max_iter=30,
else: # wgere k_current is K
score = normalized_mutual_info_score(c, ap.predict(y))
if score > score_best:
print "update p {} -> {}". format(p_best, p)
print("update p {} -> {}".format(p_best, p))
p_best = p
score_best = score
print 'p: {}, {}, {}'.format(p_lower, p, p_upper)
print 'score: {}'.format(score_best)
print
print('p: {}, {}, {}'.format(p_lower, p, p_upper))
print('score: {}'.format(score_best))
print()
return AffinityPropagation(preference=p_best).fit(y)


Expand All @@ -132,7 +132,7 @@ def ap_cluster_k(x, K, preference_init=-1.0, max_iter=30,
ap = ap_cluster_k(y, K, preference_init=-1.0, c=c, iter_finetune=30)
c_pred = ap.predict(y)

print normalized_mutual_info_score(c, c_pred)
print(normalized_mutual_info_score(c, c_pred))
plt.plot(np.vstack((c_pred, c)).T)
plt.show()
# print f1_score(c, c_pred)
42 changes: 21 additions & 21 deletions main_clustering_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,23 @@ def main(param_dict):
logger.retrieval_best = retrieval
logger.retrieval_test_best = retrieval_test

print "#", epoch
print "time: {} ({})".format(epoch_time, total_time)
print "[train] loss:", loss_average
print "[train] soft:", soft
print "[train] hard:", hard
print "[train] retr:", retrieval
print "[test] soft:", soft_test
print "[test] hard:", hard_test
print "[test] retr:", retrieval_test
print "[best] soft: {} (at # {})".format(logger.soft_test_best,
logger.epoch_best)
print p, 'gamma:{}'.format(gamma)
print("#", epoch)
print("time: {} ({})".format(epoch_time, total_time))
print("[train] loss:", loss_average)
print("[train] soft:", soft)
print("[train] hard:", hard)
print("[train] retr:", retrieval)
print("[test] soft:", soft_test)
print("[test] hard:", hard_test)
print("[test] retr:", retrieval_test)
print("[best] soft: {} (at # {})".format(logger.soft_test_best,
logger.epoch_best))
print(p, 'gamma:{}'.format(gamma))
# print norms of the weights
params = xp.hstack([xp.linalg.norm(param.data)
for param in model.params()]).tolist()
print "|W|", map(lambda param: float('%0.2f' % param), params)
print
print("|W|", map(lambda param: float('%0.2f' % param), params))
print()

# Draw plots
plt.figure(figsize=(8, 4))
Expand Down Expand Up @@ -186,13 +186,13 @@ def main(param_dict):
logger.save(dir_name)
p.save(dir_name)

print "total epochs: {} ({} [s])".format(logger.epoch, logger.total_time)
print "best test score (at # {})".format(logger.epoch_best)
print "[test] soft:", logger.soft_test_best
print "[test] hard:", logger.hard_test_best
print "[test] retr:", logger.retrieval_test_best
print str(p).replace(', ', '\n')
print
print("total epochs: {} ({} [s])".format(logger.epoch, logger.total_time))
print("best test score (at # {})".format(logger.epoch_best))
print("[test] soft:", logger.soft_test_best)
print("[test] hard:", logger.hard_test_best)
print("[test] retr:", logger.retrieval_test_best)
print(str(p).replace(', ', '\n'))
print()


if __name__ == '__main__':
Expand Down
42 changes: 21 additions & 21 deletions main_lifted_struct_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,23 @@ def main(param_dict):
logger.retrieval_best = retrieval
logger.retrieval_test_best = retrieval_test

print "#", epoch
print "time: {} ({})".format(epoch_time, total_time)
print "[train] loss:", loss_average
print "[train] soft:", soft
print "[train] hard:", hard
print "[train] retr:", retrieval
print "[test] soft:", soft_test
print "[test] hard:", hard_test
print "[test] retr:", retrieval_test
print "[best] soft: {} (at # {})".format(logger.soft_test_best,
logger.epoch_best)
print p
print("#", epoch)
print("time: {} ({})".format(epoch_time, total_time))
print("[train] loss:", loss_average)
print("[train] soft:", soft)
print("[train] hard:", hard)
print("[train] retr:", retrieval)
print("[test] soft:", soft_test)
print("[test] hard:", hard_test)
print("[test] retr:", retrieval_test)
print("[best] soft: {} (at # {})".format(logger.soft_test_best,
logger.epoch_best))
print(p)
# print norms of the weights
params = xp.hstack([xp.linalg.norm(param.data)
for param in model.params()]).tolist()
print "|W|", map(lambda param: float('%0.2f' % param), params)
print
print("|W|", map(lambda param: float('%0.2f' % param), params))
print()

# Draw plots
plt.figure(figsize=(8, 4))
Expand Down Expand Up @@ -184,13 +184,13 @@ def main(param_dict):
logger.save(dir_name)
p.save(dir_name)

print "total epochs: {} ({} [s])".format(logger.epoch, logger.total_time)
print "best test score (at # {})".format(logger.epoch_best)
print "[test] soft:", logger.soft_test_best
print "[test] hard:", logger.hard_test_best
print "[test] retr:", logger.retrieval_test_best
print str(p).replace(', ', '\n')
print
print("total epochs: {} ({} [s])".format(logger.epoch, logger.total_time))
print("best test score (at # {})".format(logger.epoch_best))
print("[test] soft:", logger.soft_test_best)
print("[test] hard:", logger.hard_test_best)
print("[test] retr:", logger.retrieval_test_best)
print(str(p).replace(', ', '\n'))
print()


if __name__ == '__main__':
Expand Down

0 comments on commit e477e94

Please sign in to comment.