拉丁超立方——样本点空间转换

由拉丁超立方原理可知,在使用拉丁超立方采样采集的样本点的取值范围都在[0,1]区间内,而在实际问题中,设计变量的取值范围并不一定会在[0-1]区间内,为了保持在[0,1]区间内拉丁超立方采集的样本点的空间分布不变,如何将样本点转换到实际空间。

由于样本点每一维都是独立的,因此只分析一维,多维可以直接扩展矩阵。假设样本点在[1,5]区间需要转换到[5,10]区间,且一个样本点x在[1,5]区间取值是2。

一种方法是从取值范围左端点处考虑,可知这个样本点在[1,5]区间占比(2-1)/(5-1)=1/4,因此该样本点转换后在[5,10]空间也应该占比1/4,因此转换后的位置为5+(10-5)*(1/4)。另一种方法则从取值范围右端点处考虑,在[1,5]空间内x离右端点距离占比(5-2)/(5-1)=3/4,因此准换到[5,10]后距离右端点10的距离占比也应该是3/4,因此转换后的位置为10-(10-5)*(3/4)。

下面列出根据这个思想写的matlab代码

x是样本点矩阵,fromdomain是转换前所在的空间取值范围,toDomain是转换后所在空间取值范,这个srgtScaleVariable函数是根据取值范围右端点出考虑的方法。

function [xstar] = srgtsScaleVariable(x, fromDomain, toDomain)

[npoints, ndv] = size(x);

rangeFrom = fromDomain(2,:) - fromDomain(1,:);   %两个空间的范围值

rangeTo   = toDomain(2,:)   - toDomain(1,:);

a = rangeTo./rangeFrom;
b = toDomain(2,:) - a.*fromDomain(2,:);

xstar  = zeros(npoints, ndv);

for counter01 = 1 : npoints
    
    % mapping
    xstar(counter01,:) = a.*x(counter01,:) + b;
    
    % make sure that points in the lower bound will not suffer with MATLAB
    % precision
    % 检查样本点是否是端点处
    mask = x(counter01,:) == fromDomain(1,:); % detects if point has any variable in the lower boud,逻辑值
    xstar(counter01,:) = mask.*toDomain(1,:) + ...
        (~mask).*xstar(counter01,:);  %如果是的话,则转换后在转换后的空间端点处,否则是上面表达式值。
    
    % make sure that points in the upper bound will not suffer with MATLAB
    % precision
    mask = x(counter01,:) == fromDomain(2,:); % detects if point has any variable in the upper boud
    xstar(counter01,:) = mask.*toDomain(2,:) + ...
        (~mask).*xstar(counter01,:);
    
end

return

 

x是输入样本点,normspace是当前空间取值范围,signspace是转换后的空间取值范围。Scalevariable函数是根据从取值范围左端点处考虑的方法。

function [x_end] = ScaleVariable(x, normspace, signspace)
[npoints,ndv]=size(x);
a=normspace(2,:)-normspace(1,:);
b=signspace(2,:)-signspace(1,:);


x_end=zeros(npoints,ndv);
for i=1:npoints
    x_end(i,:)=(((x(i,:)-normspace(1,:))./a).*b)+signspace(1,:);   
end
return

检查两种方法

clear
clc

physicalspace = [-5  0;  % lower bound
    10 15]; % upper bound

normalizedspace = [0  0; % lower bound
    1  1]; % upper bound

% create points in the normalized space
P = [0.0  0.0
    0.5  0.5
    1.0  1.0
    0   0
    1   1];

% map P to the physical space
X = srgtsScaleVariable(P, normalizedspace, physicalspace)
X1= ScaleVariable(P, normalizedspace, physicalspace)

两种方法的对比结果

拉丁超立方采样后的样本转换到实际空间

clear
clc


npoints=10;  %样本点数
ndv=2;  %维数
LHS = srgtsDOELHS(npoints, ndv);  %拉丁超立方采样
physicalspace = [-5  0;  % lower bound
    10 15]; % upper bound

normalizedspace = [0  0; % lower bound
    1  1]; % upper bound

% map LHS to the physical space
X = srgtsScaleVariable(LHS, normalizedspace, physicalspace);
subplot(1,2,1);
scatter(LHS(:,1),LHS(:,2),'filled');
subplot(1,2,2);
scatter(X(:,1),X(:,2),'filled');

拉丁超立方函数代码 

function LH = srgtsDOELHS(npoints, ndv)

LH = [];

for c2 = 1 : ndv
    LH = [LH, randperm(npoints).'];
end

    
LH = srgtsScaleVariable(LH, ...
                        [ones(1,ndv); npoints*ones(1,ndv)], ...
                        [zeros(1,ndv); ones(1,ndv)]);

return

 

 拉丁超立方采样转换到实际空间后的分布对比,可以看到并没有影响空间分布性。

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值