我正在使用鸭嘴兽优化工具创建具有已知均值,CV,偏度和峰度的直方图,我能够找到优化值,但未获得所需的确切值。我在Python 3中使用Ubuntu EC2实例。我在下面复制了我的代码。在下面的图片中,您可以看到我如何使用a,c,loc和scale的初始比例参数(12.328607937460614,-25.460218010291722,-199.09204975419763,245.10235332412498)达到22的目标均值,CV为10,偏度值-0.43,峰度为0.352。我将这些价值观从已发表的文献研究中剔除。我有点担心不同的软件可能会以不同的方式计算偏度和峰度。我这样做的原因是,我可以在模仿文献中发现的产出分布的基础上测试不同的经济模型。在此做出回应,我可以进一步澄清。
import ipywidgets as widgets
import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import ipywidgets as widgets
import scipy.optimize
import scipy.stats
import csv
import pprint
import math
from platypus import *
import matplotlib.pyplot as plt
from scipy import interpolate
import numpy as np
from math import pow
def GammaDistribution(x):
a = x[0]
c = x[1]
loc = x[2]
scale = x[3]
distribution = scipy.stats.gengamma(a=a, c=c, loc=loc, scale=scale)
type(distribution)
sample = distribution.rvs(size=4000)
average_ = np.mean(sample)
variance_ = np.var(sample)
toup = distribution.stats("mvsk")
average = str(np.asscalar(toup[0]))
variance = str(np.asscalar(toup[1]))
skewness = str(np.asscalar(toup[2]))
kurtosis = str(np.asscalar(toup[3]))
cv = math.sqrt(float(variance)) / float(average) * 100
list_ = [
(
a,
c,
loc,
scale,
float(average),
float(variance),
cv,
float(skewness),
float(kurtosis),
)
]
listing.append((list_))
# print(
# "mean = ",
# str(average),
# ", variance = ",
# str(variance),
# "CV = ",
# str(cv),
# ", skewness = ",
# str(skewness),
# ", kurtosis = ",
# str(kurtosis),
# )
# print(
# "a = ", str(a), ", c = ", str(c), "loc = ", str(loc), ", scale = ", str(scale)
# )
Dm = pow((Tm - float(average)), 5)
Dcv = pow(Tcv - float(cv),2)
Ds = pow((Tk - float(skewness))*5,3.0)
Dk = (Ts - float(kurtosis))*10
# MinimizeThis = Dm + Dcv + Dk + Ds
# print(MinimizeThis)
# MinimizeThis = int(MinimizeThis * 10)
# print(MinimizeThis)
return Dm, Dcv, Ds, Dk
# return float(average), float(cv), float(skewness), float(kurtosis)
Tm = 22
Tcv = 10
Ts = -0.43
Tk = 0.352
# problem = Problem(4, 4, 4)
problem = Problem(4, 4)
problem.types[:] = [Real(1, 100), Real(-100, 50), Real(-200, 0), Real(.2, 300)]
problem.constraints[:] = "==0"
problem.function = GammaDistribution
algorithms = [
NSGAII,
(NSGAIII, {"divisions_outer": 12}),
(CMAES, {"epsilons": [0.05]}),
GDE3,
IBEA,
(MOEAD, {"weight_generator": normal_boundary_weights, "divisions_outer": 12}),
(OMOPSO, {"epsilons": [0.05]}),
SMPSO,
SPEA2,
(EpsMOEA, {"epsilons": [0.05]}),
]
approach = GDE3
algorithm = approach(problem)
algorithm.run(200)
# print(algorithm.result)
print (Tm, Tcv, Ts, Tk)
for solution in unique(nondominated(algorithm.result)):
print(solution.variables, solution.objectives)
solution.objectives[0]
print(test)