Comments (6)
pip in install 也有問題, 人手條改 C:\ProgramData\Anaconda3\Lib\site-packages\gaft\mpiutil.py 後就無事
from gaft.
可以通过pip install 安装 0.5.7版本,bug已修复
from gaft.
你好,由于最近更新了GAFT的部分接口,mpi的部分在最新版本中不会自动实例化,而是用户自行实例化。例子是我忘记更新了,你可以将你的脚本中的
from gaft.mpiutil import mpi
改写成
from gaft.mpiutil import MPIUtil
mpi = MPIUtil()
from gaft.
例子我会在今天进行更新,谢谢提醒
from gaft.
运行例子还是报错:
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
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)
from gaft.
Did you install GAFT using pip install
? I forgot to push the newest version to PyPI, you can currently install GAFT from source. I'll upload it to PyPI today.
Thanks for your issue.
from gaft.
Related Issues (20)
- 多进程运行大量重复参数 HOT 2
- ImportError: cannot import name 'GAEngine' HOT 4
- 那个染色体的单词好像是chromosome HOT 2
- question: individual, binary_individual, decimal_individual HOT 2
- fitness函数没有并行 HOT 4
- sum_fit maybe is 0 that causes error:ZeroDivisionError: float division by zero HOT 3
- decimal_individual中decode问题
- How to initial population with a specified solution
- Come in and have a look! 作为一名老用户,中肯地对此框架作出一些评价,走过路过的也希望来看一下。 HOT 1
- 请问我该怎么添加等式约束 HOT 3
- Weight optimization in order to minimize correlation
- RouletteWheelSelection ZeroDivisionError
- gaft 是否已经不再维护? HOT 1
- 多进程运行时,请问如何仅仅让主程序执行一些log文件? HOT 1
- The mutation operator occurs only at level of bits
- 自定义Individual类
- 自定义个体的过程中,mutate需要重载怎么做
- Question in RouletteWheelSelection?
- Windows10无法识别mpirun HOT 1
- Question: Best fitness values are written to best_fit.py
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gaft.