-
Notifications
You must be signed in to change notification settings - Fork 0
Add breed_rats to ch07 #12
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
Conversation
…yle D205 and D209
Now that was a refactor session. RIP coverage from not testing setters. I'll add setter tests and review sphinx docs next time. |
Never needed to make ROUSs, like in Princess Bride, but now I know how they may have gotten there. |
@property | ||
def min_wt(self): | ||
"""int: Minimum weight of adult rat in initial population. | ||
|
||
Default is ``200``. | ||
""" | ||
return self._min_wt | ||
|
||
@min_wt.setter | ||
def min_wt(self, value: int): | ||
self._min_wt = value |
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.
I considered making the properties mixedCase, like I've seen in other packages, but PEP8 advises to follow function naming rules for method names. Furthermore, PEP8 advises function names should be lowercase with underscores.
Technically, minWt
has one fewer key press than min_wt
. This will keep me up at night.
# pylint: disable=too-many-instance-attributes,too-many-public-methods | ||
# Limit is for instance attributes and public methods are 7 and 20, | ||
# but analysis like this requires many constants. | ||
# I am opting to make them modifiable in something that is isn't a | ||
# dictionary. | ||
# If there is a better way, please submit an issue for discussion. |
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.
pylint
is a wise sage that tries to warn you when you're doing too much at once. Turning this module into a class helped with usability and readability, but there are a lot of variables at work here.
While I may look into dictionaries or namedtuples again, I like that each variable can be controlled independently for testing small variances.
Testing at what point each variable stops being beneficial is an interesting pastime.
Summary
Initialize chapter 7 with a genetic algorithm simulator.
Description
Simulates a genetic algorithm by breeding rats until they reach an average weight of 50000 grams. The challenge here is modifying the code to allow for a variable number of males and females in the population rather than equal numbers for matched pairs.
This version keeps the population in a dictionary, pseudo-randomly assigns gender to the litters of pups (the test data for this is very interesting, I might add), and pseudo-randomly selects males to breed with more than one female.
The litters of pups are then added to the general population based on gender and become part of the selection process for the largest weight per gender.
This method uses the same population size as the one detailed in the book, but because of gender separation and selection, shaves off about 10 years from reaching the target weight.
So, why am I not merging? Pylint doesn't like functions to have more than 5 arguments nor 15 variable names. To get around that, I had to use tuples, but tuples as arguments don't allow for specifying what is in them. That creates this clunky function:
impracticalpythonprojects/src/ch07/c1_breed_rats.py
Lines 214 to 232 in 6c238f2
I'd like to clean this up as much as possible. After some research and pondering, I can either use module constants directly in the function or make the whole module a class.
So, I'll be spending time converting this module into a proper class.
Team Notifications
Me, myself, and I