Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nulling-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
smadani2
nulling-python
Commits
d8df0983
Commit
d8df0983
authored
4 years ago
by
Sepehr Madani
Browse files
Options
Downloads
Patches
Plain Diff
Add a Butterfly-based implementation of genetic
parent
24f3ff78
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
algorithms/genetic_butterfly_algorithm.py
+40
-0
40 additions, 0 deletions
algorithms/genetic_butterfly_algorithm.py
with
40 additions
and
0 deletions
algorithms/genetic_butterfly_algorithm.py
0 → 100644
+
40
−
0
View file @
d8df0983
from
random
import
randrange
,
random
,
choice
,
sample
from
cmath
import
exp
,
phase
from
math
import
log10
,
pi
,
nan
,
cos
,
sin
from
utils.pattern
import
compute_pattern
,
compute_single_pattern
from
.genetic_algorithm
import
GeneticAlgorithm
,
Chromosome
from
.butterfly_algorithm
import
ButterflyAlgorithm
class
GeneticWithButterflyAlgorithm
(
GeneticAlgorithm
):
"""
Finds nulls by running a genetic algorithm on all possible
discrete values. Uses the Butterfly algorithm to create a base
chromosome, from which the entire population is created.
"""
def
__init__
(
self
,
options
):
super
().
__init__
(
options
)
butterfly_alg
=
ButterflyAlgorithm
(
options
)
weights
,
score
=
butterfly_alg
.
solve
()
self
.
base_weights
=
[
x
for
x
in
weights
]
pass
def
initialize_sample
(
self
):
self
.
generations
=
0
self
.
chromosomes
.
clear
()
if
self
.
overwrite_mutations
:
self
.
chromosomes
=
[
Chromosome
(
self
.
base_weights
,
shufflize
=
False
)]
+
[
Chromosome
(
self
.
base_weights
)
for
_
in
range
(
self
.
sample_size
-
1
)
]
else
:
self
.
chromosomes
=
[
Chromosome
(
self
.
base_weights
,
shufflize
=
False
)]
+
[
Chromosome
(
self
.
base_weights
)
for
_
in
range
(
self
.
sample_size
*
2
-
2
)
]
if
self
.
buckets
is
not
None
:
self
.
initialize_buckets
()
# TODO: Find what overloading I missed from Genetic. The min score for this alg cannot be worse than the base_weights
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment