optimvalues
为优化问题创建值
描述
例子
创造Initial Points for Problem-Basedga
为创建初始点ga
(genetic algorithm solver) in the problem-based approach, create an优化价值
object usingoptimvalues
。
用Rosenbrock的功能作为适应性(目标)函数创建针对2D问题的优化变量。
x = optimvar("x",下部= -5,upperbound = 5);y = optimvar("y",下部= -5,upperbound = 5);rosenbrock =(10*(y -x。^2))。^2 +(1 -x)。^2;prob = optimproblem(Objective = RosenBrock);
创造100 random 2-D points within the bounds. The points must be row vectors.
RNGdefault%可再现性xval = -5 + 10*rand(1,100);yval = -5 + 10*rand(1,100);
创建初始点值对象。因为您不计算健身值,所以值为NaN
在显示中。
vals = optimvalues(prob,x = xval,y = yval)
阀= 1x100 OptimizationValues vector with properties: Variables properties: x: [3.1472 4.0579 -3.7301 4.1338 1.3236 -4.0246 -2.2150 ... ] y: [-3.3782 2.9428 -1.8878 0.2853 -3.3435 1.0198 -2.3703 ... ] Objective properties: Objective: [NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ... ]
Solve the problem usingga
starting from the initial point阀
。放ga
人口为100的选择。
opts = optimoptions(“ GA”,PopulationSize=100); [sol,fv] = solve(prob,vals,Solver=“ GA”,选项=选择)
使用GA解决问题。优化终止:健身价值的平均变化小于选项。功能耐力。
sol =带有字段的结构:X:1.0000 Y:1.0000
FV = 4.1061E-09
ga
returns a solution very near the true solutionx = 1,y = 1
和a fitness value near0
。
创造Initial Values for Problem-Based代理
为创建初始点代理
在具体问题具体分析的方法, create an优化价值
object usingoptimvalues
。
创造optimization variables for a 2-D problem with Rosenbrock's function as the objective function.
x = optimvar("x",下部= -5,upperbound = 5);y = optimvar("y",下部= -5,upperbound = 5);rosenbrock =(10*(y -x。^2))。^2 +(1 -x)。^2;prob = optimproblem(Objective = RosenBrock);
创造constraints that the solution is in a disc of radius 2 about the origin and lies below the line y = 1 + x.
disc = x^2 + y^2 <= 2^2; prob.Constraints.disc = disc; line = y <= 1 + x; prob.Constraints.line = line;
创造40 random 2-D points within the bounds. The points must be row vectors.
RNGdefault%可再现性N = 40; xval = -5 + 10*rand(1,N); yval = -5 + 10*rand(1,N);
Evaluate Rosenbrock's function on the random points. The function values must be a row vector. This step is optional. If you do not provide the function values,代理
评估该点的目标函数(xval,yval)
。当您具有函数值时,您可以通过提供值作为数据来节省求解器的时间。
fval = zeros(1,N);fori = 1:N p0 = struct('X',xval(i),'y',Yval(i));fval(i)= evaluate(Rosenbrock,p0);end
评估这些点的约束。约束值必须是行向量。此步骤是可选的。如果您不提供约束值,代理
评估点的约束函数(xval,yval)
。
discval = zeros(1,N); lineval = zeros(1,N);fori = 1:N p0 = struct('X',xval(i),'y',Yval(i));discval(i)=不可行(DISC,P0);lineVal(i)=不可行(线,p0);end
创建初始点值对象。
vals = optimvalues(prob,x = xval,y = yval,objective = fval,disc = discval,line = lineVal)
vals = 1x40具有属性的优化价值矢量:变量属性:x:[3.1472 4.0579 -3.7301 4.1338 1.3236 -4.0246 -2.2150 ...Objective: [1.1067e+04 3.1166e+04 1.2698e+04 1.9992e+04 2.3846e+03 ... ] Constraints properties: disc: [6.2803 13.8695 16.9638 21.8023 7.5568 12.2078 1.2024 0 ... ] line: [0 05.3853 0 0 2.9222 0.6709 0 0 0 0 0.1841 0 0 0 0 0 0 2.5648 ...]
Solve the problem using代理
starting from the initial point阀
。
[sol,fv] = solve(prob,vals,Solver="surrogateopt")
使用代理解决问题。
替代之所以停止,是因为它超过了“选项”设置的函数评估限制限制。
sol =带有字段的结构:X:0.7961 y:0.6340
FV = 0.0416
代理
returns a solution somewhat near the true solutionx = 1,y = 1
具有目标函数值接近0
。
输入参数
概率
—优化问题
优化问题
object
优化问题,指定为优化问题
目的。创造概率
usingoptimproblem
。
To obtain useful output fromoptimvalues
, you must also include some data in name-value arguments.
Name-Value Arguments
将可选的参数对Name1=Value1,...,NameN=ValueN
, 在哪里Name
is the argument name and价值
是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。
例子:瓦尔= optimvalues(x=xvals,y=yvals)
dataName
—可变,命名目标或命名约束的数据
真正的双重array
变量,命名为目标或命名约束的数据指定为真实的双阵列。指定变量的所有数据名称。目标和约束函数名称是可选的。
When you specifynval
点,每个值的值dataName
argument must have the following dimensions.
概率。property.name |
尺寸(值) |
---|---|
Scalar or vector | numel(prob.property.name) -经过-nval |
矩阵或数组 | size(prob.property.name) -经过-nval |
特别是dataName
是向量,是dataName
参数是一个矩阵nval
columns. For example, if the'X'
variable is a row vector of length 2, andnval
is 3, then the'X'
可变规范可能是:
瓦尔= optimvalues(概率,'X',[1 2 3;4 5 -6]);
该规范意味着'X'
takes the three values[1,4]
,[2,5]
, 和[3,-6]
。
例子:对于标量'X'
和两元素行矢量'y'
和NVAL = 2
:val = optimValues(prob,x = [5,3],y = [1 2; 3 4])
。输出瓦尔
has two values:x = 5,y = [1 3]
和x = 3,y = [2 4]
。
数据类型:双倍的
客观的
—价值s for unnamed objective function
真正的双重array
未命名的目标函数的值,指定为真实的双阵列。值的大小与dataName
。
您可以通过两种方式指定多个目标函数的值以优化问题:
The
客观的
property of the optimization problem is a function handle, where the function returns a vector or array. In this case, specify the value as a matrix. Each matrix row represents the values of one objective at the various points. Each column represents the values of the various objectives at one point.The
客观的
优化问题的属性具有多个命名目标。在这种情况下,使用其名称作为一个dataName
争论。
这些求解器使用任何提供的目标函数值:
ga
gamultiobj
paretosearch
代理
例子:For one objective and two points,瓦尔= optimvalues(概率,x=[3,5],Objective=[exp(3)+1,exp(5)-1])
数据类型:双倍的
约束
—价值s for unnamed constraint function
真正的双重
价值s for an unnamed constraint function, specified as a real double array. The size of the values is the same as indataName
。
You can specify values of multiple constraint functions for optimization problems in two ways:
The
约束
property of the optimization problem is a function handle, where the function returns an array. In this case, specify the values as an array with one more dimension than the function returns.The
'Constraints'
优化问题的属性具有多个命名约束。在这种情况下,使用其名称作为一个dataName
争论。
These solvers use any supplied nonlinear constraint function values:
paretosearch
代理
These solvers ensure that linear constraints are satisfied at all iterations or for all population members:
ga
gamultiobj
paretosearch
模式搜索
代理
例子:对于两个点和三个约束,val = optimValues(prob,x = [3,5],客观= [exp(3)+1,exp(5)-1],约束= [4 5; -7 -2; 0.2 12])
数据类型:双倍的
Output Arguments
Version History
See Also
Topics
- Specify Start Points for MultiStart, Problem-Based(Global Optimization Toolbox)
- 指定基于问题的替代的起点和值(Global Optimization Toolbox)
- Problem-Based Optimization Workflow
matlab命令
You clicked a link that corresponds to this MATLAB command:
通过在MATLAB命令窗口中输入该命令。Web浏览器不支持MATLAB命令。万博1manbetx
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
美洲
- AméricaLatina(Español)
- 加拿大(英语)
- 美国(英语)