이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Enforce condition in lsqnoneg
조회 수: 4 (최근 30일)
이전 댓글 표시
sanjay
2024년 7월 5일
I working on inverse problem which is rank deficient and for that i am using tikhonov regularization , for minization i am using lsqnoneg to resolve it which is giving me good result but now i have to enforce a condition in each iteration of minimzation of lsqnoneg, however lsqnoneg oterations are automatic i cant control it manually althohg i used fmincon but it is not giving me the same results can some one help what algorithm should i use so that i can enforce my conditon during optimization iterations and it gives results like lsqnoneg,
Tikh_Output.IA_recovered_line_1 = lsqnonneg(Combined_Coeff_Matrix,Combined_projection_line_1);
Tikh_Output.IA_recovered_line_2 = lsqnonneg(Combined_Coeff_Matrix,Combined_projection_line_2);
here is my code
댓글 수: 18
sanjay
2024년 7월 5일
I want apply condition that in every iteration the lsqnoneg recover my x it is bascially a 1601x1 matrix , it checks if any value between 1 to 1600 is less than 1601th pixel , if yes then it should make it equal to 1601th values,i also used options = optimset('OutputFcn', @enforce_Condition); this option to call the condition but unfortunately in matlab lsqnoeng doesnot support it
Torsten
2024년 7월 5일
Shouldn't this be equivalent to imposing the 1600 conditions
x(1) >= x(1601)
x(2) >= x(1601)
...
x(1600) >= x(1601)
?
sanjay
2024년 7월 5일
yes but i dont want apply this condition after i recovered all my values from lsqnoneg but i want to apply this condition during each iteration of lsqnoneg could you please help
John D'Errico
2024년 7월 5일
If the problem is singular though, the solution is not unique. So that fmincon does not give the same results as lsqnonneg is meaningless, because that is fully expected.
sanjay
2024년 7월 5일
Then what should i do to enforce condition during optimization which solver i should use?
sanjay
2024년 7월 5일
This is how i have applied but results are not fine also it converges too early
A = [eye(1600), -ones(1600,1)];
b = zeros(1600, 1);
lb = zeros(1601, 1);
x0 = zeros(1601, 1);
[x, resnorm, residual, exitflag, output] = lsqlin(Combined_Coeff_Matrix, Combined_projection_line_1, ...
A, b, [], [], lb, [], x0);
Torsten
2024년 7월 5일
Your matrix A is incorrect ; the conditions you set would be
x(1) <= x(1601)
x(2) <= x(1601)
...
x(1600) <= x(1601)
sanjay
2024년 7월 5일
Then how should I put the A values so that i satisfies my conditon in which i want to check during each optimization operation that if from 1 to 1600 any of the vlaue is less than 1601th value then it shoud assign that variable the value of 1601 otherwise it should not do anything
sanjay
2024년 7월 5일
This not giving me specific reuslts, can you tell this constraint checks the condtion on each iteration of optimization when x recovers?
Torsten
2024년 7월 5일
편집: Torsten
2024년 7월 5일
At least the solution should satisfy the constraints. It is the case for all optimization algorithms that constraints can be violated during the computational process (except for bound constraints, I guess). You should at least supply an initial guess x0 that satisfies the constraints if this is that important for you.
What do you mean by "This not giving me specific reuslts" ? Do you mean "satisfactory results" ?
sanjay
2024년 7월 6일
Satisfactory results mean the task i want from this is to check the recovered value of my solution in each iteration should check whether my values from 1 to 1600 are less than the alst value of my solution if yes then it should assign them the vlaue of 1601th to then otherwise leave then as it is. this in not happening in this case
Torsten
2024년 7월 6일
편집: Torsten
2024년 7월 6일
I know what "satisfactory results" mean, but you wrote "specific reuslts" that I couldn't understand.
Including the contraint A*x <= b should produce a solution that satisfies x(1) >= x(1601),...,x(1600) >= x(1601). Usually the way how you arrive at this solution (directly or by checking in each iteration) is irrelevant. But for some reason that I don't understand this doesn't seem to be the case here.
There is no optimization tool in which you can directly change optimization variables depending on some conditions during the optimization process. You can only change constraints or the objective function. If you want to do this, you have to use "fmincon" - the problem description for "lsqlin" is fixed right from the beginning and cannot be altered during the computational process.
sanjay
2024년 7월 6일
Okay i explain what i am trying to do, i am working on an inverse problem and i have create my coefficent matrix and measurement using this i am trying to recover my X, i am successfull in doing so using lsqnoneg, but i have been given a task that i have to apply this condition in each optimization iteration to chek if some of the vlaues recovered in each iteration of optimization falls below the last value of the solution then make it equal to last value otherwise leave it as it is? do you think this constraint based approach is doing so or i should use fmincon
Torsten
2024년 7월 6일
편집: Torsten
2024년 7월 6일
As I said: You can't change solution variables during the optimization process in MATLAB optimizers. The changes must be initiated by your definition of the objective function or by the definition of your constraints. So neither "lsqlin" or "fmincon" can help you in this respect.
But if you want the optimal solution that satisfies x(1) >= x(1601), ... , x(1600) >= x(1601), then the constraint-based solution with "lsqlin" should be correct in my opinion (althogh the result you get might not be as expected).
Do you get the same results with lsqnonneg and lsqlin if you work without the A*x <= b constraint and only set the lower bounds vector lb to zeros(1601,1) ?
sanjay
2024년 7월 6일
Yes i tried without constraint then the reconstruction results are coming same in lsqin and lsqnoneg,
채택된 답변
Matt J
2024년 7월 6일
편집: Matt J
2024년 7월 6일
Suppose your original problem is,
Rewrite the problem by making the change of variables x=Q*z where z>=0 and
Q=eye(1601); Q(:,end)=1;
Then the problem becomes,
which you can solve with lsqnonneg. After solving for z, you can retrieve x with x=Q*z.
댓글 수: 22
sanjay
2024년 7월 6일
Hi i am sorry i am not understanding it ? how can i use this in lsqnoneg there no ption for constraint , are you talking about constraint here x=Q*z ? can you explore or tell me in more easy way
sanjay
2024년 7월 6일
I tried this method its working but can you let me know why it will not change the result
Torsten
2024년 7월 6일
편집: Torsten
2024년 7월 6일
I tried this method its working but can you let me know why it will not change the result
Because the underlying mathematical problem is the same. The only difference is how it is formulated for the solver.
If you get different results if you solve
min: ||C*x-d||
under the constraints
A*x <= b
x >=0
with lsqlin and
min: ||C*Q*z-d||
with lsqnonneg and compute x from
x = Q*z
after getting the solution for z, then C is most probably rank-deficient, but at least ||C*x-d|| and ||C*Q*z-d|| from the two computations should be the same.
sanjay
2024년 7월 7일
Yes my C is basically rank deficient but my question is it enforcing the conditon during my optimization ? is it checking every everytime whether x recovering in iteration is greater than or equal to last value of x? because that is what is want
Matt J
2024년 7월 7일
편집: Matt J
2024년 7월 7일
but my question is it enforcing the conditon during my optimization ?
When optimizing over z with lsqnonneg, the only condition being enforced is z>=0.
However, for any z>=0, you can readily verify that x=Q*z will satisfy your desired boundary conditions on x. The converse is also true. Starting with any x satisfying the boundary conditions, we can construct a corresponding z>0 by doing,
which is in fact the same as z=Q\x;
Torsten
2024년 7월 7일
편집: Torsten
2024년 7월 7일
is it checking every everytime whether x recovering in iteration is greater than or equal to last value of x?
Your inputs to "lsqlin" or "lsqnonneg" are constant (C,A,b,lb,ub) and don't change during the solution process. So it is completely irrelevant if your constraints will be violated or not during the computation.
If you could interfere in the solution process and change the inputs depending on an intermediate result, things would be different.
sanjay
2024년 7월 7일
Then what about the Q we multiplied with z, is it not enforcing the condition , here in whole discussion is it happening that my X solution vlaues are checked whether these values are greateter than or equal to last vlaue of my X in each optimization stage? as i got the result in which all those values which were less than last value of X have been replace with last vlaue of X , but i need to is it applying thr condition after recovering all the vlaues of X or is it applying during optimization
Torsten
2024년 7월 7일
편집: Torsten
2024년 7월 7일
You tell the solver that you want to find an X that minimizes ||C*X-d||, and the solution vector X should not be arbitrary, but satisfy that all components of X should be greater or equal than the last component, and the solver computes such an X. This is solved as an integrated problem - thus the condition is not applied after recovering x(1),...,x(1600), but during the optimization because the value of x(1601) influences ||C*X-d||. Or is the last column of C a zero column ?
Matt J
2024년 7월 7일
편집: Matt J
2024년 7월 7일
Then what about the Q we multiplied with z, is it not enforcing the condition
Yes. Again, for any z>=0, the x obtained by doing x=Q*z will satisfy your desired boundary condition.
Conversely also, for any x satisfying your boundary condition, the corresponding z=Q\x will satisfy z>=0. They are in a 1-1 relationship.
sanjay
2024년 7월 7일
No my C is coeeficeint matrix and d is my measurements and i am applying this to recover my X, but now i wanted to apply the condition that during each iteration of optimization although this condition can be applied after recovering all the x , it checks whether my x vlaues are greater than or equal to zero but as there was not way to put direct condition during lsqnoeng function so i asked this question and you proposed this solution which is giving me fine results but wanted to confrim that this solution is checking my relavent condition during optimization ,
Torsten
2024년 7월 7일
now i wanted to apply the condition that during each iteration of optimization although this condition can be applied after recovering all the x , it checks whether my x vlaues are greater than or equal to zero
??? Greater or equal zero ? I thought greater or equal x(1601) ?
Matt J
2024년 7월 7일
편집: Matt J
2024년 7월 7일
@sanjay, please indicate whether your comments are directed to me or to Torsten (or somebody else).
Regarding what is is happening during optimization: when lsqnonneg is used to optimize over z, it generates a sequence of iteration vectors z_i, i=0,1,2,... which, because of the particulars of lsqnonneg's algorithm, all satisfy z_i>=0 throughout the optimization. lsqnonneg does not know about x at all or do any manipulations in the space of x.
However, as we have discussed, since the sequence generated by lsqnnnoneg satisfies z_i>=0, then you could create a corresponding sequence x_i=Q*z_i which would satisfy your desired boundary conditions for all x_i.
Also, for the purposes of optimization, it is irrelevant whether your constraints are satisfied at every iteration of the optimization (even if in this case they are). As long as the z_i converges to an optimal solution for z (which it does), then the x_i will converge to an optimal solution for x, because the two problems are in a 1-1 relationship.
Torsten
2024년 7월 7일
sanjay
2024년 7월 7일
Yes @Matt J you are right i have the suspect that whether my condition is being checked during optimization or after optimization as i have very little knowlede about these optimization techniques , i am sorry for the incoveneince i am creating, but as x = Qz is calcualted after reovering z so i am afraid this condition is checked after the end of all optimization happend can you please clear me
Matt J
2024년 7월 7일
편집: Matt J
2024년 7월 7일
could please let me know where my condition on X is exactly cheked ... other than z>=0
@sanjay I don't understand the question. I already told you in my last comment that the condition on X is never explicitly checked. Only the (entirely equivalent) condition z>=0 is checked.
sanjay
2024년 7월 7일
let me explain again z>=0 is checked but the whole discussion is i am enforcing the condition which X(1)>=X(1601),X(2)>=X(1601),,,,,,,,X(1600)>=X(1601) where this condition is satisfied using Q and z approach? and if i dont use this Q and z approach and recover my X and then apply this condition, so do you think they are same or they both approach has difference?
Torsten
2024년 7월 7일
편집: Torsten
2024년 7월 7일
Both approaches (using lsqlin with lb = 0 and A*x <= b or using lsqnonneg for optimization in z where x is determined after the optimization as x = Q*z) are correct and should give the same result (at least ||C*x-d|| and ||C*Q*z-d|| should be the same)). Test it.
If you don't trust in the appoach with the coordinate transformation
z(i) = x(i) - x(1601) (1 <= i <= 1600)
z(1601) = x(1601)
or explicitly rewritten in x
x(i) = z(i) + z(1601) (1 < = i <= 1600)
x(1601) = z(1601)
or rewritten in matrix form
x = Q*z
use the approach in x.
I don't know what you mean by "recover my X and then apply this condition".
Matt J
2024년 7월 7일
편집: Matt J
2024년 7월 7일
i am enforcing the condition which X(1)>=X(1601),X(2)>=X(1601),,,,,,,,X(1600)>=X(1601) where this condition is satisfied using Q and z approach?
Yes. Torsten already said it, but just for emphasis, the condition X(1)>=X(1601),X(2)>=X(1601),,,,,,,,X(1600)>=X(1601) means the very same thing as the condition z>=0. Therefore, if you have optimized over z subject to z>=0, you have done the very same thing as when you optimize over X subject to the constraints X(1)>=X(1601),X(2)>=X(1601),,,,,,,,X(1600)>=X(1601).
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)