Tweeted twitter.com/StackMma/status/1106842689780285440
    Became Hot Network Question
2 Symbols using http://steampiano.net/msc/
source | link

Voigt profile fits in MathematicaMathematica seem terribly slow. For an example data set with 81 points a corresponding fitting procedures for Voigt fits is >1000 times slower than for Gaussian or Lorentzian profile. How can Voigt profile fits be speed up?

Here is what I do. First we define the Voigt and Gaussian profile. As MathematicaMathematica often complains about [Delta]δ and [Sigma]σ being <0, I use Abs instedinstead of constraining the model as this proved faster. In addition I use the compile command to make the function even faster.

voigtprofile = Compile[{{\[Delta]δ, _Real, 0}, {\[Sigma]σ, _Real, 0}, {A, _Real,0}, {\[Nu]0ν0,_Real, 0}, {\[Nu]ν, _Real, 0}}, A PDF[VoigtDistribution[Abs@\[Delta]PDF[VoigtDistribution[Abs@δ, Abs@\[Sigma]]Abs@σ], \[Nu]ν - \[Nu]0]];ν0]];
gaussian[\[Sigma]_gaussian[σ_, A_, \[Nu]0_ν0_, \[Nu]_]ν_] := Return[A PDF[NormalDistribution[\[Nu]0PDF[NormalDistribution[ν0, \[Sigma]]σ], \[Nu]]];ν]];

Then I create noisy example data sets with a bit of noise:

noisyDataV = {#, 
 voigtprofile[0.15, 0.1, 1, 0, #] + RandomReal[{-0.1, 0.1}]} & /@ Range[-2, 2, 0.05];
noisyDataG = {#, gaussian[0.1, 1, 0, #] + RandomReal[{-0.1, 0.1}]} & /@
Range[-2, 2, 0.05];

And we use NonlinearModelFit to fit the data with excellent start parameters:

tv = AbsoluteTiming[vfit = NonlinearModelFit[noisyDataV, 
 voigtprofile[\[Delta]voigtprofile[δ, \[Sigma]σ, 
  A, \[Nu]0ν0, \[Nu]]ν], {{\[Delta]δ, 0.15}, {\[Sigma]σ, 0.1}, {A, 
   1}, {\[Nu]0ν0, 0}}, \[Nu]];]ν];]
tg = AbsoluteTiming[gfit = NonlinearModelFit[noisyDataG, 
 gaussian[\[Sigma]gaussian[σ, 
  A, \[Nu]0ν0, \[Nu]]ν], {{\[Sigma]σ, 0.1}, {A, 1}, {\[Nu]0ν0, 
   0}}, \[Nu]];]ν];]

And if we compare the required time for fit:

tv[[1]]/tg[[1]]

I get values between 1000 and 6000, which is terrible. In addition, selecting a fit MethodMethod e.g. NMinimizeNMinimize or other does at best yield the same result.

As this minimal example is just a very simple example, times scale up to unbearable long times for more realistic scenarios with real data. I'm glad for any hint on how to speed this simple example up.

Voigt profile fits in Mathematica seem terribly slow. For an example data set with 81 points a corresponding fitting procedures for Voigt fits is >1000 times slower than for Gaussian or Lorentzian profile. How can Voigt profile fits be speed up?

Here is what I do. First we define the Voigt and Gaussian profile. As Mathematica often complains about [Delta] and [Sigma] being <0, I use Abs insted of constraining the model as this proved faster. In addition I use the compile command to make the function even faster.

voigtprofile = Compile[{{\[Delta], _Real, 0}, {\[Sigma], _Real, 0}, {A, _Real,0}, {\[Nu]0,_Real, 0}, {\[Nu], _Real, 0}}, A PDF[VoigtDistribution[Abs@\[Delta], Abs@\[Sigma]], \[Nu] - \[Nu]0]];
gaussian[\[Sigma]_, A_, \[Nu]0_, \[Nu]_] := Return[A PDF[NormalDistribution[\[Nu]0, \[Sigma]], \[Nu]]];

Then I create noisy example data sets with a bit of noise:

