我已实现了压缩算法,假定我放弃,要求:
myCompression(data, th)
<>th>/em>参数在0到1之间。 有时这个数字实际上可能很小,例如212.19e-013。
num = length(myCompression(data, th))
gave me the number of data remains after compression. If I want num to be bigger, I need to choose a lower th parameter. Viceversa, if I want higher num, I have to choose lower th.
Now the problem is: I want to find a proper th such that num is equal to a target number that I choose. As you know, find th is really long work, and I would realize a brute force algorithm that finds th that satisfy my need. I ve write this:
target = 304;
th = 2.49e-011;
num = 0;
while(num~=target)
num = length(MCSimplify3(time, latitudes, longitudes, th));
disp(horzcat( tol: , num2str(th), num: , num2str(num)));
if (num>target)
th = th+(rand()*th);
else
th = th-(rand()*th);
end
th = abs(th);
end
以前的文字开始,但从未达到目标。 问题Ippose是由于添加或细分的(rand()*th)
过于庞大,因此时间超过了目标,时间低于一个。 因此,正如你可以在这里看到的那样,这种局面继续推移,而且永远无法取得结果:
tol: 2.67e-012 num: 333
tol: 4.0685e-012 num: 303
tol: 2.9909e-012 num: 320
tol: 3.1953e-012 num: 316
tol: 4.5895e-012 num: 298
tol: 3.7916e-012 num: 308
tol: 3.8906e-012 num: 308
tol: 7.6049e-012 num: 257
tol: 4.3302e-012 num: 299
tol: 1.6646e-013 num: 624
tol: 2.9337e-013 num: 562
tol: 2.9553e-013 num: 561
tol: 4.965e-013 num: 503
tol: 8.47e-013 num: 448
tol: 1.3934e-012 num: 391
tol: 2.163e-012 num: 350
tol: 2.6348e-012 num: 335
tol: 4.6699e-012 num: 296
谁能帮助我?