You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
C:\Users\Administrator\Envs\py3MachineLearning\Scripts\python.exe D:/personal/Mathematical_modeling/genetic_algorithm.py
Traceback (most recent call last):
File "D:/personal/Mathematical_modeling/genetic_algorithm.py", line 48, in
engine.run(ng=100)
File "C:\Users\Administrator\Envs\py3MachineLearning\lib\site-packages\gaft\engine.py", line 45, in profiled_func
result = func(*args, **kwargs)
File "C:\Users\Administrator\Envs\py3MachineLearning\lib\site-packages\gaft\engine.py", line 160, in run
a.setup(ng=ng, engine=self)
File "C:\Users\Administrator\Envs\py3MachineLearning\lib\site-packages\gaft\mpiutil.py", line 147, in _call_in_master_proc
if mpi.is_master:
NameError: name 'mpi' is not defined
麻烦您帮忙看下这是什么问题呢?
engine.py:
import cProfile
import pstats
import os
from .components import IndividualBase, Population
from .plugin_interfaces.operators import Selection, Crossover, Mutation
from .plugin_interfaces.analysis import OnTheFlyAnalysis
from .mpiutil import MPIUtil
mpi = MPIUtil()
mpiutile.py
def master_only(func):
''' Decorator to limit a function to be called only in master process in MPI env.
''' @wraps(func)
def _call_in_master_proc(*args, **kwargs):
if mpi.is_master:
return func(*args, **kwargs)
return _call_in_master_proc
代码:
#!/usr/bin/env python
-- coding: utf-8 --
'''
Find the global maximum for binary function: f(x) = ysim(2pix) + xcos(2piy)
'''
from math import sin, cos, pi
from gaft import GAEngine
from gaft.components import BinaryIndividual
from gaft.components import Population
from gaft.operators import TournamentSelection
from gaft.operators import UniformCrossover
from gaft.operators import FlipBitBigMutation
Built-in best fitness analysis.
from gaft.analysis.fitness_store import FitnessStore
from gaft.analysis.console_output import ConsoleOutput
C:\Users\Administrator\Envs\py3MachineLearning\Scripts\python.exe D:/personal/Mathematical_modeling/genetic_algorithm.py
Traceback (most recent call last):
File "D:/personal/Mathematical_modeling/genetic_algorithm.py", line 48, in
engine.run(ng=100)
File "C:\Users\Administrator\Envs\py3MachineLearning\lib\site-packages\gaft\engine.py", line 45, in profiled_func
result = func(*args, **kwargs)
File "C:\Users\Administrator\Envs\py3MachineLearning\lib\site-packages\gaft\engine.py", line 160, in run
a.setup(ng=ng, engine=self)
File "C:\Users\Administrator\Envs\py3MachineLearning\lib\site-packages\gaft\mpiutil.py", line 147, in _call_in_master_proc
if mpi.is_master:
NameError: name 'mpi' is not defined
麻烦您帮忙看下这是什么问题呢?
engine.py:
import cProfile
import pstats
import os
from .components import IndividualBase, Population
from .plugin_interfaces.operators import Selection, Crossover, Mutation
from .plugin_interfaces.analysis import OnTheFlyAnalysis
from .mpiutil import MPIUtil
mpi = MPIUtil()
mpiutile.py
def master_only(func):
''' Decorator to limit a function to be called only in master process in MPI env.
'''
@wraps(func)
def _call_in_master_proc(*args, **kwargs):
if mpi.is_master:
return func(*args, **kwargs)
代码:
#!/usr/bin/env python
-- coding: utf-8 --
'''
Find the global maximum for binary function: f(x) = ysim(2pix) + xcos(2piy)
'''
from math import sin, cos, pi
from gaft import GAEngine
from gaft.components import BinaryIndividual
from gaft.components import Population
from gaft.operators import TournamentSelection
from gaft.operators import UniformCrossover
from gaft.operators import FlipBitBigMutation
Built-in best fitness analysis.
from gaft.analysis.fitness_store import FitnessStore
from gaft.analysis.console_output import ConsoleOutput
Define population.
indv_template = BinaryIndividual(ranges=[(-2, 2), (-2, 2)], eps=0.001)
population = Population(indv_template=indv_template, size=50).init()
Create genetic operators.
#selection = RouletteWheelSelection()
selection = TournamentSelection()
crossover = UniformCrossover(pc=0.8, pe=0.5)
mutation = FlipBitBigMutation(pm=0.1, pbm=0.55, alpha=0.6)
Create genetic algorithm engine.
Here we pass all built-in analysis to engine constructor.
engine = GAEngine(population=population, selection=selection,
crossover=crossover, mutation=mutation,
analysis=[ConsoleOutput, FitnessStore])
Define fitness function.
@engine.fitness_register
def fitness(indv):
x, y = indv.solution
return ysin(2pix) + xcos(2piy)
if 'main' == name:
engine.run(ng=100)
Originally posted by @lilyef2000 in https://github.com/_render_node/MDEyOklzc3VlQ29tbWVudDQ0MjY1NzMzNA==/timeline/issue_comment#issuecomment-442657334
The text was updated successfully, but these errors were encountered: