Changeset abad620 in sasview for pr_inversion/c_extensions
- Timestamp:
- May 8, 2008 10:55:47 AM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 4241e48
- Parents:
- 2e07e8f
- Location:
- pr_inversion/c_extensions
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pr_inversion/c_extensions/Cinvertor.c
r2d06beb rabad620 319 319 double regterm = 0.0; 320 320 double tmp = 0.0; 321 // Number of slices in regularization term estimate 322 int nslice = 25; 321 323 322 324 PyObject *data_obj; … … 331 333 residuals = PyList_New(self->params.npoints); 332 334 333 regterm = reg_term(pars, self->params.d_max, npars );335 regterm = reg_term(pars, self->params.d_max, npars, nslice); 334 336 335 337 for(i=0; i<self->params.npoints; i++) { … … 367 369 double regterm = 0.0; 368 370 double tmp = 0.0; 371 // Number of slices in regularization term estimate 372 int nslice = 25; 369 373 370 374 PyObject *data_obj; … … 378 382 residuals = PyList_New(self->params.npoints); 379 383 380 regterm = reg_term(pars, self->params.d_max, npars );384 regterm = reg_term(pars, self->params.d_max, npars, nslice); 381 385 382 386 … … 465 469 if (!PyArg_ParseTuple(args, "did", &d_max, &n, &q)) return NULL; 466 470 return Py_BuildValue("f", ortho_transformed(d_max, n, q)); 471 472 } 473 474 static PyObject * oscillations(Cinvertor *self, PyObject *args) { 475 double *pars; 476 PyObject *data_obj; 477 Py_ssize_t npars; 478 double oscill, norm; 479 480 if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 481 OUTVECTOR(data_obj,pars,npars); 482 483 oscill = reg_term(pars, self->params.d_max, npars, 100); 484 norm = int_p2(pars, self->params.d_max, npars, 100); 485 return Py_BuildValue("f", sqrt(oscill/norm)/acos(-1.0)*self->params.d_max ); 467 486 468 487 } … … 489 508 {"is_valid", (PyCFunction)is_valid, METH_VARARGS, ""}, 490 509 {"basefunc_ft", (PyCFunction)basefunc_ft, METH_VARARGS, ""}, 510 {"oscillations", (PyCFunction)oscillations, METH_VARARGS, ""}, 491 511 492 512 {NULL} -
pr_inversion/c_extensions/invertor.c
r2d06beb rabad620 1 1 #include <math.h> 2 2 #include "invertor.h" 3 #include <memory.h> 4 #include <stdio.h> 5 #include <stdlib.h> 3 6 4 7 double pi = 3.1416; … … 120 123 * regularization term calculated from the expansion. 121 124 */ 122 double reg_term(double *pars, double d_max, int n_c ) {125 double reg_term(double *pars, double d_max, int n_c, int nslice) { 123 126 double sum = 0.0; 124 127 double r; 125 128 double deriv; 126 129 int i; 127 for (i=0; i< 25; i++) {128 r = d_max/ 25.0*i;130 for (i=0; i<nslice; i++) { 131 r = d_max/(1.0*nslice)*i; 129 132 deriv = dprdr(pars, d_max, n_c, r); 130 133 sum += deriv*deriv; 131 134 } 132 return sum/ 25.0*d_max;135 return sum/(1.0*nslice)*d_max; 133 136 } 134 137 138 /** 139 * regularization term calculated from the expansion. 140 */ 141 double int_p2(double *pars, double d_max, int n_c, int nslice) { 142 double sum = 0.0; 143 double r; 144 double value; 145 int i; 146 for (i=0; i<nslice; i++) { 147 r = d_max/(1.0*nslice)*i; 148 value = pr(pars, d_max, n_c, r); 149 sum += value*value; 150 } 151 return sum/(1.0*nslice)*d_max; 152 } 153 -
pr_inversion/c_extensions/invertor.h
r2d06beb rabad620 26 26 double pr(double *c, double d_max, int n_c, double r); 27 27 double dprdr(double *pars, double d_max, int n_c, double r); 28 double reg_term(double *pars, double d_max, int n_c); 28 double reg_term(double *pars, double d_max, int n_c, int nslice); 29 double int_p2(double *pars, double d_max, int n_c, int nslice); 29 30 void pr_err(double *pars, double *err, double d_max, int n_c, 30 31 double r, double *pr_value, double *pr_value_err);
Note: See TracChangeset
for help on using the changeset viewer.