Reduce Curve Fitting Time for a Large Number of Datasets

In the blog we will discuss several methods to reduce the fitting time when fitting a large number of datasets with a user-defined function.

In this example for speed comparison, we are going to fit 100 datasets to a complicated function. We have put together a zip file which includes following folders

  • csv: 100 csv files, each has a dataset to be fit
  • fdf Files: the fitting function defined by Origin C (VoigtSum.FDF) and Python (VoigtSumPy.FDF)
  • Analysis Templates: analysis templates for Origin C fitting function (FitOC.ogwu) and Python fitting function (FitPy.ogwu), which are to be used in Distributed Batch Processing app.
  • SpeedyFitData.opju: CSV files are imported in a worksheet and put side by side, which are to be used in the Speedy Fit app.

** To use the fitting functions in Origin, drag and drop the FDF files to Origin


Speed Comparison

**The processing speed would be different depending on your PC configuration

As we can see, defining python fitting function which utilized Python’s numpy and scipy’s matrix calculation can greatly improve the speed, especially when working together with Speed Fit app or Distributed Batch Processing app


Define Python Vector fitting function in Origin

The Python code used in VoigtSumPy.FDF in the zip file is defined as below. It utilizes numpy and scipy’s matrix calculation.

import numpy as np
from scipy.special import wofz

def Voigt(x, xc, A, alpha, gamma):
    Return the Voigt line shape at x with Lorentzian component FWHM gamma
    and Gaussian component FWHM alpha.
    sigma = alpha/2.0 / np.sqrt(2 * np.log(2))
    hg = gamma/2.0
    return A*np.real(wofz((x-xc + 1j*hg)/sigma/np.sqrt(2))) / sigma /np.sqrt(2*np.pi)
def myfunc( x, a, b, T, P, n):
    return y.tolist()


Speedy Fit app

The Speedy Fit app generated result for all the plots in the end of processing and it saves a lot of time. To use it, we should import all the csv files to a worksheet and put them side by side first. (See SpeedyFitData.opju in the zip file)

Results of the Speedy Fit app

Distributed Batch Processing app

The Distributed Batch Processing app can distribute the fitting process to multiple Origin instances.

To use the app, we should perform fitting on one data first and prepare analysis templates. (See FitPy.ogwu and FitOC.ogwu in the zip file)

Use Distributed Batch Processing app to fit 100 files

Results of the Distributed Batch Processing app


メールアドレスが公開されることはありません。 * が付いている欄は必須項目です