Update:
The data has been made available as a text file.
It is desired to use the Weights
option with NonlinearModelFit
and the direct coding gives the error message "Wolfram Kernel for Windows has stopped working." Below the commands are given the import the data and run a few models. The first two work fine; the last one gives the error message given above.
data = Import["sample_data.txt", "Table"];
(* Create data for NonlinearModelFit *)
dataWeights = data[[All, 3]];
dataSpectrum = data[[All, {1, 2}]];
dataWeightsN = dataWeights/Max[dataWeights];
(* This works *)
nlm1 = NonlinearModelFit[dataSpectrum, a (x/150.0)^(-2) + b (x/150.0)^(-1),
{{a, 449}, {b, -177}}, x];
nlm1["BestFitParameters"]
(* {a -> 440.0413493307273`,b -> -174.44382871465248`} *)
(* This works: dataSpectrum is multiplied by 1.0 and the Weights option is added *)
nlm2 = NonlinearModelFit[1.0*dataSpectrum, a (x/150.0)^(-2) + b (x/150.0)^(-1),
{{a, 449}, {b, -177}}, x, Weights -> dataWeightsN];
nlm2["BestFitParameters"]
(* {a -> 430.15765125168565`,b -> -156.68960890633196`} *)
(* This doesn't work. Original data and model with Weights are used *)
(* Error message is "Wolfram Kernel for Windows has stopped working" *)
nlm3 = NonlinearModelFit[dataSpectrum, a (x/150.0)^(-2) + b (x/150.0)^(-1),
{{a, 449}, {b, -177}}, x, Weights -> dataWeightsN]
End of update
Has anyone experience corruption while importing numbers from a textfile?
The issue I have is that nonlinear model fitting completes only without a weighting function, but the issue goes away if I modify my lists and arrays by multiplying them by 1.0 before feeding them to the NLM function. (or manually cutting and pasting the array values into the code works too, but that is way too manual as I may have to analyze 100 data sets)
Example: I have 25 ordered pairs of numbers I wish to fit using NLM
dataList={{90.5125000, 1001.3813546}, {91.5,977.38053}, {92.56, 966.23423}, and so on}.
I have a weights list of 25 values in a list like
dataWeights={0.85836, 0.577296, 0.2, 0.68656, 1, 0.23434, and so on}
This call doesn't work (meaning all variables turn blue)
z = NonlinearModelFit[datalist, a (x/150.0)^(-2) + b(x/150.0)^(-1), {a,b}, x, Weights -> dataWeights];
but this one works
z = NonlinearModelFit[datalist, a (x/150.0)^(-2) + b(x/150.0)^(-1), {a,b}, x];
However, if I issue the command:
datalist=1.0*datalist;
both calls work or if I cut and paste, both calls work.
datalist was created by the following Code
data = Import["filename.txt", "Table"];
dataWeights = data[[1 ;;, 3]];
datalist = data[[1 ;;, 1 ;; 2]];
Sorry that I don't provide the data, as the problem goes away if I enter all of the data into this question with a cut and paste.
So the question boils down to Mathematica 11.1 - has anyone had experience with white space issues in text files containing numbers, and if yes, did you figure out what to do with your text file to make sure you didn't get problems in the future.
LinearModelFit
? In any case 25 vals is not too much to post, just paste the whole thing into the question. $\endgroup$ – george2079 Apr 7 '17 at 23:33