noisyDataV = {#, 
 voigtprofile[0.15, 0.1, 1, 0, #] + RandomReal[{-0.1, 0.1}]} & /@ Range[-2, 2, 0.05];
noisyDataG = {#, gaussian[0.1, 1, 0, #] + RandomReal[{-0.1, 0.1}]} & /@
Range[-2, 2, 0.05];

And we use NonlinearModelFit to fit the data with excellent start parameters:

tv = AbsoluteTiming[vfit = NonlinearModelFit[noisyDataV, 
 voigtprofile[\[Delta], \[Sigma], 
  A, \[Nu]0, \[Nu]], {{\[Delta], 0.15}, {\[Sigma], 0.1}, {A, 
   1}, {\[Nu]0, 0}}, \[Nu]];]
tg = AbsoluteTiming[gfit = NonlinearModelFit[noisyDataG, 
 gaussian[\[Sigma], 
  A, \[Nu]0, \[Nu]], {{\[Sigma], 0.1}, {A, 1}, {\[Nu]0, 
   0}}, \[Nu]];]

And if we compare the required time for fit:

tv[[1]]/tg[[1]]

I get values between 1000 and 6000, which is terrible. In addition, selecting a fit Method e.g. NMinimize or other does at best yield the same result.

As this minimal example is just a very simple example, times scale up to unbearable long times for more realistic scenarios with real data. I'm glad for any hint on how to speed this simple example up.

Voigt profile fits in Mathematica seem terribly slow. For an example data set with 81 points a corresponding fitting procedures for Voigt fits is >1000 times slower than for Gaussian or Lorentzian profile. How can Voigt profile fits be speed up?

Here is what I do. First we define the Voigt and Gaussian profile. As Mathematica often complains about δ and σ being <0, I use Abs instead of constraining the model as this proved faster. In addition I use the compile command to make the function even faster.

voigtprofile = Compile[{{δ, _Real, 0}, {σ, _Real, 0}, {A, _Real,0}, {ν0,_Real, 0}, {ν, _Real, 0}}, A PDF[VoigtDistribution[Abs@δ, Abs@σ], ν - ν0]];
gaussian[σ_, A_, ν0_, ν_] := Return[A PDF[NormalDistribution[ν0, σ], ν]];

Then I create noisy example data sets with a bit of noise:

noisyDataV = {#, 
 voigtprofile[0.15, 0.1, 1, 0, #] + RandomReal[{-0.1, 0.1}]} & /@ Range[-2, 2, 0.05];
noisyDataG = {#, gaussian[0.1, 1, 0, #] + RandomReal[{-0.1, 0.1}]} & /@
Range[-2, 2, 0.05];

And we use NonlinearModelFit to fit the data with excellent start parameters:

tv = AbsoluteTiming[vfit = NonlinearModelFit[noisyDataV, 
 voigtprofile[δ, σ, 
  A, ν0, ν], {{δ, 0.15}, {σ, 0.1}, {A, 
   1}, {ν0, 0}}, ν];]
tg = AbsoluteTiming[gfit = NonlinearModelFit[noisyDataG, 
 gaussian[σ, 
  A, ν0, ν], {{σ, 0.1}, {A, 1}, {ν0, 
   0}}, ν];]

And if we compare the required time for fit:

tv[[1]]/tg[[1]]

I get values between 1000 and 6000, which is terrible. In addition, selecting a fit Method e.g. NMinimize or other does at best yield the same result.

As this minimal example is just a very simple example, times scale up to unbearable long times for more realistic scenarios with real data. I'm glad for any hint on how to speed this simple example up.

1
source | link

How to speed up Voigt profile fits?

Voigt profile fits in Mathematica seem terribly slow. For an example data set with 81 points a corresponding fitting procedures for Voigt fits is >1000 times slower than for Gaussian or Lorentzian profile. How can Voigt profile fits be speed up?

Here is what I do. First we define the Voigt and Gaussian profile. As Mathematica often complains about [Delta] and [Sigma] being <0, I use Abs insted of constraining the model as this proved faster. In addition I use the compile command to make the function even faster.

voigtprofile = Compile[{{\[Delta], _Real, 0}, {\[Sigma], _Real, 0}, {A, _Real,0}, {\[Nu]0,_Real, 0}, {\[Nu], _Real, 0}}, A PDF[VoigtDistribution[Abs@\[Delta], Abs@\[Sigma]], \[Nu] - \[Nu]0]];
gaussian[\[Sigma]_, A_, \[Nu]0_, \[Nu]_] := Return[A PDF[NormalDistribution[\[Nu]0, \[Sigma]], \[Nu]]];

Then I create noisy example data sets with a bit of noise:

noisyDataV = {#, 
 voigtprofile[0.15, 0.1, 1, 0, #] + RandomReal[{-0.1, 0.1}]} & /@ Range[-2, 2, 0.05];
noisyDataG = {#, gaussian[0.1, 1, 0, #] + RandomReal[{-0.1, 0.1}]} & /@
Range[-2, 2, 0.05];

And we use NonlinearModelFit to fit the data with excellent start parameters:

tv = AbsoluteTiming[vfit = NonlinearModelFit[noisyDataV, 
 voigtprofile[\[Delta], \[Sigma], 
  A, \[Nu]0, \[Nu]], {{\[Delta], 0.15}, {\[Sigma], 0.1}, {A, 
   1}, {\[Nu]0, 0}}, \[Nu]];]
tg = AbsoluteTiming[gfit = NonlinearModelFit[noisyDataG, 
 gaussian[\[Sigma], 
  A, \[Nu]0, \[Nu]], {{\[Sigma], 0.1}, {A, 1}, {\[Nu]0, 
   0}}, \[Nu]];]

And if we compare the required time for fit:

tv[[1]]/tg[[1]]

I get values between 1000 and 6000, which is terrible. In addition, selecting a fit Method e.g. NMinimize or other does at best yield the same result.

As this minimal example is just a very simple example, times scale up to unbearable long times for more realistic scenarios with real data. I'm glad for any hint on how to speed this simple example up.