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 refactored main branch #9

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

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jun 22, 2023

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:

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

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from sjvrijn June 22, 2023 08:51
Comment on lines -252 to -257
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'
Copy link
Author

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:

Comment on lines -424 to +422
opts = dict()
opts = {}
Copy link
Author

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:

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))}>"
Copy link
Author

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:

Comment on lines -99 to +96
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
Copy link
Author

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:

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
Copy link
Author

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:

Comment on lines -50 to +54
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
}
Copy link
Author

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:

Comment on lines -61 to +67
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)
}
Copy link
Author

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:

Comment on lines -72 to -81
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)

Copy link
Author

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:

Comment on lines -118 to +156
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,
)
Copy link
Author

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:

Comment on lines -181 to +198
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))
Copy link
Author

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:

Comment on lines -289 to +302
self.FCE = FCE if FCE > target else target # Fixed Cost Error
self.FCE = max(FCE, target)
Copy link
Author

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:

This removes the following comments ( why? ):

# Fixed Cost Error

Comment on lines -309 to +322
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:
Copy link
Author

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:

Comment on lines -318 to +334
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})"
Copy link
Author

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:

Comment on lines -25 to +27
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
)
Copy link
Author

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:

self.assertDictEqual(getVals([None]*self.length), dict())
self.assertDictEqual(getVals([None]*self.length), {})
Copy link
Author

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:

self.default = dict(((opt[0], opt[1][0]) for opt in options))
self.default = {opt[0]: opt[1][0] for opt in options}
Copy link
Author

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:

self.default = dict(((opt[0], opt[1][0]) for opt in options))
self.default = {opt[0]: opt[1][0] for opt in options}
Copy link
Author

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:

default = dict(((opt[0], opt[1][1]) for opt in options))
default = {opt[0]: opt[1][1] for opt in options}
Copy link
Author

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:

case = dict(((opt[0], opt[1][0]) for opt in options))
case = {opt[0]: opt[1][0] for opt in options}
Copy link
Author

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:

case = dict(((opt[0], opt[1][1]) for opt in options))
case = {opt[0]: opt[1][1] for opt in options}
Copy link
Author

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:

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

0 participants