FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Replaces max/min with argmax/argmin by Chipe1 · Pull Request #481 · aimacode/aima-python · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 2 additions & 4 deletions search.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,9 @@ def __call__(self, s1): # as of now s1 is a state rather than a percept
self.H[self.s] = min(self.LRTA_cost(self.s, b, self.problem.output(self.s, b),
self.H) for b in self.problem.actions(self.s))

# costs for action b in problem.actions(s1)
costs = [self.LRTA_cost(s1, b, self.problem.output(s1, b), self.H)
for b in self.problem.actions(s1)]
# an action b in problem.actions(s1) that minimizes costs
self.a = list(self.problem.actions(s1))[costs.index(min(costs))]
self.a = argmin(self.problem.actions(s1),
key=lambda b:self.LRTA_cost(s1, b, self.problem.output(s1, b), self.H))

self.s = s1
return self.a
Expand Down
6 changes: 2 additions & 4 deletions text.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,7 @@ def score(self, plaintext):
def decode(self, ciphertext):
"""Return the shift decoding of text with the best score."""

list_ = [(self.score(shift), shift)
for shift in all_shifts(ciphertext)]
return max(list_, key=lambda elm: elm[0])[1]
return argmax(all_shifts(ciphertext), key=lambda shift: self.score(shift))


def all_shifts(text):
Expand Down Expand Up @@ -360,7 +358,7 @@ def decode(self, ciphertext):
problem = PermutationDecoderProblem(decoder=self)
solution = search.best_first_graph_search(
problem, lambda node: self.score(node.state))
print(solution.state, len(solution.state))

solution.state[' '] = ' '
return translate(self.ciphertext, lambda c: solution.state[c])

Expand Down

Back | FazBrowse Home | New Git URL