Changeset 43c0a8e in sasview for pr_inversion/c_extensions


Ignore:
Timestamp:
May 23, 2008 10:55:39 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:
dfb58f8
Parents:
eb06cbe
Message:

Add a couple of figures of merit

Location:
pr_inversion/c_extensions
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pr_inversion/c_extensions/Cinvertor.c

    rf71287f4 r43c0a8e  
    492492        PyObject *err_obj; 
    493493        Py_ssize_t npars2; 
    494            
     494        int i;  
     495         
    495496        if (!PyArg_ParseTuple(args, "OOd", &data_obj, &err_obj, &r)) return NULL; 
    496         OUTVECTOR(data_obj,pars,npars); 
     497        OUTVECTOR(data_obj,pars,npars);  
    497498        OUTVECTOR(err_obj,pars_err,npars2); 
    498                  
     499 
    499500        pr_err(pars, pars_err, self->params.d_max, npars, r, &pr_value, &pr_err_value); 
    500501        return Py_BuildValue("ff", pr_value, pr_err_value);      
     
    537538 
    538539        return Py_BuildValue("i", count );       
     540         
     541} 
     542 
     543static PyObject * get_positive(Cinvertor *self, PyObject *args) { 
     544        double *pars; 
     545        PyObject *data_obj; 
     546        Py_ssize_t npars; 
     547        double fraction; 
     548          
     549        if (!PyArg_ParseTuple(args, "O", &data_obj)) return NULL; 
     550        OUTVECTOR(data_obj,pars,npars); 
     551         
     552        fraction = positive_integral(pars, self->params.d_max, npars, 100); 
     553 
     554        return Py_BuildValue("f", fraction );    
     555         
     556} 
     557 
     558static PyObject * get_pos_err(Cinvertor *self, PyObject *args) { 
     559        double *pars; 
     560        double *pars_err; 
     561        PyObject *data_obj; 
     562        PyObject *err_obj; 
     563        Py_ssize_t npars; 
     564        Py_ssize_t npars2; 
     565        double fraction; 
     566         
     567        if (!PyArg_ParseTuple(args, "OO", &data_obj, &err_obj)) return NULL; 
     568        OUTVECTOR(data_obj,pars,npars);  
     569        OUTVECTOR(err_obj,pars_err,npars2); 
     570         
     571        fraction = positive_errors(pars, pars_err, self->params.d_max, npars, 51); 
     572 
     573        return Py_BuildValue("f", fraction );    
    539574         
    540575} 
     
    567602                   {"oscillations", (PyCFunction)oscillations, METH_VARARGS, ""}, 
    568603                   {"get_peaks", (PyCFunction)get_peaks, METH_VARARGS, ""}, 
     604                   {"get_positive", (PyCFunction)get_positive, METH_VARARGS, ""}, 
     605                   {"get_pos_err", (PyCFunction)get_pos_err, METH_VARARGS, ""}, 
    569606    
    570607   {NULL} 
  • pr_inversion/c_extensions/invertor.c

    rf71287f4 r43c0a8e  
    100100        func_value = ortho(d_max, i+1, r); 
    101101        sum += pars[i] * func_value; 
    102         sum_err += err[i]*err[i]*func_value*func_value; 
     102        //sum_err += err[i]*err[i]*func_value*func_value; 
     103        sum_err += err[i*n_c+i]*func_value*func_value; 
    103104    } 
    104105    *pr_value = sum; 
     
    115116double dprdr(double *pars, double d_max, int n_c, double r) { 
    116117    double sum = 0.0;  
    117         int i; 
     118        int i;  
    118119    for (i=0; i<n_c; i++) { 
    119120        sum += pars[i] * 2.0*(sin(pi*(i+1)*r/d_max) + pi*(i+1)*r/d_max * cos(pi*(i+1)*r/d_max)); 
     
    180181} 
    181182 
     183/** 
     184 * Get the fraction of the integral of P(r) over the whole range 
     185 * of r that is above zero. 
     186 * A valid P(r) is define as being positive for all r. 
     187 */ 
     188double positive_integral(double *pars, double d_max, int n_c, int nslice) { 
     189    double r;  
     190    double value; 
     191        int i; 
     192        double sum_pos = 0.0; 
     193        double sum = 0.0; 
     194         
     195    for (i=0; i<nslice; i++) { 
     196        r = d_max/(1.0*nslice)*i; 
     197        value = pr(pars, d_max, n_c, r); 
     198        if (value>0.0) sum_pos += value; 
     199        sum += value; 
     200    } 
     201    return sum_pos/sum; 
     202} 
     203 
     204/** 
     205 * Get the fraction of the integral of P(r) over the whole range 
     206 * of r that is at least one sigma above zero. 
     207 */ 
     208double positive_errors(double *pars, double *err, double d_max, int n_c, int nslice) { 
     209    double r;  
     210    double value; 
     211        int i;  
     212        double sum_pos = 0.0; 
     213        double sum = 0.0; 
     214        double pr_val; 
     215        double pr_val_err; 
     216         
     217    for (i=0; i<nslice; i++) { 
     218        r = d_max/(1.0*nslice)*i; 
     219        pr_err(pars, err, d_max, n_c, r, &pr_val, &pr_val_err); 
     220        if (pr_val>pr_val_err) sum_pos += pr_val; 
     221        sum += pr_val; 
     222         
     223 
     224    } 
     225    return sum_pos/sum; 
     226} 
  • pr_inversion/c_extensions/invertor.h

    rf71287f4 r43c0a8e  
    3333                double r, double *pr_value, double *pr_value_err); 
    3434int npeaks(double *pars, double d_max, int n_c, int nslice); 
     35double positive_integral(double *pars, double d_max, int n_c, int nslice); 
     36double positive_errors(double *pars, double *err, double d_max, int n_c, int nslice); 
    3537 
    3638#endif 
Note: See TracChangeset for help on using the changeset viewer.