Talk:Normalize
I think Normalize should be deprecated and eventually removed from Analytica. Here's why:
When you have a 1-D vector of data, and you say you want to normalize the points, there are three different meanings that people intend, depending on the context:
- They want to scale the values so they add to 1. E.g.:
- x / Sum(x,i)
- They want to scale a vector so it has unit length, e.g.:
- They want to scale a continuous curve to have unit area, i.e., so the indefinite integral is 1.0, e.g.:
- x / Area(x,i)
Analytica's Normalize function implements the third meaning.
What makes Normalize so undesirable is that I believe it may be a common cause of errors in models, and worst of all, these are the types of errors that are likely to go unnoticed. All three meanings result in result that are pretty close numerically, so the discrepancy between what the modeler intended and what is computed could easily go unnoticed.
If someone wanted to normalize in the first or second sense, they might go looking for a function to do this, see Normalize(), notice that its parameters seem to match what they are looking for, its name sounds like it is doing what they want, and its computed values appear to be pretty close to what they expect, so they never realize it is computing something different.
It would be better to force people to divide explicitly, to ensure they are normalizing in the intended way. I would also find it reasonable to replace Normalize with better-named functions, perhaps: NormalizeSum, NormalizeVect, and NormalizeArea.
Please weigh in with your opinions here!
Maybe make index I non-optional?
Another possibility would be to make the third parameter, i, be non-optional. The confusion occurs with the 2-parameter usage:
- Normalize(y,x)
which looks a lot like:
- Normalize(A,i)
But if you are always forced to specify the third parameter, you wouldn't be able to use Normalize(A,i) without an error. That would make it difficult to make that "common" error.
One possibility would be to have the next release of Analytica start issuing a warning whenever you use Normalize without the third parameter. After that shows up for a few releases, then we could eventually make it mandatory.
Backward compatibility
I think you have a good point. The first meaning is definitely the most commonly occurring, so yes, that does seem like a point of contention. The 3rd meaning is pretty tough to implement when you need it, so it justifies a built-in function, but I'm with you that it would have been better it if had been named NormalizeArea.
We could solve this with a library. The library would add the 3 functions NormalizeSum, NormalizeVect and NormalizeArea, and override the built-in function, either to throw an error, or the require the 3rd parameter. You would need to add the library to your model, but once you do, you would be protected from these mistakes.
Enable comment auto-refresher