Sourcery refactored master branch#1
Conversation
| class RL_QG_agent: | ||
| def __init__(self): | ||
| self.model_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Reversi") | ||
| pass # 删掉这句话,并填写相应代码 |
There was a problem hiding this comment.
Function RL_QG_agent.__init__ refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass)
This removes the following comments ( why? ):
# 删掉这句话,并填写相应代码
| # 这个函数 主要用于测试, 返回的 action是 0-63 之间的一个数值, | ||
| # action 表示的是 要下的位置。 | ||
| action = 123456789 # 删掉这句话,并填写相应代码 | ||
|
|
||
| return action | ||
| return 123456789 |
There was a problem hiding this comment.
Function RL_QG_agent.place refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# 删掉这句话,并填写相应代码
# 这个函数 主要用于测试, 返回的 action是 0-63 之间的一个数值,
# action 表示的是 要下的位置。
| name = ''.join([g.capitalize() for g in game.split('_')]) | ||
| if obs_type == 'ram': | ||
| name = '{}-ram'.format(name) | ||
| name = f'{name}-ram' |
There was a problem hiding this comment.
Lines 311-491 refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting) - Replace if statement with if expression (
assign-if-exp)
This removes the following comments ( why? ):
# somewhat harder because of higher variance:
# probably the hardest because you only get a constant number of rewards in total:
# probably the easiest:
# semi_supervised envs
# A frameskip of 1 means we get every frame
| max_epochs = 100 | ||
|
|
||
| for i_episode in range(max_epochs): | ||
| for _ in range(max_epochs): |
There was a problem hiding this comment.
Lines 15-47 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore) - Replace if statement with if expression (
assign-if-exp) - Replace call to format with f-string. (
use-fstring-for-formatting)
This removes the following comments ( why? ):
# pass
# 调用自己训练的模型
| assert isinstance(board_size, int) and board_size >= 1, 'Invalid board size: {}'.format(board_size) | ||
| assert ( | ||
| isinstance(board_size, int) and board_size >= 1 | ||
| ), f'Invalid board size: {board_size}' | ||
|
|
There was a problem hiding this comment.
Function ReversiEnv.__init__ refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting)
| std = np.sqrt(np.mean(np.abs(ys - ys_pred) ** 2)) | ||
| return std | ||
| return np.sqrt(np.mean(np.abs(ys - ys_pred) ** 2)) |
There was a problem hiding this comment.
Function evaluate refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| pass | ||
| # 按诗的字数排序 | ||
| poems = sorted(poems, key=lambda line: len(line)) | ||
| # print(poems) | ||
| # 统计每个字出现次数 | ||
| all_words = [] | ||
| for poem in poems: | ||
| all_words += [word for word in poem] | ||
| all_words += list(poem) | ||
| counter = collections.Counter(all_words) # 统计词和词频。 | ||
| count_pairs = sorted(counter.items(), key=lambda x: -x[1]) # 排序 | ||
| words, _ = zip(*count_pairs) | ||
| words = words[:len(words)] + (' ',) | ||
| words = words[:] + (' ',) |
There was a problem hiding this comment.
Function process_poems1 refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass) - Replace identity comprehension with call to collection constructor (
identity-comprehension) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index)
| line = line.strip() | ||
| if line: | ||
| if line := line.strip(): |
There was a problem hiding this comment.
Function process_poems2 refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Replace identity comprehension with call to collection constructor (
identity-comprehension) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index)
| if w == start_token or w == end_token: | ||
| if w in [start_token, end_token]: | ||
| break | ||
| shige.append(w) | ||
| poem_sentences = poem.split('。') | ||
| for s in poem_sentences: | ||
| if s != '' and len(s) > 10: | ||
| print(s + '。') | ||
| print(f'{s}。') |
There was a problem hiding this comment.
Function pretty_print_poem refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons) - Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| """ | ||
| sen_embed = self.word_embedding(input_sentence) | ||
| return sen_embed | ||
| return self.word_embedding(input_sentence) |
There was a problem hiding this comment.
Function word_embedding.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
Branch
masterrefactored 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
masterbranch, then run:Help us improve this pull request!