-
Notifications
You must be signed in to change notification settings - Fork 15
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
parametrizedFunction constants #30
Comments
Can you give a clearer example with a real function to fit? |
function parametrizedFunction(params, c) { I cannot or should not modify f. And c should be chosen from a finite set of possible values. Now, in my loop I have this: |
Actually, you don't need to define it there. You could easily use a "factory" function instead like this: function getFixedFunction(...constants) {
return function fixedFunction(...variables) {
let result;
// ...(use the constants & variables to compute the result)...
return result;
}
}
for (let c of [1, 2, 3, 4 /* ... */ ]) {
// ...
LM(data, getFixedFunction(c) ...)
}
That may be more idiomatic for Matlab, but since JavaScript has better support for functional programming / "first class functions" it is possible to separate the concern regarding how the function is constructed (constants, etc.) from the LM implementation. I think keeping the API simple for this is a better design choice then trying to force a particular decomposition onto the user. For example, I cannot think of a function for which the existing call signature will not work, yet if we required the function to be in some particular form, say |
I see. Nevertheless, the factory function used in this way is syntactic sugar for defining functions within a loop. My real concern is that there exist many complex function with many parameters, but usually you only want to optimize a subset of them.
The function that have right to call parametrizedFunction is the LM, so there is only one person who can mix up those parameters. As I say, It is working, but I consider including the constants can simplify many cases. |
How would having
Exactly. The |
The parametrizedFunction must accept a constant. I.e. all the other parameters that does not need to be fitted
function parametrizedFunction(params, constants) {
}
The text was updated successfully, but these errors were encountered: