主要内容

本页采用了机器翻译。点击此处可查看英文原文。

CustomStartPointSet

自定义起点

说明

CustomStartPointSet 是一个矩阵的对象包装器,其行代表 MultiStart 的起点。

创建对象

描述

tpoints = CustomStartPointSet(ptmatrix)ptmatrix 矩阵生成 CustomStartPointSet 对象。ptmatrix 的每一行代表一个起点。

示例

输入参量

全部展开

起点,指定为矩阵。ptmatrix 的每一行代表一个起点。

示例: randn(40,3) 创建了 3 维的 40 个起点。

数据类型: double

属性

全部展开

此 属性 为只读。

起点的数量,指定为正整数。NumStartPointsptmatrix 中的行数。

示例: 40

数据类型: double

此 属性 为只读。

每个起点的维度,指定为正整数。StartPointsDimensionptmatrix 中的列数。

StartPointsDimensionproblem.x0 中的元素数量相同,后者是传递给 runproblem 结构体。

示例: 5

数据类型: double

对象函数

list列出起点

示例

全部折叠

创建一个具有 64 个三维点的 CustomStartPointSet 对象。

[x,y,z] = meshgrid(1:4);
ptmatrix = [x(:),y(:),z(:)] + [10,20,30];
tpoints = CustomStartPointSet(ptmatrix);

tpointsptmatrix 对象中包含的 CustomStartPointSet 矩阵。

使用 tpointslist 对象中提取原始矩阵。

tpts = list(tpoints);

检查 tpts 输出是否与 ptmatrix 相同。

isequal(ptmatrix,tpts)
ans = logical
   1

若要生成一组与问题边界范围不同的伪随机起始点,请显式地创建这些点。例如,考虑以下涉及二维点的问题:

sixmin = @(x)(4*x(1)^2 - 2.1*x(1)^4 + x(1)^6/3 ...
    + x(1)*x(2) - 4*x(2)^2 + 4*x(2)^4);
lb = [-6,-12];
ub = [20,40];
x0 = [1,2];
problem = createOptimProblem("fmincon",...
    x0=x0,lb=lb,ub=ub,objective=sixmin);

假设您希望起始点位于区间

-5x15-4x24,

这比问题的边界要小得多。在此范围内生成 20 个点:

rng default % For reproducibility
N = 20; % Number of points
lbcustom = [-5,-4];
ubcustom = [5,4];
ptmatrix = lbcustom + rand(N,2).*repmat((ubcustom - lbcustom),N,1);

查看伪随机点的取值范围:

[minpt,maxpt] = bounds(ptmatrix)
minpt = 1×2

   -4.0246   -3.7453

maxpt = 1×2

    4.7059    3.6018

这些点几乎覆盖了整个范围。

将这些点放入一个 CustomStartPointSet 对象中。

tpoints = CustomStartPointSet(ptmatrix);

使用自定义起始点来解决该问题。

ms = MultiStart;
[x,fval, exitflag,output] = run(ms,problem,tpoints)
MultiStart completed the runs from all start points. 

All 20 local solver runs converged with a positive local solver exitflag.
x = 1×2

   -0.0898    0.7127

fval = 
-1.0316
exitflag = 
1
output = struct with fields:
                funcCount: 952
         localSolverTotal: 20
       localSolverSuccess: 20
    localSolverIncomplete: 0
    localSolverNoSolution: 0
                  message: 'MultiStart completed the runs from all start points. ↵↵All 20 local solver runs converged with a positive local solver exitflag.'

相比之下,如果使用来自边界范围内的 20 个伪随机点来求解该问题。

[x2,fval2,exitflag2,output2] = run(ms,problem,20)
MultiStart completed the runs from all start points. 

All 20 local solver runs converged with a positive local solver exitflag.
x2 = 1×2

    0.0898   -0.7127

fval2 = 
-1.0316
exitflag2 = 
1
output2 = struct with fields:
                funcCount: 1558
         localSolverTotal: 20
       localSolverSuccess: 20
    localSolverIncomplete: 0
    localSolverNoSolution: 0
                  message: 'MultiStart completed the runs from all start points. ↵↵All 20 local solver runs converged with a positive local solver exitflag.'

在此示例中,虽然两个解的目标函数值相同(以体现精度),但使用自定义起始点集的解所进行的函数计算次数要少得多。

版本历史记录

在 R2010a 中推出