-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
State of inner products in Base #496
Comments
Could you explain a little bit more about your use case and why having it in Base instead of just defining it in your package is beneficial? A concrete example would be best. Do you expect several |
I think having a formal interface for these mathematical spaces will help users exploit the type system better. For example, I would expect clustering methods to work on any metric space. If I could define my type with an inner product, I would benefit from As a concrete example, I came across this limitation today trying to define a geometry for compositional data: https://github.com/juliohm/CoDa.jl I'd rather specialize on a well-known |
Why not extend |
The concept of dot product is more strict than the concept of inner product. Whereas the latter is defined for general spaces, a dot product is only defined when there is the notion of a coordinate system defined by a finite basis. The semantics of To distinguish further, in a Hilbert space with inner product Another example as I pointed out in my I don't see benefit in maintaining the term Can you elaborate on the objections for this change? |
We generally require a fair amount of justification for adding new public functions to Base, that's the objection. This could be provided by an |
I don't see a good argument to define a basic mathematical concept like inner products elsewhere that is not in Base. A language whose main audience is scientific computing folks would benefit from correct terminology. Why the concept of |
So you want all possible mathematical concepts in the base language? Not having something defined in Base doesn't force people to use the wrong terminology. The |
I never said that.
I am sure that it doesn't. Promoting the wrong terminology is the issue. People coming from a less mathematical background will adopt the usage of dot because they see it in Base. Usage of the term "dot" product to represent the concept of inner product is incorrect. It is also harmful to the mathematical community, which struggles every now and then to fix these scars that wrong terminology has left. Students from my generation are consistently having to refer to old books to get the terminology right, this shouldn't be the case.
That would already be a major improvement in my opinion. See all the examples I gave above on functional and compositional data. People in these communities would never use the term |
Renaming |
There was a little discussion of this in #433 and JuliaLang/julia#22220 |
This is what I proposed in my first message in this thread:
I repeat dot product is the incorrect term for the operation I am discussing here. Inner, outer, scalar product... these are mathematical objects. "dot product" is a computational object: it gets two sequences of numbers and performs |
I had focused on the second option you proposed, which seems to have been adding |
@juliohm It's probably worth (re)stating that there is an active effort currently trying to shrink Also worth keeping in mind that a fair number of Julia newcomers may be familiar with a dot product but not an inner product (say, they did a bit of physics at university, but aren't math majors) so there are also some reasons to keep Thus, there is a burden to make a reasonable case for how putting this in |
Thank you @andyferris for sharing your thoughts. I see the resistance very clearly, which is something that I am not very excited about. Nevertheless, I am curious about how this specific proposal leads to code increase? To me, it seems like a trivial change in code with major improvement in abstraction. The example with Clustering.jl is just one of many, think of any kernel-based method that can be made to work with arbitrary Julia types for which the notion of inner product exists. MultivariateStats.jl has plenty of them. |
Regarding the comment about |
Yes, the standard libraries are all built together with the Julia system image and available by default. |
To clarify, it would be loaded with standard Julia so you don't have to install anything, but you would still have to write |
This is where it gets odd, right, since we'll get the |
Yes, that's basically where we'll have to draw the line: Base must define as much linear algebra functionality as needed to make LinAlg not a pirate, so matmul is defined in Base because |
Let me give you a concrete example and ask you how would you solve it with the current interface, maybe this can clarify things for me. The goal is to perform factor analysis with compositional data. I have a type called a What I understood from the last comments is that both MultivariateStats.jl and CoDa.jl would have to depend on LinAlg.jl. The dependency in MultivariateStats.jl is just to bring name |
It seems I would be quite tempted to define the dual vector space. So, you could define |
The first sentence in https://en.wikipedia.org/wiki/Dot_product does seem to suggest that |
Thank you @andyferris, I appreciate your thoughts on the dual space. I'd rather not rely on a new type for this task though. The final solution is unnecessarily complex. What I am interested in understanding is why something like: inner(x,y) = sum(x.*y)
norm(x) = sqrt(inner(x,x))
export inner, norm not welcome in Base? I am assuming this is all that is required to define the function names generically for users of the language to specialize on. Keep in mind I am asking these questions with the genuine interest of understanding the point of view of the core devs. I want to say this before the conversation goes into the wrong direction again. From the perspective of someone interested in math in general, it feels unnatural to have these concepts not exported by default, and instead have them defined inside of If I can emphasize it further, there is the concept of inner product, which is independent of arrays. This concept is represented by the statement |
Another example of a use case is Krylov methods. If you have e.g. function spaces with inner products, then you could use Krylov methods to approximate a linear problem or eigenproblem in a small finite-dimensional subspace of that infinite dimensional function space. I too have my own objects which form a vector/Hilbert space but are not part of |
Right - (Now I’m vaguely wondering if |
In fact, for general vector-like objects, it's also useful to query the dimension of the vector space (e.g. to verify that Krylov dimension should not be larger than dimension of the full space in my example use case). The example of nested arrays shows that Now for the example of using nested arrays as a general vector, So I do agree that we need a consistent interface here to be used across packages, that would therefore belong in a central location (probably not in Base but certainly in a Standard Library, e.g. such that one has to do Option 1 (my interpretation so far):
Option 2 (probably better): use more mathematically correct names
And finally, just pinging @stevengj as he will certainly have some useful comments; my apologies if this is inconvenient. |
Yes, congrats! |
It seems like there might be some consensus forming around the idea of having both
Regarding:
I don't believe that would be an issue. Since this is a fairly uncommon operation, I would expect people to at the very least try it to see what it does and/or go look at the documentation. I think that the above would be a great change, and not very disruptive since the semantics of |
Maybe |
@stevengj, when you added this paragraph to a previous comment by yourself, you meant that the syntax |
Any chance this feature will make it to Julia v1.0? I have so many ideas and packages that depend on the notion of general inner products. Please let me know if I should lower my expectations. Sorry for the constant reminder. |
Have you not seen JuliaLang/julia#27401? |
Not technically hard to add to the parser, but it has proven difficult to come up with a consensus on how (and whether) to represent custom brackets in the language. See the discussion at JuliaLang/julia#8934, which went nowhere 4 years ago and has not been revived since. (Add that to the fact that in different fields people use the same brackets for many different things, e.g. ⟨u⟩ is used for ensemble averages in statistical physics.) Another issue, raised in JuliaLang/julia#8892, is the visual similarity of many different Unicode brackets. |
Thank you @stevengj, I appreciate the clarifications. I am already very excited that we are gonna have general inner products standardized across packages. 💯 Maybe the angle bracket notation could shine in another release cycle in the future. Not as important, but quite convenient to be able to write code that is literally like the math in our publications. |
If |
@StefanKarpinski, the argument in JuliaLang/julia#8934 was that it should be a macro. I don't think we ever came to a consensus. (If we decide in Base that |
I don't recall the details of that discussion but making a macro seems like obviously a bad idea to me. |
With JuliaLang/julia#27401 I think we can consider inner products to have been taking seriously. |
Traditionally, an issue is closed only when the relevant PR is merged... |
Sure, we can leave it open I guess. Just wanted to get it off the triage label. |
Should this be closed since JuliaLang/julia#27401 is merged now? |
If a user needs to define custom inner products for general Hilbert spaces, what is the current state in Base for this type of generalization? #334 is a related, but less general issue. My concern is with new types that aren't arrays.
I'd like to propose renaming
dot
toinner
, or perhaps directing users to defineinner(x,y)
as a general inner product between objectsx
andy
, including the array case:In case the change is reasonable, could it be part of Julia v1.0?
The text was updated successfully, but these errors were encountered: