Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented Mar 21, 2022

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

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

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from brucew2099 March 21, 2022 00:13
@@ -11,6 +11,7 @@

"""

Copy link
Author

Choose a reason for hiding this comment

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

Lines 36-40 refactored with the following changes:

This removes the following comments ( why? ):

# counter

num_correct = sum(int(a == y) for a, y in zip(predictions, test_data[1]))
print("Baseline classifier using an SVM.")
print(str(num_correct) + " of " + str(len(test_data[1])) + " values correct.")
print(f'{str(num_correct)} of {len(test_data[1])} values correct.')
Copy link
Author

Choose a reason for hiding this comment

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

Function svm_baseline refactored with the following changes:

Comment on lines -73 to +75
print("Epoch {} : {} / {}".format(j,self.evaluate(test_data),n_test))
print(f"Epoch {j} : {self.evaluate(test_data)} / {n_test}")
else:
print("Epoch {} complete".format(j))
print(f"Epoch {j} complete")
Copy link
Author

Choose a reason for hiding this comment

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

Function Network.SGD refactored with the following changes:

Comment on lines -182 to +202
print("Epoch %s training complete" % j)
print(f"Epoch {j} training complete")

if monitor_training_cost:
cost = self.total_cost(training_data, lmbda)
training_cost.append(cost)
print("Cost on training data: {}".format(cost))
print(f"Cost on training data: {cost}")
if monitor_training_accuracy:
accuracy = self.accuracy(training_data, convert=True)
training_accuracy.append(accuracy)
print("Accuracy on training data: {} / {}".format(accuracy, n))
print(f"Accuracy on training data: {accuracy} / {n}")
if monitor_evaluation_cost:
cost = self.total_cost(evaluation_data, lmbda, convert=True)
evaluation_cost.append(cost)
print("Cost on evaluation data: {}".format(cost))
print(f"Cost on evaluation data: {cost}")
if monitor_evaluation_accuracy:
accuracy = self.accuracy(evaluation_data)
evaluation_accuracy.append(accuracy)
print("Accuracy on evaluation data: {} / {}".format(self.accuracy(evaluation_data), n_data))
print(
f"Accuracy on evaluation data: {self.accuracy(evaluation_data)} / {n_data}"
)

Copy link
Author

Choose a reason for hiding this comment

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

Function Network.SGD refactored with the following changes:

Comment on lines -300 to +303
result_accuracy = sum(int(x == y) for (x, y) in results)
return result_accuracy
return sum(int(x == y) for (x, y) in results)
Copy link
Author

Choose a reason for hiding this comment

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

Function Network.accuracy refactored with the following changes:

Comment on lines -324 to +327
f = open(filename, "w")
json.dump(data, f)
f.close()
with open(filename, "w") as f:
json.dump(data, f)
Copy link
Author

Choose a reason for hiding this comment

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

Function Network.save refactored with the following changes:

Comment on lines -334 to +336
f = open(filename, "r")
data = json.load(f)
f.close()
with open(filename, "r") as f:
data = json.load(f)
Copy link
Author

Choose a reason for hiding this comment

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

Function load refactored with the following changes:


# define the (regularized) cost function, symbolic gradients, and updates
l2_norm_squared = sum([(layer.w**2).sum() for layer in self.layers])
l2_norm_squared = sum((layer.w**2).sum() for layer in self.layers)
Copy link
Author

Choose a reason for hiding this comment

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

Function Network.SGD refactored with the following changes:

Comment on lines -141 to +145
for i in range(iters):
for _ in range(iters):
r = f()
t1 = time.time()
print("Looping %d times took %f seconds" % (iters, t1 - t0))
print("Result is %s" % (r,))
print(f"Result is {r}")
Copy link
Author

Choose a reason for hiding this comment

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

Function testTheano refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 21, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.03%.

Quality metrics Before After Change
Complexity 5.75 ⭐ 5.75 ⭐ 0.00
Method Length 63.91 🙂 63.91 🙂 0.00
Working memory 11.93 😞 11.93 😞 0.00
Quality 61.08% 🙂 61.05% 🙂 -0.03% 👎
Other metrics Before After Change
Lines 1037 1036 -1
Changed files Quality Before Quality After Quality Change
expand_mnist.py 32.97% 😞 32.97% 😞 0.00%
mnist_svm.py 84.31% ⭐ 84.55% ⭐ 0.24% 👍
network.py 67.60% 🙂 67.44% 🙂 -0.16% 👎
network2.py 58.59% 🙂 58.07% 🙂 -0.52% 👎
network3.py 61.59% 🙂 61.59% 🙂 0.00%
test.py 71.84% 🙂 71.84% 🙂 0.00%

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
network3.py Network.SGD 18 🙂 409 ⛔ 21 ⛔ 21.65% ⛔ Try splitting into smaller methods. Extract out complex expressions
network2.py Network.SGD 21 😞 244 ⛔ 23 ⛔ 23.20% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
network.py Network.backprop 2 ⭐ 170 😞 12 😞 55.30% 🙂 Try splitting into smaller methods. Extract out complex expressions
network2.py Network.backprop 2 ⭐ 168 😞 12 😞 55.49% 🙂 Try splitting into smaller methods. Extract out complex expressions
network2.py Network.update_mini_batch 1 ⭐ 127 😞 14 😞 57.91% 🙂 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

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.

0 participants