凸随机值的最小化 [英] Minimization of convex stochastic values
问题描述
我有一个等距变量(假设values=0:1e-3:1
).我想从最接近统一随机值(假设x=rand
)的values
中获取值及其对应的索引.
I have a variable of equidistant values (suppose values=0:1e-3:1
). I want to get the value and its correspondent index from values
which is closest to a uniformly random value (suppose x=rand
).
我可以做[value,vIdx]=min(abs(values-x))
,这是我能做的最简单的最小化. 不幸的是,min
函数不会从数据的一个属性(即凸的)中获益.我不需要搜索所有索引,因为一旦找到不小于前一个索引的索引,我便找到了全局最小值.话虽如此,我不想用matlab min函数代替一个循环,具体取决于它与我将要开始的值之间的距离,该循环会更慢.有很多方法可以用作黄金分割,但是我不确定使用matlab fmincon是否会比min
方法更快.
I could do [value,vIdx]=min(abs(values-x))
, which would be the simplest minimization I could do. Unfortunately the min
function won't take advantage from one property from the data, that is to be convex. I don't need to search all indexes, because as soon as find an index that is no more lesser than the previous I've found the global minimum. Said that, I don't want to substitute the matlab min function for a loop that would be slower depending on how distant it is from the value I will start. There are many methods that could be used, as the golden section, but I am not sure if using matlab fmincon would be faster than the min
method.
有人比使用所述的min
方法更快地获得所需值的任何提示/想法吗?有空时我会检查时间表现,但是如果有人知道先验答案很好,请告诉我.
Does anyone have any hints/ideas how to get the required value faster than using the described min
method? I'll check the time performance when I have time, but if someone knows a good answer a priori, please let me know.
可能的应用程序:捕捉到最近的图形数据
Possible Application: Snap to nearest graphic data
推荐答案
由于您的点是等距的,因此可以使用值x
来找到索引:
Since your points are equidistant you can use the value x
to find the index:
vIdx = 1+round(x*(numel(values)-1));
这个想法是,您将间隔[0, 1]
分成大小相等的numel(values)-1
个间隔.现在,通过将x
乘以该数字,您可以将间隔映射到[0, numel(values)-1]
,在此处将点映射到整数值.现在,使用round
可以得到最接近的一个,通过加1可以得到MATLAB所需的基于1的索引.
The idea is that you are dividing the interval [0, 1]
into numel(values)-1
equally sized intervals. Now by multiplying x
by that number you map the interval to [0, numel(values)-1]
where your points are mapped to integer values. Now using round
you get the closest one and by adding 1 you get the one-based index that MATLAB requires.
这篇关于凸随机值的最小化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!