我正在使用pyDOE包生成DOE,然后使用此函数将其转换为正态分布:
def Transform_DOE(means,std,DOE):
import numpy as np
import sys
from scipy.stats.distributions import norm
p=np.shape(DOE)[1]#dimension of the DOE
if np.shape(means)[0]==1:
means=means*p
elif p!=np.shape(means)[0]:
print 'the dimensions of the DOE is not consistent with that of "means"!'
sys.exit(1)
if np.shape(std)[0]==1:
std=std*p
elif p!=np.shape(std)[0]:
print 'the dimensions of the DOE is not consistent with that of "std"!'
sys.exit(1)
if np.max(DOE)>1 or np.min(DOE)<0:
print 'The input DOE should be in [0,1]'
sys.exit(1)
DOEtrf=np.mat(DOE)
for i in xrange(p):
DOEtrf[:,i]=norm(loc=means[i], scale=std[i]).ppf(DOEtrf[:, i])
return DOEtrf
示例运行如下:
DOEtrf=Transform_DOE([1,2,3],[0.1,0.3,0.2],DOE)
当我运行此代码时,DOE将会改变!我使用指针还是我不知道的东西?
我使用Anaconda for python 2.7,这就是我生成DOE的方法:
def DOE_LHS(n,p,Min,Max):
import numpy as np
import pyDOE
import sys
if type(Min)!=list or type(Max)!=list :
print "Min and Max should be lists!"
sys.exit(1)
elif np.size(Min)!=p or np.size(Max)!=p:
print "The dimension of Min and Max is not consistent with p!"
sys.exit(1)
Min=map(float,Min) #or Min=[float(i) for i in Min]
Max=map(float,Max)
Min=np.array(Min)
Max=np.array(Max)
Range=Max-Min
DOE=pyDOE.lhs(p,samples=n,criterion="centermaximin",iterations=1000)
DOE=DOE*np.tile(Range,(n,1))+Min
return DOE
提前感谢。