Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery Starbot ⭐ refactored radsn23/bandits-codes #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sourcery-ai-bot
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch https://github.com/sourcery-ai-bot/bandits-codes master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines +103 to -108
T = 500
N = 10 #number of batches
versions = 3 #or the number of arms of the bandit
l=0.1 #lambda
X_size = 3
for a in alphas:
T = 500
N = 10 #number of batches
versions = 3 #or the number of arms of the bandit
l=0.1 #lambda
X_size = 3
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 104-160 refactored with the following changes:

  • Hoist statements out of for/while loops (hoist-statement-from-loop)

if prior == None:
if prior is None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function email_mooclet.__init__ refactored with the following changes:

  • Use x is None rather than x == None (none-compare)

tried_outputs = [0,0,0]
tried_outputs = [0,0,0]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 41-62 refactored with the following changes:

  • Replace unused for index with underscore (for-index-underscore)

# number of trials used to compute expectation stats
# set to small value when debugging for faster speed
num_trials_prob_best_action = int(1e4)

if models == None:
if models is None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function calculate_linucb_single_bandit refactored with the following changes:

  • Hoist statements out of for/while loops (hoist-statement-from-loop)
  • Move assignments closer to their usage (move-assign)
  • Use x is None rather than x == None (none-compare)
  • Replace index in for loop with direct reference (for-index-replacement)
  • Replace manual loop counter with call to enumerate (convert-to-enumerate)
  • Convert for loop into dictionary comprehension (dict-comprehension)

if len(pre_regret) == 0:
if not pre_regret:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function read_avg_regret refactored with the following changes:

  • Simplify sequence comparison (simplify-len-comparison)

Comment on lines -187 to -193
pass

plt.title(title)

plt.show()

pass
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function plot_email_data refactored with the following changes:

  • Remove redundant pass statement (remove-redundant-pass)

Comment on lines -280 to +297

print(','.join(group_header), file=outf)

writer = csv.DictWriter(outf, fieldnames=field_names_out)
writer.writeheader()

sample_number = 0

cumulative_sample_regret = 0
for row in reader:

for sample_number, row in enumerate(reader):
# copy the input data to output file
out_row = {}
out_row = {fieldname: row[fieldname] for fieldname in reader.fieldnames}

for i in range(len(reader.fieldnames)):
out_row[reader.fieldnames[i]] = row[reader.fieldnames[i]]

''' write performance data (e.g. regret) for this sample'''
action = chosen_actions[sample_number]
observed_rewards = [int(row[HEADER_ACTUALREWARD.format(a + 1)]) for a in range(num_actions)]
sampling_dist = sampling_distributions[sample_number]
reward = observed_rewards[action]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function writeOutFile refactored with the following changes:

  • Replace index in for loop with direct reference (for-index-replacement)
  • Replace manual loop counter with call to enumerate (convert-to-enumerate)
  • Convert for loop into dictionary comprehension (dict-comprehension)

@@ -76,7 +76,6 @@ def write_performance(out_row, action, optimal_action, reward, sample_regret, cu
out_row[H_ALGO_SAMPLE_REGRET_CUMULATIVE] = cumulative_sample_regret
out_row[H_ALGO_REGRET_EXPECTED] = expected_regret
out_row[H_ALGO_REGRET_EXPECTED_CUMULATIVE] = cumulative_expected_regret
pass
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function write_performance refactored with the following changes:

  • Remove redundant pass statement (remove-redundant-pass)

@@ -76,7 +76,6 @@ def write_performance(out_row, action, optimal_action, reward, sample_regret, cu
out_row[H_ALGO_SAMPLE_REGRET_CUMULATIVE] = cumulative_sample_regret
out_row[H_ALGO_REGRET_EXPECTED] = expected_regret
out_row[H_ALGO_REGRET_EXPECTED_CUMULATIVE] = cumulative_expected_regret
pass
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function write_performance refactored with the following changes:

  • Remove redundant pass statement (remove-redundant-pass)

@@ -66,7 +66,6 @@ def write_performance(out_row, action, optimal_action, reward, sample_regret, cu
out_row[H_ALGO_SAMPLE_REGRET_CUMULATIVE] = cumulative_sample_regret
out_row[H_ALGO_REGRET_EXPECTED] = expected_regret
out_row[H_ALGO_REGRET_EXPECTED_CUMULATIVE] = cumulative_expected_regret
pass
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function write_performance refactored with the following changes:

  • Remove redundant pass statement (remove-redundant-pass)

Comment on lines -148 to +147
# number of trials used to run Thompson Sampling to compute expectation stats
# set to small value when debugging for faster speed
num_trials_prob_best_action = int(1e4)

if models == None:
if models is None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function calculate_thompson_single_bandit refactored with the following changes:

  • Move assignments closer to their usage (move-assign)
  • Use x is None rather than x == None (none-compare)
  • Replace index in for loop with direct reference (for-index-replacement)
  • Replace manual loop counter with call to enumerate (convert-to-enumerate)
  • Convert for loop into dictionary comprehension (dict-comprehension)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant