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

Add trace_dot in linalg #4176

Merged
merged 4 commits into from Feb 28, 2018

Conversation

vinx13
Copy link
Member

@vinx13 vinx13 commented Feb 15, 2018

  • Add method that computes trace of the product of two matrixes in linalg
  • Use trace_dot in LMNN

obj[iter] += linalg::trace(
linalg::element_prod(
linalg::matrix_prod(L, L, true, false), gradient));
obj[iter] +=
Copy link
Member

Choose a reason for hiding this comment

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

Is this the same as before? Doesnt seem to me but maybe I am blind :)

Copy link
Member Author

Choose a reason for hiding this comment

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

They are different. Actually I was wrong in #4167. Now it is the same as the original one.

obj[iter] = TRACE(L.transpose()*L,gradient) + m_regularization*cur_impostors.size();

Copy link
Member

Choose a reason for hiding this comment

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

EHM!!!
Why did the tests pass? Or are there none?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, here the trace is used as the termination condition. Seems that it doesn't stop until reaching maximum number of iterations when trace is wrong in tests.

Copy link
Member

Choose a reason for hiding this comment

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

I see now! makes sense
Ok, this definitely should be tested somehow (at least in a unit test)
Wanna do send another PR for that?

Copy link
Member

Choose a reason for hiding this comment

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

Check the history of that line, it changed back and forth IIRC

Copy link
Collaborator

@iglesias iglesias Mar 9, 2018

Choose a reason for hiding this comment

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

I checked and only found the three mentioned here: the original with TRACE plus the two in this diff.

Copy link
Member Author

Choose a reason for hiding this comment

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

The original with TRACE is correct, the former one in this diff is wrong.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Where is the difference between them, @vinx13?

Copy link
Member Author

Choose a reason for hiding this comment

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

We are calculating trace of L' * L * gradient, which is sum( (L'L) . gradient' ), instread of trace( (L'L) . gradient) that appears in the previous commit

template <typename T>
T trace_dot(const SGMatrix<T>& A, const SGMatrix<T>& B)
{
return sum(element_prod(A, transpose_matrix(B)));
Copy link
Member

Choose a reason for hiding this comment

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

is transpose matrix changing the memory (it shouldnt)

Also, the API seems inconsistent, for some methods we pass flags for whether matrices should be transposed. And for others, this flag doesnt exist and we have to transpose matrices from the outside ?

Copy link
Member Author

Choose a reason for hiding this comment

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

transpose matrix creates a new matrix.
The API is indeed inconsistent, maybe we should add transpose flags to element_prod ?

Copy link
Member

Choose a reason for hiding this comment

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

yep!

Copy link
Member Author

Choose a reason for hiding this comment

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

@karlnapf I made another pr #4183 , with which I could make it clear here

@karlnapf
Copy link
Member

What is the status of this one then? :)

@vinx13
Copy link
Member Author

vinx13 commented Feb 27, 2018

This one would be ready for review after cleaning up calls to transpose_matrix.

@karlnapf
Copy link
Member

ok ping me here once that is the case

@vinx13
Copy link
Member Author

vinx13 commented Feb 28, 2018

@karlnapf Ready for review now :)

@@ -1734,6 +1734,23 @@ TEST(LinalgBackendEigen, SGMatrix_trace)
EXPECT_NEAR(trace(A), tr, 1e-15);
}

TEST(LinalgBackendEigen, SGMatrix_tract_dot)
Copy link
Member

Choose a reason for hiding this comment

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

typo

@karlnapf
Copy link
Member

typo fix and travis green and we can merge this :)

@karlnapf
Copy link
Member

restarted the hickup builds...should be fine soon

@karlnapf karlnapf merged commit 9197c72 into shogun-toolbox:develop Feb 28, 2018
ktiefe pushed a commit to ktiefe/shogun that referenced this pull request Jul 30, 2019
* Implemented trace_dot in linalg
* Use trace_dot in LMNN
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