Changeset abad620 in sasview


Ignore:
Timestamp:
May 8, 2008 10:55:47 AM (17 years ago)
Author:
Mathieu Doucet <doucetm@…>
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
Message:

Added alpha estimate

Location:
pr_inversion
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pr_inversion/c_extensions/Cinvertor.c

    r2d06beb rabad620  
    319319        double regterm = 0.0; 
    320320        double tmp = 0.0; 
     321        // Number of slices in regularization term estimate 
     322        int nslice = 25; 
    321323         
    322324        PyObject *data_obj; 
     
    331333    residuals = PyList_New(self->params.npoints); 
    332334 
    333     regterm = reg_term(pars, self->params.d_max, npars); 
     335    regterm = reg_term(pars, self->params.d_max, npars, nslice); 
    334336     
    335337    for(i=0; i<self->params.npoints; i++) { 
     
    367369        double regterm = 0.0; 
    368370        double tmp = 0.0; 
     371        // Number of slices in regularization term estimate 
     372        int nslice = 25; 
    369373         
    370374        PyObject *data_obj; 
     
    378382    residuals = PyList_New(self->params.npoints); 
    379383 
    380     regterm = reg_term(pars, self->params.d_max, npars); 
     384    regterm = reg_term(pars, self->params.d_max, npars, nslice); 
    381385 
    382386     
     
    465469        if (!PyArg_ParseTuple(args, "did", &d_max, &n, &q)) return NULL; 
    466470        return Py_BuildValue("f", ortho_transformed(d_max, n, q));       
     471         
     472} 
     473 
     474static 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 );     
    467486         
    468487} 
     
    489508                   {"is_valid", (PyCFunction)is_valid, METH_VARARGS, ""}, 
    490509                   {"basefunc_ft", (PyCFunction)basefunc_ft, METH_VARARGS, ""}, 
     510                   {"oscillations", (PyCFunction)oscillations, METH_VARARGS, ""}, 
    491511    
    492512   {NULL} 
  • pr_inversion/c_extensions/invertor.c

    r2d06beb rabad620  
    11#include <math.h> 
    22#include "invertor.h" 
     3#include <memory.h> 
     4#include <stdio.h> 
     5#include <stdlib.h> 
    36 
    47double pi = 3.1416; 
     
    120123 * regularization term calculated from the expansion. 
    121124 */ 
    122 double reg_term(double *pars, double d_max, int n_c) { 
     125double reg_term(double *pars, double d_max, int n_c, int nslice) { 
    123126    double sum = 0.0;  
    124127    double r; 
    125128    double deriv; 
    126129        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; 
    129132        deriv = dprdr(pars, d_max, n_c, r); 
    130133        sum += deriv*deriv; 
    131134    } 
    132     return sum/25.0*d_max; 
     135    return sum/(1.0*nslice)*d_max; 
    133136} 
    134137 
     138/** 
     139 * regularization term calculated from the expansion. 
     140 */ 
     141double 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  
    2626double pr(double *c, double d_max, int n_c, double r); 
    2727double dprdr(double *pars, double d_max, int n_c, double r); 
    28 double reg_term(double *pars, double d_max, int n_c); 
     28double reg_term(double *pars, double d_max, int n_c, int nslice); 
     29double int_p2(double *pars, double d_max, int n_c, int nslice); 
    2930void pr_err(double *pars, double *err, double d_max, int n_c,  
    3031                double r, double *pr_value, double *pr_value_err); 
  • pr_inversion/invertor.py

    r2d06beb rabad620  
    88    ## Time elapsed for last computation 
    99    elapsed = 0 
     10    ## Alpha to get the reg term the same size as the signal 
     11    suggested_alpha = 0 
    1012     
    1113    def __init__(self): 
     
    191193                     
    192194        new_alpha = sum_sig/(sum_reg/self.alpha) 
    193         print "Suggested alpha =", 0.1*new_alpha 
     195        self.suggested_alpha = new_alpha 
    194196         
    195197        try: 
Note: See TracChangeset for help on using the changeset viewer.