- 帖子
- 35
- 积分
- 80
- 技术
- 8
- 捐助
- 0
- 注册时间
- 2020-5-27
|
2楼
发表于 2020-7-16 15:37
| 只看该作者
回复 1# Liule
#!/usr/bin/env python3
from scipy.optimize import differential_evolution
from math import log
from math import e
import numpy as np
data = """1.0 300 -35.287
1.5 315 -34.047
2.0 330 -32.872
2.5 345 -31.757
====copy your data=====
5.0 880 -12.729
5.0 890 -12.547
5.0 900 -12.369"""
data = data.split("\n")
data = list(map(lambda x: filter(None, x.split(" ")), data))
data = map(lambda x: list(map(float, x)), data)
data = list(data)
def f(x, y, a, b, c, d, f):
return (a * (y + 273.15) + b + c * x + d * (y + 273.15) * np.log(y+273.15) \
+ f * ((y+273.15) ** 2)) / (8.3144 * (y + 273.15) * log(10,e))
def fitness(parameters):
error = 0
for x, y, z in data:
res = f(x, y, *parameters)
error += abs(res - z) ** 2
return error
from scipy.optimize import differential_evolution
bounds = [(-500000, 500000)] * 5
x = differential_evolution(fitness, bounds, disp=True).x
print(list(x)) |
-
1
评分人数
-
|