Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decomposition - symmetric and anti-symmetric #62

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

AnhMai-bit
Copy link

Decompose a quadratic equation into symmetric, antisymmetric parts using its transpose.

Decompose a quadratic equation into symmetric, antisymmetric parts using its transpose.
@AnhMai-bit AnhMai-bit marked this pull request as draft April 24, 2022 18:53
@AnhMai-bit AnhMai-bit marked this pull request as ready for review April 24, 2022 18:53
@AnhMai-bit
Copy link
Author

@ehuan2 Hi Eric, for some reason I cannot add you as the reviewer. Please take a look at my work. Thank you.

@ndattani
Copy link
Member

Hi @AnhMai-bit the first thing I'll ask you to do is to remove all the comments and to put the definitions of your b variables all on one line. Please follow the format that were used to verify all other pages of the book. When you are done this, I can look at your code in more detail. You can just commit your newest changes to your patch-1 branch and this pull request will automatically get updates with whatever you commit to there.

Removed comments, all coefficients defined in one line.
@AnhMai-bit
Copy link
Author

Hi @ndattani, I updated the file just now.

@ndattani
Copy link
Member

Excellent! I'll take a deeper look on Tuesday. Now I'm preparing for a talk I'll be giving in Montreal tomorrow :)

@AnhMai-bit
Copy link
Author

Best of luck with your talk insert lucky clover ! Please also send me the link to the event if online registration is available, I would like to check it out :).

b1 = b(:,1); b2 = b(:,2); b3 = b(:,3); b4 = b(:,4);

f=b1.*b2 + b2.*b3 + b3.*b4 - 4*b1.*b2.*b3;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if this example had the following:

  • 1 linear term with a coefficient of +1,
  • 1 quadratic terms with a coefficient of +2,
  • 1 cubic term with a coefficient of -4, and
  • one quartic term with a coefficient of +2.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add that asap.


f_sym = (1/2)*(f + f.');
f_anti = (1/2)*(f - f.');

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes no sense. I don't see why you did f.'.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to make the transpose of the matrix.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ndattani my alternative solution is below. I will add that to the code if you approve.

% f_sym = (1/2)(f(b) + (1-f(b))
f_sym = (1/2)
(f + (1-f))

% f_anti = (1/2)(f(b) - (1-f(b))
f_anti = (1/2)
(f - (1-f))

Copy link
Member

@ndattani ndattani Apr 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone who has used MATLAB for as long as me would know that f.' does the transpose of f, but what made you think that it would be a good idea to do the transpose?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into how decomposition into symmetric and antisymmetric would be and I see there are 2 ways to do it. One this by adding and subtracting transpose into f, divided by two. Source: https://www.mathworks.com/matlabcentral/answers/401295-how-to-find-the-symmetric-and-skew-symmetric-part-of-a-specified-matrix.

The other is from the paper attached to the part in the book: https://www.maths.lth.se/matematiklth/vision/publdb/reports/pdf/kahl-strandmark-iccv-11.pdf. Notation: f - (1-transpose of f), divided by 2.

Can you please explain the difference between those 2? Thank you.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second example doesn't use the transpose.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like I confused myself somewhere, my apologies. I will fix that tomorrow since I currently have to prepare to move.

Updated new function, coefficients and calculation for symmetry and antisymmetry
Copy link
Member

@ehuan2 ehuan2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Anh Mai!

The example looks great, and you've almost verified it correctly! My suggestion is to check that the solutions for f_anti and f_sym actually work by:

  1. Creating new variables that represent the two that we want to check (ie f is the same as f_sym + f_anti)
  2. Assign these the values that we want to check for b1, b2, b3, b4. Remember that we want to check that the solution, ie the minimum values for them, are the same on both sides. A good way to check this is by taking a look at the pairwise example right above your changes.

@ehuan2
Copy link
Member

ehuan2 commented Apr 28, 2022

Oh I forgot to mention! Feel free to also edit the latex file with your example! Now that it's verified on MatLab, you can edit the Volume_1/Book_about_Quadratization.tex file. Let me know if you need help on this part, the setup can be a bit rough at times.

@AnhMai-bit
Copy link
Author

AnhMai-bit commented Apr 29, 2022

Thank you so much Eric. I will update it today. I will let you know on discord if I have more questions.

f_sym = (1/2)*(f + (1 - f));
f_anti = (1/2)*(f - (1 - f));

f_new = f_sym + f_anti;

LHS=min(reshape(f_new,[]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

So this commit is almost good, but I'd suggest you trying to run this code in the MatLab environment (https://matlab.mathworks.com/, should be free for UWaterloo ppl) and you'll discover that your reshape function is incorrectly used (take a look at the reference here: https://www.mathworks.com/help/matlab/ref/reshape.html). Let me know if you have any questions!

Corrected reshape functions.
@ehuan2
Copy link
Member

ehuan2 commented May 1, 2022

Alright I think I might've actually given bad advice - I think I forgot what the use of reshape is (and realizing I messed this up myself!). So, reshape is used to rearrange the output values we get into a matrix where we only care about the minimum in each row.

So a good example is if we take a look at pg. 52 of the pdf, we get the example of ba_1 = b1b3, ba_2 = b2b4. In this case, we can see from the output of what b looks like in matlab, that each 4 rows have the same first b1...b4.

image

This means that when we do reshape, we're essentially saying we don't care about what values we get for ba1, ba2 (since we group them together), we just care about the minimum that we get overall (since ba1 and ba2 are not actually variables we want to depend on).

So, in your case, think about whether or not there are any of these redundant ba's we need to get rid of. Is there any b_i that we can do without? (If not, then we don't need a reshape/min!).

I'm not 100% sure, so @ndattani can probably help me double check.

@ndattani
Copy link
Member

ndattani commented May 1, 2022

I like that we have an example function:

b1.*b2 + b2.*b3 + b3.*b4 - 4*b1.*b2.*b3

Now it's time to write that function as a sum of f_symm and f_antisymm where f_symm is a symmetric function and f_antisym is an anti-symmetric function. The symmetric component should be quadratized using one of the methods in the book for symmetric function quadratization (the top of the page will say something like SFR-BCR-1), and the anti-symmetric component should be quadratized using some other quadratization method.

Updated decomposition method, used NTR - KZFD and SFR-BCR-1.
@ehuan2
Copy link
Member

ehuan2 commented May 6, 2022

Hey @AnhMai-bit ! Looks good to me! Feel free to edit the .tex with the equations (suggest to add in the quadratization for the symmetric and anti-symmetric part) and then the full example together. Let me know if you need help on this part. Feel free to merge after Dr. Dattani's approval!

@AnhMai-bit
Copy link
Author

Thank you for your feedback @ehuan2. I will start adding to the text file after the solution is approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants