Optimizing parameters without specifying them (Mathematica)

In summary, the speaker is discussing their use of NMinimize to optimize a likelihood function and their desire for Mathematica to automatically declare the correct number of parameters for them when solving for them. They currently have to hard code their notebook for each different size of vector and are wondering if there is a way for Mathematica to use anonymous variables or declare parameters automatically. The suggested solution is to create a function called myNMinimize that takes in a function and the number of parameters and uses Table and ToExpression to declare the parameters and solve for them.
  • #1
yourgoldteeth
10
0
I use NMinimize to optimize a likelihood function. The number of parameters included depends on the dimensions of a vector I pass. I would like to have Mathematica check the dimensions of the vector, declare the correct number of parameters for me, and then solve for them.

Right now, I have to hard code my notebook for each different size of vector I hand it. Is there anyway to have Mathematica either use anonymous variables, or declare parameter1, parameter2... parameterN variables for me, automatically, and use them?

Thanks
 
Physics news on Phys.org
  • #2
myNMinimize[f_,n_]:=NMinimize[f,Table[ToExpression["parameter"<>ToString],{i,1,n}]]

Then
myNMinimize[(parameter1-3)^2+2(parameter2+1)^4+parameter3^2,3]
returns
{parameter1->3., parameter2->-1., parameter3-> 0.}
 
Last edited:

1. How can I optimize parameters in Mathematica without specifying them?

One way to optimize parameters without specifying them in Mathematica is by using the function FindMinimum. This function allows you to specify the objective function and the range of values for the parameters, and it will automatically find the optimal values for the parameters within that range.

2. Can I optimize multiple parameters simultaneously without specifying their values?

Yes, you can optimize multiple parameters simultaneously without specifying their values in Mathematica. This can be done by using the function FindMinimum and specifying a list of parameters and their corresponding ranges. The function will then find the optimal values for all the parameters simultaneously.

3. How do I know if the optimized parameters are accurate?

The best way to check the accuracy of the optimized parameters in Mathematica is by plotting the objective function with the optimized parameters and comparing it to the original data. If the plot closely matches the data, then the optimized parameters are likely accurate.

4. Can I optimize parameters without knowing the underlying mathematical model?

Yes, you can optimize parameters without knowing the underlying mathematical model in Mathematica. This is because the FindMinimum function does not require you to specify the mathematical model, only the objective function and the range of values for the parameters.

5. Are there any limitations to optimizing parameters without specifying them in Mathematica?

One limitation of optimizing parameters without specifying them in Mathematica is that it may take longer to converge to the optimal values, especially if the range of values for the parameters is large. Additionally, the optimized parameters may not be as accurate compared to when they are specified in the optimization process.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
932
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
257
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
684
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
Back
Top