Comments (5)
包装一层
def your_func(x, model, y):
return x+model+y
def demo_func(t):
x, model, y = t
return your_func(x, model, y)
from scikit-opt.
不好意思,我没看懂。我的意思是我调用PSO的时候,怎么把x, model, y这三个传给demo_func(),也就是这个参数t在主函数里怎么构造。
from scikit-opt.
如果model和y是其它地方定义的,
model = 's'
y = 1
def your_func(x, model, y):
x1, x2, x3 = x
if model == 's':
return x1 + x2 + x3 + y
else:
return x1 + x2 - x3 - y
那么你在调用 scikit-opt 的时候,需要在外面封装一层
def demo_func(x):
x1, x2, x3 = x
return your_func(x, model, y)
然后把 demo_func 放入 scikit-opt 计算
PSO(func=demo_func, **params)
from scikit-opt.
明白了,非常感谢
from scikit-opt.
下面是我根据上面的代码写的程序,但是存在两个问题:
- 该程序会报错:ValueError: not enough values to unpack (expected 3, got 1)
- 并没有把main函数中的model和y传给demo_func()
恳请好心人给小白指点迷津,感激不尽!
from sko.GA import GA
def your_func(x, model, y):
return x + model + y
def demo_func(t):
x, model, y = t
return your_func(x, model, y)
def main():
model = 's'
y = 1
ga = GA(func=demo_func, n_dim=1, size_pop=10, max_iter=50)
best_params, residuals = ga.run()
print('best_x:', best_params, '\n', 'best_y:', residuals)
if name == "main":
main()
from scikit-opt.
Related Issues (20)
- crossover.py文件中crossover_2point_bit算子起作用吗
- How to change crossover rate? HOT 1
- 请问GA在做整数规划的时候怎么设置才能保证每次n个变量间不重复 HOT 1
- Allow users to set number of process pool workers/threads
- 如何在初始化阶段将表现良好的个体加入种群?
- 规定GA起始点
- 约束条件不生效
- 请教多进程模式下,如何释放占用内存 HOT 3
- ACA算法发生除0问题
- 请问模拟退火算法出自于哪里?
- 希望增加进度条
- 如何设置遗传算法优化函数最大化?提供的一些demo都是目标函数最小化问题求解
- 请问,如何解决一个简单的VRP问题?
- 如何用已知的较好参数初始化种群 HOT 2
- 默认优化目标最大还是最小
- solve the problem that use grid route
- 计算加速
- 非优化参数的传入 HOT 2
- BUG: array shape mismatch between Y and pbest_y in PSO, error raised in update_pbest HOT 1
- 请问约束等式或约束不等式支持向量化形式的约束吗?
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 scikit-opt.