Hello friends, Below is the optimization work. Even though I woked with fminsearch and similar tools, I cannot figure this out. Any help? Thank you very much. A & B & KEY are vectors of same length. the KEY is unknown. find the KEY such that minimize the function B-A(KEY).
clc;clear
A= [25 21.2 0.4 3.5 15 60 14 8.1 16.9 1.1];
KEY= [3 5 8 1 10 9 7 6 2 4];
B= A(KEY) + rand(1,10);

 채택된 답변

Walter Roberson
Walter Roberson 2022년 9월 27일

0 개 추천

You do not want to minimize B-A(KEY): those are vectors and you cannot minimize a vector.
A= [25 21.2 0.4 3.5 15 60 14 8.1 16.9 1.1];
KEY= [3 5 8 1 10 9 7 6 2 4];
B= A(KEY) + rand(1,10);
Kp = perms(KEY);
values = sum((B - A(Kp)).^2,2);
[bestresult, idx] = min(values);
bestresult
bestresult = 3.4348
Kp(idx,:)
ans = 1×10
3 5 8 1 10 9 7 6 2 4

댓글 수: 5

Ali
Ali 2022년 9월 27일
Thank you so much dear Walter, The code above is actually the simplified version of the main code where the key has the length of 44, I do not think my laptop can run perms for such huge data.
Walter Roberson
Walter Roberson 2022년 9월 27일
편집: Walter Roberson 2022년 9월 27일
Do you need the absolute best match, or would a "reasonably good" match be useful?
If you only needed a "reasonably good" match then you could use ga() with custom creation and integer constraints that enforced that the trial values were an integer permutation. But ga() often does not find the global minima -- for example in a Traveling Salesman problem it might get stuck with two nodes exchanged when the difference in total distance between the two is not large.
Ali
Ali 2022년 9월 27일
편집: Walter Roberson 2022년 9월 28일
The code is actually much complicated than that. The answer KEY is unique, it is not mathematically possible of having more than one answer, the problem I faced is how to define the key with initial values in optimization tools? In other words, we tell the optimization to converge between upper and lower bounds but it has to understand the integers are unique, if x(2) for example is 3, no other x can have this value.
You have phrased this as a minimization, not as a key recovery. minimization implies that potentially after the noise has been added, that a different key than the initial key is now the best one.
Walter Roberson
Walter Roberson 2022년 9월 28일
That's why I was talking about custom functions to enforce integer permutation.
Ali
Ali 2022년 9월 28일
Thank you so much, I will try ga.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2022년 9월 28일

0 개 추천

댓글 수: 1

Ali
Ali 2022년 11월 27일
Thank you for late reply. I saw your comment now, I appreciate and take a look.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

태그

질문:

Ali
2022년 9월 27일

댓글:

Ali
2022년 11월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by