318 float nu, rho, lzmlh, amax, chiSq0;
320 std::vector<float> res(nData);
321 std::vector<float> beta(nParam);
322 std::vector<float> dp(nParam);
323 std::vector<float> alpsav(nParam);
324 std::vector<float> psav(nParam);
325 std::vector<float> dydp(nData * nParam);
326 std::vector<float> alpha(nParam * nParam);
328 bool haslimits =
false;
329 for (j = 0; j < nParam; j++) {
330 if (plimmin[j] > std::numeric_limits<float>::lowest() ||
331 plimmax[j] < std::numeric_limits<float>::max()) {
337 fgauss(
y, p, nParam, nData, res);
339 dgauss(p, nParam, nData, dydp);
343 for (j = 0; j < nParam; j++) {
344 if (alpha[j * nParam + j] > amax) amax = alpha[j * nParam + j];
346 lambda = 0.001 * amax;
348 for (j = 0; j < nParam; j++) {
349 alpsav[j] = alpha[j * nParam + j];
350 alpha[j * nParam + j] = alpsav[j] + lambda;
358 for (j = 0; j < nParam; j++) {
362 fgauss(
y, p, nParam, nData, res);
365 for (j = 0; j < nParam; j++) {
366 if (p[j] <= plimmin[j] || p[j] >= plimmax[j])
372 for (j = 0; j < nParam; j++) {
373 lzmlh += dp[j] * (lambda * dp[j] + beta[j]);
375 rho = 2. * (chiSq0 - chiSqr) / lzmlh;
377 for (j = 0; j < nParam; j++)
380 lambda = nu * lambda;
382 for (j = 0; j < nParam; j++) {
383 alpha[j * nParam + j] = alpsav[j] + lambda;
388 lambda = lambda * fmax(0.333333, 1. - pow(2. * rho - 1., 3));
389 dchiSqr = chiSqr - chiSq0;
void solve_matrix(const std::vector< float > &beta, const std::vector< float > &alpha, const int npar, std::vector< float > &dp)
void fgauss(const float yd[], const float p[], const int npar, const int ndat, std::vector< float > &res)
float cal_xi2(const std::vector< float > &res, const int ndat)
void dgauss(const float p[], const int npar, const int ndat, std::vector< float > &dydp)
void setup_matrix(const std::vector< float > &res, const std::vector< float > &dydp, const int npar, const int ndat, std::vector< float > &beta, std::vector< float > &alpha)