I’m planning to add a new function in the G’MIC math evaluator that takes a vector-valued argument v and returns its normalized version \frac{v}{\|v\|}.
How would you name such a function ?
I don’t want to use normalize as it is already the name of a G’MIC command that does something else (linear normalization of an image).
For an idea, I’ve asked ChatGPT and it suggested to use the name unitize.
So that would be something as:
X = unitize([1,2,3]);
Do you agree with this suggestion? Or do you have another name to propose?
It doesn’t really have to be a verb, as it doesn’t act “in-place”, but returns a new unit vector.
Maybe
norm brings to my mind the notion of mapping lengths to vectors; in the interest of terseness, I need not explicitly write vector — such is implied.
unit conveys to me that special length mapping to unity, so the useful outcome of the operation is the orientation of the vector within the space that it is embedded.
(2.) left me dancing with the idea of orient(), a riff on the pipeline command pair norm, which conveys pixel vector ‘length’, and orientation, which conveys their spatial positioning. Mathematical Expressions already has norm() (aka: norm2()); orient() would complete (and echo) the pipeline counterparts. That may be too poetical; unitnorm() is the more practical name, methinks.
orient() is my suggestion because it matches the name of my command. unit(), unitize() and unitnorm() can be confusing. I would rather call it unitvector().
After thinking about it for a moment, what I have in mind right now is to actually make the name coherent with the current family of normP() functions, so that would mean adding an entire family of unitnormP() functions that works equivalently:
Y = unitnorm2(X) and Y = unitnorm(X) , both equivalent. One can also use Y = unitnorm(x0,x1,...,xN) , just as it is possible to do it with norm().
And variations : unitnorm0(), unitnorm1(), unitnorminf() for the L-0, L-1 and L-inf norms.
Also looking at all this made me realize that there was no version of normP() that can takes a parameter P that is not a constant value. So I’ll also add normp(p,X) and unitnormp(p,X) to allow calling these functions with variable parameters p.
Maybe create some kind of alias so that it retains compatibility with 3.2.3 until old scripts are updated, and then switch over to the new names? Something like that.
I’ve finally decide to keep versions of normP() where P is a constant.
To keep a perfect compatibility you just have then to use norm2() instead of norm() in your source code and it will be OK (already made the changes in gmic-community).
OK, so things have changed again.
While doing the modifications in the various .gmic files, I realized that norm(a,b,c,...) was actually used a lot, and was quite a readable expression.
On the contrary, computing the L-p norm of a vector (with a variable p), was not a so common need.
And I don’t want to break anything, just for that.
So, my final decision about norm() is:
Things will not change compared to version 3.2.3 : norm(1,2,3), norm([1,2,3]), norm2(1,2,3), norm1(1,2,3) will be valid and do the same as in 3.2.3.
New function normp(V,p) is introduced when we really need to compute a L-p norm of a vector with a variable p.