-
Notifications
You must be signed in to change notification settings - Fork 137
Conversation
Formatting error. Co-Authored-By: Artem Artemev <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding tests! I left a few minor comments.
@dan-zheng I'll take care of the doc comments like you mentioned in the SVD PR. Thanks for the precondition performance explanation. |
#578 is actually already merged. The doc comments for /// Returns the singular value decomposition of `self`, given that `self` is an optionally
/// batched matrix.
/// ...
func svd(computeUV: Bool = true, fullMatrices: Bool = false) -> ( ... } |
/// - Parameter matrix: A tensor of shape `[..., N, M, M]`. | ||
/// - Returns: A tensor containing the determinants of all input submatrices. | ||
@inlinable | ||
func slogdet<T: TensorFlowFloatingPoint>(_ matrix: Tensor<T>) -> (Tensor<T>, Tensor<T>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to define the derivative of slogdet
?
Motivation: slogdet
overlaps with the previously defined func logdet
below:
@differentiable(wrt: matrix where T: TensorFlowFloatingPoint)
func logdet<T: TensorFlowFloatingPoint>(_ matrix: Tensor<T>) -> Tensor<T> {
return 2.0 * log(cholesky(matrix).diagonalPart()).sum(squeezingAxes: -1)
}
(Aside: func logdet
should be renamed to func logDeterminant
.)
func logdet
is differentiable, while func slogdet
is not. If we can define a derivative for func slogdet
, we could consider changing the implementation of func logdet
to call func slogdet
instead of custom computation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shashi456: to make progress on this, could you please rename the existing func logdet
to func logDeterminant
? We can try to unify or code share func logDeterminant
and func signAndLogDeterminant
in a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dan-zheng I would recommend against this renaming. slogdet
and logdet
are well known and used by every single scientific language I know - Python (numpy), R, Julia, Matlab. The det
abbreviation is also broadly used in the literature as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shashi456 ^^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dan-zheng since I mostly take inspiration from the tensorflow-python API and check numpy linear algebra library for additional consistency. I initially named the functions slogdet and det.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel reusing existing term-of-art names here is reasonable. Could you please add (sign:logDeterminant:)
result tuple element labels to slogdet
please?
func slogdet<T: TensorFlowFloatingPoint>(_ matrix: Tensor<T>) -> (sign: Tensor<T>, logDeterminant: Tensor<T>) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @param087, who implemented
func logdet
in #592.
I wonder what you used as the reference implementation forfunc logdet
? I'm curious why it uses custom logic instead of forwarding to a_Raw
op.
@dan-zheng, I had taken reference from https://github.com/tensorflow/tensorflow/blob/r2.1/tensorflow/python/ops/linalg/linalg_impl.py#L72-L103 to implement logdet
. Considering the python implementation of logdet
and making it differentiable, I found custom logic is more promising than that of forwarding to a _Raw
op.
@dan-zheng will do so. |
Continuing my comment #604 (comment), @dan-zheng, in general, the preference to have short and concise namings for math functions, because often math-like code has long and nested expressions which by itself are really hard to read, https://github.com/GPflow/GPflow/blob/develop/gpflow/expectations/squared_exponentials.py#L79
It is not about numpy only, these abbreviations are used everywhere: Python (numpy, tensorflow, pytorch), R, matlab, Julia and just commonly in the literature about linear algebra. Also, for me renaming of |
Okay, that's fair! For every API, we could try to find an idiomatic Swift name, or to use an existing domain-specific term-of-art name. In some cases, we chose new idiomatic Swift names:
In this case, I feel using an existing term-of-art name is reasonable! Thanks for your feedback! |
@dan-zheng WDYT? |
Co-Authored-By: Dan Zheng <[email protected]>
Co-Authored-By: Artem Artemev <[email protected]>
One empty line between declarations.
tests locally pass. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for adding two unit tests for det
and slogdet
!
No description provided.