Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Highlighted

05-29-2020 01:49 PM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

I try to fit gauss function with* Constrained Non-linear Fit,* I get different results with or without set bounds.

When i set bounds, then the fit is not optimalize and the result parameters are same as the initial parameters.

If the bounds array is not conected then the fit get optimalized. Strange fatc is that, the best fit parameters are in between the bounds.

I do not understand why i dont recieve same result in both cases (best fit parameters are not found when bounds are conected).

Please can someone explain this behiavor and how to fix setting to get optimal result even with bounds connected.

Solved! Go to Solution.

Download All

Virus scan in progress. Please wait to download attachments.

Highlighted
Options

** LabVIEW Champion. It all comes together in GCentral **

**What does "Engineering Redefined" mean??**

05-29-2020 02:22 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Any reason you are not using Gaussian Peak fit?

Highlighted
Options

** LabVIEW Champion. It all comes together in GCentral **

**What does "Engineering Redefined" mean??**

05-29-2020 03:39 PM - edited 05-29-2020 03:59 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

That said, your bounds are reversed (you swapped lower bounds with upper bounds, leaving no valid range)

Highlighted
Options

** LabVIEW Champion. It all comes together in GCentral **

**What does "Engineering Redefined" mean??**

Solution

Accepted by OpiCAN00

05-29-2020 03:56 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Your code was such a mess that I tried to clean it up a bit for better troubleshooting.

Model:

You must be coming from a text programming background, because all you really need is the following (No FOR loop, No formula node, etc.):

Bounds generation:

Your are inputting the existing parameters as array AND as scalars. Seems redundant. All you need is an array of parameters and an array of % freedom values (note that I reversed upper and lower bounds for correct function!):

Attached is a quick attempt at cleanup. Modify as needed.

Highlighted
Options

05-30-2020 06:56 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Thank You very much,

my dumb mistake to swap the bounds. I agree the code which i posted is kinda mess. I was overworked and copy/paste some code artefacts from different projects. I use formula node in model function and Constrained Non-linear Fit, because in near future i will need to extend code to fit more (asymmetric) gausses in one spectra and also one function with 28 parameters (It seems to me easier to write formula than combine many mathematical functions.). I wanted to learn how Constrained Non-linear Fit work and I thought this way of solve fitting would be best for my tasks. I see the code can even look nice if it is optimized. I have to work on my programming style :).

Highlighted
Options

** LabVIEW Champion. It all comes together in GCentral **

**What does "Engineering Redefined" mean??**

Solution

Accepted by OpiCAN00

05-30-2020 11:27 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

@OpiCAN00 wrote:my dumb mistake to swap the bounds. .

Not necessarily dumb. If I had written the implementations I would sort the limits so we always have a valid range and we can just call them limit A and limit B. Whatever is smaller is the lower limit automatically. 😉

@OpiCAN00 wrote:

because in near future i will need to extend code to fit more (asymmetric) gausses in one spectra and also one function with 28 parameters (It seems to me easier to write formula than combine many mathematical functions.).

Well, if one Gaussian is simpler graphically, several gaussians are also simpler than a formula node. Here's a very old example for a model that automatically scales to the number of gaussians based on the number of parameters (note that the width and area are define differently, so rescale as needed). You would have one additional parameter for asymmetry.

Highlighted
Options

05-30-2020 12:41 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report to a Moderator

Well, it is nice alogrithm. It will be useful for sure. Thanks 🙂