Optimize vector position and values to form another vector.

4 views (last 30 days)
Hi, I am stuck with a problem which I do not know how to proceed. I have 2 vectors:
a = [1 2 3 2 1];
b = zeros(1, 11);
I want to find the best placement (maximum 3 or 4) and weighting of vector 'a' inside vector 'b' so that the values of vector b have the least standard deviation possible.
A possible solution could be:
b(1:5) = a * 2;
b(4:8) = a * 1.5;
b(6:10) = a * 1.5;
b(9: 11) = a * 2;
However, if it were that simple to figure, I wouldn't need help :-). Please, leave a suggestion as to how this could be tackled. Thank you.
  6 Comments
Charles
Charles on 4 Jun 2011
Hi, there will be overlaps with the placements. This concept is captured in the example that I gave as there is overlap between the first and second (1:5 and 4:8) placement, and between the second and third placement (4:8 & 6:10). As for b(11) being equal to 0, that was an initial omission which I have corrected. I hope it is clearer.

Sign in to comment.

Answers (2)

Andrew Fowler
Andrew Fowler on 3 Jun 2011
You could set up your problem in a couple of ways. The easiest would be by brute force using nested loops, though it may not be the best:
a = [1 2 3 2 1]
b = zeros(1,11)
% Make a guess that you know is too high for the standard deviation
devb = 50
% There's only 7 places that a can go into b, so we make
% a for loop that has 7 increments.
for i = 1:7
b(i:i+4) = a; % You dimensions have to match. See what I did?
% The syntax here is inital_value:increment:final_value,
% and you get a vector that goes from initital_value
% to final_value by steps of increment.
for j = 1:0.1:2
c = b*j; % This is weighting as you presented it in your question,
% but I think it might not be right.
% if the values that have been run through the loops give
% you a lower deviation value than the others, this statement
% will overwrite the previous value of deviationb with the current
% value, and save the values of i and j so you know what your
% solution was.
if std(c) < deviationb
deviationb = std(c);
solutioni = i
solutionj = j
end
end
end
This code worked when I ran it, but I think you need to take another look at your problem.
  4 Comments
Charles
Charles on 4 Jun 2011
Hi Andrew, thanks for your suggestion. H/v, the example doesn't work because :
1. All the values of b must be non-zero.
2. Maximum placement points is 3 or 4.
3. Each placement point has its own weight.
Thanks.

Sign in to comment.


Sean de Wolski
Sean de Wolski on 3 Jun 2011
For the above example and any other permutation defined by it the best case scenario is all four weights to equal zero and the positions equal to whatever. That is, your 'b' vector is not completely full b(11) is still zero. As long 'b' can have non-a values, then there's no reason to have non-zero values since this WILL be the minimum standard deviation.
Assuming, you want to constrain all 'b' to not also be in 'a' it should be possible to set it up for fmincon, as an optimization problem of six variables: two positions and four weights, the positions constrained to integers in the middle so that the middle is covered. The boundaries are fixed since you would NEED one position to be 1, and the other to be length(b)-length(a)+1.
Just a few ideas hopefully someone can build on.
  1 Comment
Charles
Charles on 4 Jun 2011
Yea, all values of 'b' should be non-zero. Also, the number of positions and weightings are the same. Thanks foe ur comment.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!