-
Notifications
You must be signed in to change notification settings - Fork 3
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 refactored main branch #9
base: main
Are you sure you want to change the base?
Conversation
if large <= 0: | ||
if large <= 0 or small > 0 and large <= small: | ||
self.regime = 'small' | ||
elif small <= 0 or large > small: | ||
self.regime = 'large' | ||
else: | ||
self.regime = 'small' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function EvolutionaryOptimizer.determineRegime
refactored with the following changes:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Remove redundant conditional (
remove-redundant-if
)
opts = dict() | ||
opts = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function CustomizedES.__init__
refactored with the following changes:
- Replace
dict()
with{}
(dict-literal
)
return "<FloatIndividual [{}]: {}>".format( | ||
str(np.round_(self.fitness,2)), | ||
str(np.round_(self.genotype.flatten(), 2)), | ||
) | ||
return f"<FloatIndividual [{str(np.round_(self.fitness, 2))}]: {str(np.round_(self.genotype.flatten(), 2))}>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function FloatIndividual.__repr__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
if n > 5: | ||
self.baseStepSize = 1 / n | ||
else: | ||
self.baseStepSize = 0.175 # Random guess value, may need to be updated | ||
|
||
self.baseStepSize = 1 / n if n > 5 else 0.175 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function MixedIntIndividual.__init__
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
This removes the following comments ( why? ):
# Random guess value, may need to be updated
if bool(random.getrandbits(1)): | ||
return 5/7 | ||
else: | ||
return 7/5 | ||
return 5/7 if bool(random.getrandbits(1)) else 7/5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function _getXi
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
values = {initializable_parameters[i]: val for i, val in enumerate(init_values) if val is not None} | ||
return values | ||
return { | ||
initializable_parameters[i]: val | ||
for i, val in enumerate(init_values) | ||
if val is not None | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function getVals
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
opts = {option[0]: option[1][int(bitstring[i])] for i, option in enumerate(options)} | ||
return opts | ||
return { | ||
option[0]: option[1][int(bitstring[i])] | ||
for i, option in enumerate(options) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function getOpts
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
for i, option in enumerate(options): | ||
for option in options: | ||
name, choices, _ = option | ||
if name in opts: | ||
if opts[name] in choices: | ||
bitstring.append(choices.index(opts[name])) | ||
else: | ||
bitstring.append(0) | ||
if name in opts and opts[name] in choices: | ||
bitstring.append(choices.index(opts[name])) | ||
else: | ||
bitstring.append(0) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function getBitString
refactored with the following changes:
- Remove unnecessary calls to
enumerate
when the index is not used (remove-unused-enumerate
) - Merge duplicate blocks in conditional (
merge-duplicate-blocks
)
ipop = '{}-'.format(opts['ipop']) if opts['ipop'] is not None else '' | ||
weight = '${}$-weighted '.format(opts['weights_option']) if opts['weights_option'] is not None else '' | ||
ipop = f"{opts['ipop']}-" if opts['ipop'] is not None else '' | ||
weight = ( | ||
f"${opts['weights_option']}$-weighted " | ||
if opts['weights_option'] is not None | ||
else '' | ||
) | ||
|
||
sel = 'Pairwise selection' if opts['selection'] == 'pairwise' else '' | ||
sampler = 'a {} sampler'.format(opts['base-sampler']) if opts['base-sampler'] is not None else '' | ||
sampler = ( | ||
f"a {opts['base-sampler']} sampler" | ||
if opts['base-sampler'] is not None | ||
else '' | ||
) | ||
|
||
if len(sel) + len(sampler) > 0: | ||
append = ' with {}' | ||
if len(sel) > 0 and len(sampler) > 0: | ||
temp = '{} and {}'.format(sel, sampler) | ||
if not sel or sampler == "": | ||
temp = f'{sel}{sampler}' | ||
else: | ||
temp = '{}{}'.format(sel, sampler) | ||
temp = f'{sel} and {sampler}' | ||
append = append.format(temp) | ||
else: | ||
append = '' | ||
|
||
base_string = "{seq}{thres}{weight}{mirror}{ortho}{active}(mu{elitist}lambda)-{tpa}{ipop}CMA-ES{append}" | ||
|
||
name = base_string.format(elitist=elitist, active=active, thres=thres, mirror=mirror, ortho=ortho, | ||
tpa=tpa, seq=seq, ipop=ipop, weight=weight, append=append) | ||
|
||
return name | ||
return base_string.format( | ||
elitist=elitist, | ||
active=active, | ||
thres=thres, | ||
mirror=mirror, | ||
ortho=ortho, | ||
tpa=tpa, | ||
seq=seq, | ||
ipop=ipop, | ||
weight=weight, | ||
append=append, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function getPrintName
refactored with the following changes:
- Replace call to format with f-string [×5] (
use-fstring-for-formatting
) - Simplify comparison to string length [×2] (
simplify-str-len-comparison
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Swap if/else branches (
swap-if-else-branches
) - Replaces an empty collection equality with a boolean operation (
simplify-empty-collection-comparison
)
integer = 0 | ||
for i in range(max_length): | ||
integer += representation[i] * factors[i] | ||
|
||
return integer | ||
return sum(representation[i] * factors[i] for i in range(max_length)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function reprToInt
refactored with the following changes:
- Convert for loop into call to sum() (
sum-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
self.FCE = FCE if FCE > target else target # Fixed Cost Error | ||
self.FCE = max(FCE, target) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ESFitness.__init__
refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity
)
This removes the following comments ( why? ):
# Fixed Cost Error
elif self.ERT is not None and other.ERT is not None and self.ERT < other.ERT: | ||
elif self.ERT is not None and self.ERT < other.ERT: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ESFitness.__lt__
refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if
)
kwargs = "target={},min_fitnesses={},min_indices={},num_successful={}".format( | ||
self.target, self.min_fitnesses, self.min_indices, self.num_successful | ||
) | ||
kwargs = f"target={self.target},min_fitnesses={self.min_fitnesses},min_indices={self.min_indices},num_successful={self.num_successful}" | ||
else: | ||
kwargs = "target={},ERT={},FCE={},std_dev_ERT={},std_dev_FCE={}".format( | ||
self.target, self.ERT, self.FCE, self.std_dev_ERT, self.std_dev_FCE | ||
) | ||
return "ESFitness({})".format(kwargs) | ||
kwargs = f"target={self.target},ERT={self.ERT},FCE={self.FCE},std_dev_ERT={self.std_dev_ERT},std_dev_FCE={self.std_dev_FCE}" | ||
return f"ESFitness({kwargs})" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ESFitness.__repr__
refactored with the following changes:
- Replace call to format with f-string [×3] (
use-fstring-for-formatting
)
np.testing.assert_array_almost_equal(_keepInBounds(vector, self.lbound, self.ubound), result) | ||
np.testing.assert_array_almost_equal( | ||
_keepInBounds(result, self.lbound, self.ubound), result | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function keepInBoundsTest.test_in_bounds
refactored with the following changes:
- Use previously assigned local variable (
use-assigned-variable
)
self.assertDictEqual(getVals([None]*self.length), dict()) | ||
self.assertDictEqual(getVals([None]*self.length), {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GetValsTest.test_nones
refactored with the following changes:
- Replace
dict()
with{}
(dict-literal
)
self.default = dict(((opt[0], opt[1][0]) for opt in options)) | ||
self.default = {opt[0]: opt[1][0] for opt in options} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GetBitStringTest.setUp
refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
)
self.default = dict(((opt[0], opt[1][0]) for opt in options)) | ||
self.default = {opt[0]: opt[1][0] for opt in options} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GetFullOptsTest.setUp
refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
)
default = dict(((opt[0], opt[1][1]) for opt in options)) | ||
default = {opt[0]: opt[1][1] for opt in options} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GetFullOptsTest.test_alternative
refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
)
case = dict(((opt[0], opt[1][0]) for opt in options)) | ||
case = {opt[0]: opt[1][0] for opt in options} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GetPrintNameTest.test_default_case
refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
)
case = dict(((opt[0], opt[1][1]) for opt in options)) | ||
case = {opt[0]: opt[1][1] for opt in options} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function GetPrintNameTest.test_alternative_case
refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
)
Branch
main
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
main
branch, then run:Help us improve this pull request!