Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use adaptive integration in sasmodels (Trac #392) #535

Open
pkienzle opened this issue Mar 30, 2019 · 6 comments
Open

use adaptive integration in sasmodels (Trac #392) #535

pkienzle opened this issue Mar 30, 2019 · 6 comments

Comments

@pkienzle
Copy link
Contributor

pkienzle commented Mar 30, 2019

Adaptive integration can get much more accurate results for the same number of function evaluations. This will require a rewrite of the polydispersity loops, the resolution calculation, and the spherical integration used to evaluate 1D models from oriented shapes. Our simple use of opencl which evaluates the form factor over a fixed set of q will become much more complicated.

See ticket #347 for slit_test.py, an implementation of slit smearing with adaptive and non-adaptive integration using scipy.

Migrated from http://trac.sasview.org/ticket/392

{
    "status": "new",
    "changetime": "2019-03-02T00:21:21",
    "_ts": "2019-03-02 00:21:21.423016+00:00",
    "description": "Adaptive integration can get much more accurate results for the same number of function evaluations.  This will require a rewrite of the polydispersity loops, the resolution calculation, and the spherical integration used to evaluate 1D models from oriented shapes.  Our simple use of opencl which evaluates the form factor over a fixed set of q will become much more complicated.\n\nSee ticket SasView/sasview#312 for slit_test.py, an implementation of slit smearing with adaptive and non-adaptive integration using scipy.",
    "reporter": "pkienzle",
    "cc": "",
    "resolution": "",
    "workpackage": "SasModels Infrastructure",
    "time": "2015-03-23T14:54:36",
    "component": "SasView",
    "summary": "use adaptive integration in sasmodels",
    "priority": "major",
    "keywords": "",
    "milestone": "SasView Next Release +1",
    "owner": "",
    "type": "enhancement"
}
@butlerpd
Copy link
Member

Trac update at 2015/08/14 20:25:50: butler changed milestone from "WishList" to "SasView Next Release +1"

@pkienzle
Copy link
Contributor Author

Trac update at 2015/11/13 00:17:48: pkienzle commented:

At least we should move to using trapezoid rule rather than mid-point rule to make better use of our calculated q points.

For both Q_parallel and Q_perpendicular resolution, the trapezoid rule implementation in resolution.romberg_slit_1d (yes, the function is poorly named...) give a better result than the current implementation in resolution.slit_resolution. We should be able to incorporate the interpolation into the weight matrix calculation without too much trouble, and give a better result for no additional cost.

@pkienzle
Copy link
Contributor Author

Trac update at 2015/11/16 16:15:42: pkienzle commented:

Comments pulled in from #347 so we can close that ticket:

I compared both Igor and sasview to a direct implementation of the slit smearing integral using adaptive integration. Although neither is correct, the Igor implementation is much closer.

Looking at the code in sasview, I do not see where the residual term is added. This is the power law approximation to the tail of the distribution from q_max to q_max + Delta q_vertical. Maybe that is enough to explain the difference.

I implemented replacement resolution functions in sasmodels, though I do not yet use them in the fit. The basic idea is to continue to use a weight matrix, but allow it to be non-square, with calculated q values extrapolated to the full range of the resolution function. At least for the test problem (spheres of 6 micro radius), rectangular integration gets with 2.5% relative error for about the same number of evaluations. Trapezoid and Simpson’s rule don’t do any better. [Note: still hard to believe that trapz and simpson don't out-perform rectangular; may want to try across a broader range of shapes and sizes.]

The attached file (slit_test.py) will let you explore the various implementations. It contains a python implementation of the sphere model so that it depends only on scipy, numpy and matplotlib.

Made slit_test.py into a GIST so that we can edit it.

 https://gist.github.com/pkienzle/2faa18591b7d82d4d62d

Things to try:

use power law interpolation between points rather than linear interpolation. 

use sampling around each point to average over the oscillations 

use logarithmic rather than linear bin edges 

These can be tried independently or together.

@pkienzle
Copy link
Contributor Author

Trac update at 2015/11/17 23:32:40: pkienzle commented:

Note that the resolution matrix is fixed throughout the fit; it would be easy enough to through this matrix onto the GPU and apply the resolution before returning the q values.

@pkienzle
Copy link
Contributor Author

Trac update at 2015/11/17 23:34:29: pkienzle commented:

In lieu of adaptive integration, we could define an oversampling factor based on the maximum length scale of the form, so that we have at least N points in each 2 pi/d interval.

@butlerpd
Copy link
Member

Trac update at 2019/03/02 00:21:21: butler changed workpackage from "SasModels Redesign" to "SasModels Infrastructure"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants