Package: ffsas
v1.1Free-Form inversion forSmall-AngleScattering (SAS)ffsasis a Python library to invert for free-form distributions of model
parameters in a polydisperse SAS system. It yields the maximum likelihood
estimator of the parameter distributions and the sensitivity and uncertainty
of the maximum likelihood estimator.ffsascomes with the following features:Generality:ffsasformulates the SAS inverse problem as a
Green's-tensor-based multi-linear map, which coversanycomplex SAS models with
multiple parameters. An arbitrary model can be easily implemented by
supplying the Green's function for forward modelling, i.e., a function
that computes the monodisperse intensity on a structured grid of model parameters
(i.e., the Green's tensor). In short, users only need to care about the
physics for forward modelling, leaving the inverse problem all toffsas.
Besides, it does not require an initial guess of the parameter
distributions, the scaling factor or the source background.Efficiency: through theoretical analysis, the inverse problem is
simplified as a highly solvable nonlinear programming (NLP) problem
with a few equality constraints. It is solved by a trust-region method,
implemented in SciPy asscipy.optimize.minimize(method='trust-constr'),
officially mentioned as "the most versatile constrained minimization algorithm
implemented in SciPy and the most appropriate for large-scale problems".
Computation of the Jacobian and Hessian of the χ2 error, as the most expensive
step during solution, is accelerated by GPU and mini-batch computation.
The idea is borrowed from deep learning and implemented with PyTorch.Accuracy: the model parameters and the resulting intensity in a SAS problem
can span many orders of magnitude, and a good choice of unit system is essential
to avoid an ill-conditioned inverse problem.ffsasautomaticallyanalyzes
the orders of magnitude of data and parameters so as to determine a proper internal
unit system to avoid accuracy loss. Such an internal unit system is hidden
from users, who can use an arbitrary unit system for input and output.Usability:ffsascan be installed withpipin one line. Its usage only
includes four APIs respectively forcomputing the Green's tensorGgiven a model and a parameter spacedefine aG-system with this Green's tensorusing thisG-system to compute intensity given parameter
distributions (forward modelling)using thisG-system to invert for parameter distributions given
intensity data (inversion)A built-in logging system produces detailed and readable logs during these processes.Quick StartTo installffsas:pipinstallffsasFollow theUser Guideto learn the usage.CitationFull paper (open access):http://doi.org/10.1107/S1600576722006379BIBTex:@article{Leng:jl5041,author="Leng, Kuangdai and King, Stephen and Snow, Tim and Rogers, Sarah and Markvardsen, Anders and Maheswaran, Satheesh and Thiyagalingam, Jeyan",title="{Parameter inversion of a polydisperse system in small-angle scattering}",journal="Journal of Applied Crystallography",year="2022",volume="55",number="4",pages="966--977",month="Aug",doi={10.1107/S1600576722006379},url={https://doi.org/10.1107/S1600576722006379},}Funding and SupportThis work was supported by the ISIS Neutron and Muon Source (ISIS) of the Science and Technology Facilities Council through the ISIS-ML funding, and by Wave I of the UKRI Strategic Priorities Fund under the EPSRC grant (EP/T001569/1), particularly the AI for Science theme in that grant and the Alan Turing Institute. We gratefully acknowledge their support.