Git Product home page Git Product logo

Comments (5)

guofei9987 avatar guofei9987 commented on July 17, 2024

包装一层

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.

hadlang avatar hadlang commented on July 17, 2024

不好意思,我没看懂。我的意思是我调用PSO的时候,怎么把x, model, y这三个传给demo_func(),也就是这个参数t在主函数里怎么构造。

from scikit-opt.

guofei9987 avatar guofei9987 commented on July 17, 2024

如果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.

hadlang avatar hadlang commented on July 17, 2024

明白了,非常感谢

from scikit-opt.

KCWang010 avatar KCWang010 commented on July 17, 2024

下面是我根据上面的代码写的程序,但是存在两个问题:

  1. 该程序会报错:ValueError: not enough values to unpack (expected 3, got 1)
  2. 并没有把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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.