-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlmng.h
57 lines (48 loc) · 1.35 KB
/
lmng.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Created by troels on 9/6/16.
//
/*
* Levenberg–Marquardt fit of sum of several normal distributions.
* Using lmfit: http://apps.jcns.fz-juelich.de/doku/sc/lmfit
* Implementation inspired by lmcurve from the same project.
*/
#ifndef VMMEF_LMNG_H
#define VMMEF_LMNG_H
#include <math.h>
#include <lmmin.h>
#include <float.h>
#define NG_PAR 2
#define NGI_PAR 3
#ifdef __cplusplus
extern "C" {
#endif
static inline double g(double m, double sd, double i, double x)
{
if (sd < 1.0 || i < 100)
return -FLT_MAX;
double dxm = x-m;
return (i/(sd*sqrt(2*M_PI)))*exp(-(dxm*dxm)/(2*sd*sd));
}
typedef struct
{
const size_t n; // Number of gusian functions to sum
const long ig; // Integral of the function
const long x0; // x offset
const int* y; // measured data
} lmng_data_t;
// Eval function for fitting n gauss functions with fixed integral: ig/n
void lmng_eval(const double *par,
const int m_dat,
const void *data,
double *fvec,
int *info);
// Eval function for fitting n gauss functions where the integral of the single gauss function is also a free variable
void lmngi_eval(const double *par,
const int n_dat,
const void *_data,
double *fvec,
int *info);
#ifdef __cplusplus
}
#endif
#endif //VMMEF_LMNG_H