Closed crinklywrappr closed 8 years ago
Maybe I'm using it wrong. operators/* & operators/\ both give this error, but matrix/mmul works as expected.
*
is elementwise multiplication, so the matrices need to be the same shape (not transposes).
Likewise **
is elementwise exponent.
So this is all as expected :-)
Did this change? I'm reading through a book on machine learning in Clojure and at every step in the first chapter they assume operators/* performs matrix multiplication.
The confusion between * and mmul arises often - the documentation should be much better IMO. BUT, I suspect the problem in this case lies in the book. Packt publishing books are notorious for their low quality, but if it is true (I didn't check) that the author missed even the most important operation, it is something that I didn't expect even from them.
I've tried to be as consistent as possible with other matrix libraries when defining this, e.g. NumPy also assumes multiply
is elementwise: http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.multiply.html
*
, -
, /
, and +
are all elementwise in c.c.m.operators
.
I sometimes like to use inner-product
instead of mmul
to avoid ambiguity (they do the same thing).
@blueberry how would you improve the documentation for this?
@mikera By stressing in early examples and in many other places that mmul is for multiplication and * is not. This issue arises regularly, it even have it's own stackoverflow topic. I also think that reusing Clojure's * + etc operators for matrices is confusing; (emap * x y) is here and is much clearer). But this is another topic, that I won't get into. Users are very creative when it comes to misuse :) I do not know whether that would help, cause many people tend to not read the docs at all. As I said, in this case, the problem is in the low quality of the book publisher.
Just another comment regarding numpy as a reference: Isn't that in numpy matrix multiplication is done by x.dot(y)? Not very intuitive, if you ask me...
Well.... dot is conventionally used in mathematics to indicate inner product, which of course is a generalisation of matrix multiply. So I guess it makes sense.
An observation is that there seems to be a lot of prejudice about notation depending on whether you come from engineering, pure maths, stats, computer science etc. :-)
Sure, it makes some sense when explained in detail; but by that logic, the right name for elementwise multiply would be "asterisk"? What people first think of when they read dot in the context of (computational) linear algebra is "dot product". Now, having two methods with the same name doing two different fundamental operations for two different fundamental data structures is a bit confusing. That's why there is vdot in numpy. So, matrix multiplication is called "dot" while dot product is called "vdot". I wouldn't call that intuitive, but ok.
Matlab has a similar naming problem trying to differentiate between matrix operators and elementwise operators. They use * for matrix multiply (also works for scalars), and the .* operator for element-wise multiplication. They use + for either matrix or scalar addition, but beware of silent autoconversion since (A + 5) => (A + 5*I).
I have sometimes wondered if it might be worth it to make everything unambiguous, like mmul vs emul (matrix vs element multiplication), etc. Besides avoiding incorrect or conflicting assumptions, such names are much easier to search for using either grep or google. Alan
On Mon, Mar 28, 2016 at 3:17 AM, Dragan Djuric notifications@github.com wrote:
Sure, it makes some sense when explained in detail; but by that logic, the right name for elementwise multiply would be "asterisk"? What people first think of when they read dot in the context of (computational) linear algebra is "dot product". Now, having two method with the same name doing two different fundamental operations for two different fundamental data structures is a bit confusing. That's why there is vdot in numpy. So, matrix multiplication is called "dot" while dot product is called "vdot". I wouldn't call that intuitive, but ok.
— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/mikera/core.matrix/issues/279#issuecomment-202333062
thoughts?