fdgi

Spooktroscopy package containing various versions of spooktroscopy classes

https://github.com/congzlwag/spook

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 2 DOI reference(s) in README
  • Academic publication links
    Links to: iop.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.7%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

Spooktroscopy package containing various versions of spooktroscopy classes

Basic Info
  • Host: GitHub
  • Owner: congzlwag
  • License: mit
  • Language: Jupyter Notebook
  • Default Branch: main
  • Size: 2.58 MB
Statistics
  • Stars: 4
  • Watchers: 1
  • Forks: 2
  • Open Issues: 0
  • Releases: 7
Created about 4 years ago · Last pushed 11 months ago
Metadata Files
Readme License Citation

README.md

Spooktroscopy: Spectral-Domain Ghost Imaging

Target Problem

Solve for $X$ from $(A \otimes G)X = B$ in the least-square manner, under regularizations. The full-index representation of the objective to minimize is $\sum{iq}|\sum{w,b}A{iw}G{bq}X{wb} - B{iq}|^2$ . | Index | $i$ | $w$ | $q$ | $b$ | |--------------------|------|-------------------|--------------------|---------------------| |What does it number?| shot | photon energy bin | observed property | interested property | |Example 0 | shot | photon energy bin | kinetic energy | kinetic energy | |Example 1 | shot | photon energy bin | projected momentum | coefficient on a basis function |

G is an optional linear operator from a function of the interested property (discretized by index $b$) to a function of the observed property (discretized by index $q$), e.g. from a KE spectrum to a KE spectrum. By default G=None, $G=I$ is the identity matrix. This is the most common use case of spooktroscopy, i.e. to solve $AX=B$ without any extra linear mapping. When G accommodates a linear operation that's not identity mapping, the two linear inversions are solved in a single step.

With mode='raw', pass in matrix $G{bq}$ to G, and with mode='contracted', pass in matrix $\sumqG{bq}G{b'q}$. For example, for Abel transform in Velocity Map Imaging, pBasex offers this G with loadG.

Key Advantages

The key advantages of this package are 1. Efficient optimization: Contraction over shots is decoupled from optimization. It is recommended to input precontracted results when instantiating, or to save the caches using method save_prectr of a solver created with raw inputs. Once instantiated, the precontracted results are cached to be reused every time solving with a different hyperparameter. See spook.contraction_utils.adaptive_contraction . 2. Support dimension reduction on the dependent variable B, through basis functions in G. In that case, it is also recommended to contract (B,G) over the dependent variable space (index q) prior to instantiating a spook solver. 3. Support multiple combinations of regularizations. See Solvers . 4. Support time-dependent measurement (Beta): when each entry in the raw input A is a pair of (photon spectrum, delay bin), index w is the flattened axis of ($\omega, \tau$). In this case, the third smoothness hyperparameter is for the delay axis.

At the very bottom level, this package depends on either OSQP to solve a quadratic programming or LAPACK gesv through numpy.linalg.solve .

Installation

The stable version is on PyPI. Unfortunately in a different name. bash pip install FDGI

Solvers

Different combinations of regularizations can lead to different forms of objective function. Solvers in package always formalize the specific problem into either a Quadratic Programming or a linear equation. Examples can be found in unit tests

| Nonnegativity | Sparsity | Smoothness | Solver | Notes | | ------------- | ------------------- | ---------- | ------------------- | ------------------------------------------------------------ | | True | L1 | Quadratic | SpookPosL1 | This solver can serve tasks like in Li et al | | True | L2 squared | Quadratic | SpookPosL2 | | | False | L2 squared | Quadratic | SpookLinSolve | This solver is so far the work-horse for SpookVMI | | False | L1 | Quadratic | SpookL1 | |

A family tree of solvers is in docs/figs/famtree.svg.

Quadratic Programming

For cases where it can be formalized into a Quadratic Programming , OSQP is the weight-lifter. The root numerical method is the alternating direction method of multipliers (ADMM). Looking into the solver settings of OSQP is always encouraged, but the default settings usually work fine for spook . If one needs to pass in settings, use spk._prob.update_settings(**osqp_kwargs) on your solver instance spk.

Linear Equation

A rare case that it can be formalized into a linear equation is the third line in the table above: no nonnegativity constraint, and the sparsity is L2 norm squared. This is implemented in SpookLinSolve , which calls numpy.linalg.solve or scipy.sparse.linalg.spsolve .

Regularizations

Common regularizations are the following three types, all of which optional, depending on what a prior knowledge one wants to enforce on the problem solving.

  1. Nonnegativity: To constrain $X\geq 0$ everywhere
  2. Sparsity: To penalize on $|X|1$ or $|X|2$
  3. Smoothness: To penalize on roughness of X , along the two dimensions indexed by $w$ and $b$ independently. For the dimension indexed by $w$, the form is fixed to the laplacian-square $|(L\otimes I) X|^2_2$ where $L$ is the laplacian. Roughness along the second dimension of X is customizable with input parameter Bsmoother, which by default is laplacian squared too.

Sparsity and Smoothness are enforced through penalties in the total obejctive function, and the penalties are weighted by hyperparameters lsparse and lsmooth. lsmooth is a 2-tuple that weight roughness penalty along the two axes of X respectively. The hyperparameters can be passed in during instantiation and also updated afterwards. It is recommended to call method getXopt with the hyperparameter(s) to be updated, because it will update, solve, and return the optimal X in one step. Calling solve with the hyperparameter(s) to be updated and then calling getXopt() without input is effectively the same, and the problem will be solved once as long as there is no update.

Evaluating Terms of Objective Function

| Term | Method | Notes | |------|--------|-------| | $|(A \otimes G)X-B|2$ | residueL2| For full docstring, check help(spk.residueL2), where spk is a solver instance. | | $|L X|2$ | smoothness | By default, $L$ is a 2nd-order finite difference operator along dimension specified by input argument dim. For full docstring, check help(spk.smoothness). | | $|X|1$ or $|X|2$ | sparsity | Depends on solver class. |

  • Method residueL2 is based on function utils.calcL2fromContracted. This function evaluates the residual term from the precontracted results. Also see XValidation.calc_residual defined in xval.py.
  • Function utils.calcL2fromContracted is also used in the cross-validation class XValidation to evaluate the residual on validation sets. See xval.py for more details.

Normalization Convention

The entries in $A^TA, G^TG$ are preferred to be on the order of unity, because regularization-related quadratic form matrices have their entries around unity. The scale factors are set as

$$sa=\sqrt{\frac{1}{Nw}\mathrm{tr}(A^TA)},sg=\sqrt{\frac{1}{Nq}\mathrm{tr}(G^TG)}$$

where $Nw, Nq$ are the dimensions along the respective indices. $sasg$ is an accessible property of the solver AGscale. To normalize or not is controlled by parameter normalize in creating a solver.

By default normalize=True, i.e. self._AtA =$A^TA/sa^2$, `self.GtG=$G^TG/s_g^2$, andself.Bcontracted` = $(A^T \otimes G^T)B/(sasg)$, and the normalization is not in-place starting from version 0.9.4 . In this case, the direct solution self.res is scaled as $sasg X\mathrm{opt}$ , but the getXopt method returns the unscaled result of $X_\mathrm{opt}$. In v0.9.3 and before, the normalization is in-place, which means the first two arguments are modified in-place. In-place normalization saves memory but causes confusion when people reuses the precontracted results for other purposes after passing them to create a solver in the contracted mode. Therefore starting from v0.9.4, in-place normalization is only done when requested with normalize='inplace' in creating a solver.

With this normalization convention, the hyperparmeters whose associated regularization function is not quadratic in $X$ need scaling when changing the size of dataset. If $h(s X) = s^p h(X)$, then the scaling power of $h(X)$ is $p$, e.g. $p=2$ for quadratic terms. When duplicating the same dataset to $m$ times its original size, in order to keep the optimal point unchanged, we need to set $\lambda\mapsto m^{1-p/2} \lambda$. Therefore for $p=1$ regularization terms, the scaling is $\sqrt{m}$, and for $p=2$ terms they do not scale.

Citing

Please cite Wang et al 2023 when using this package in your publishable work. If SpookPosL1, SpookPosL2 or SpookL1 is used, we also strongly recommend to cite the original OSQP paper as suggested here.

Unit Tests

  • unittest/testPosL1.py is a good example to play with SpookPosL1.
  • unittest/testL1L2.ipynb includes good examples to play with SpookPosL1, SpookPosL2, and SpookL1.
  • unittest/test_resid_reg_eval.py showcases how to evaluate the residual and regularization terms of the objective function.

Dependencies

pip installation should manage the dependencies automatically. If not, check requirements.txt .

Acknowledgement

This work was supported by the U.S. Department of Energy (DOE), Office of Science, Office of Basic Energy Sciences (BES), Chemical Sciences, Geosciences, and Biosciences Division (CSGB).

Documentation

Full documentation is here. Alternatively, clone this repo, switch to gh-pages, and open docs/index.html in a browser.

Owner

  • Name: congzlwag
  • Login: congzlwag
  • Kind: user

Citation (CITATION.cff)

cff-version: 1.2.0
message: "This package is under MIT-license. If you use this software, please cite it as below."
authors:
  - family-names: Wang
    given-names: Jun
    orcid: https://orcid.org/0000-0003-1962-895X
title: "Spook - A package of spectral-domain ghost imaging implementations"
version: 1.0.3
doi:
date-released: 2023-06-23
preferred-citation:
  type: article
  authors:
  - family-names: "Wang"
    given-names: "Jun"
    orcid: "https://orcid.org/0000-0003-1962-895X"
  - family-names: "Driver"
    given-names: "Taran"
  - family-names: "Allum"
    given-names: "Felix"
  - family-names: "Papadopoulou"
    given-names: "Christina C"
  - family-names: "Passow"
    given-names: "Christopher"
  - family-names: "Brenner"
    given-names: "Günter"
  - family-names: "Li"
    given-names: "Siqi"
  - family-names: "Düsterer"
    given-names: "Stefan"
  - family-names: "Noor"
    given-names: "Atia Tul"
  - family-names: "Kumar"
    given-names: "Sonu"
  - family-names: "Bucksbaum"
    given-names: "Philip H."
  - family-names: "Erk"
    given-names: "Benjamin"
  - family-names: "Forbes"
    given-names: "Ruaridh"
  - family-names: "Cryan"
    given-names: "James P."
  journal: "New Journal of Physics"
  title: "Photon energy-resolved velocity map imaging from spectral domain ghost imaging"
  doi: "10.1088/1367-2630/acc201"
  year: 2023
  month: 3
  publisher: "IOP Publishing"
  volume: 25
  number: 3
  start: 033017

GitHub Events

Total
  • Create event: 6
  • Release event: 5
  • Issues event: 7
  • Delete event: 1
  • Issue comment event: 5
  • Push event: 13
  • Pull request review comment event: 1
  • Pull request review event: 1
  • Pull request event: 2
Last Year
  • Create event: 6
  • Release event: 5
  • Issues event: 7
  • Delete event: 1
  • Issue comment event: 5
  • Push event: 13
  • Pull request review comment event: 1
  • Pull request review event: 1
  • Pull request event: 2

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 4
  • Total pull requests: 2
  • Average time to close issues: 5 months
  • Average time to close pull requests: about 22 hours
  • Total issue authors: 2
  • Total pull request authors: 1
  • Average comments per issue: 1.5
  • Average comments per pull request: 0.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 3
  • Pull requests: 2
  • Average time to close issues: about 1 month
  • Average time to close pull requests: about 22 hours
  • Issue authors: 2
  • Pull request authors: 1
  • Average comments per issue: 1.67
  • Average comments per pull request: 0.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • congzlwag (3)
  • TaranDriver (1)
Pull Request Authors
  • congzlwag (2)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 61 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 7
  • Total maintainers: 1
pypi.org: fdgi

A package for spectral-domain ghost imaging

  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 61 Last month
Rankings
Dependent packages count: 10.0%
Forks count: 19.1%
Dependent repos count: 21.7%
Stargazers count: 23.1%
Average: 23.7%
Downloads: 44.5%
Maintainers (1)
Last synced: 7 months ago

Dependencies

requirements.txt pypi
  • numpy >=1.19
  • osqp >=0.6.2
  • scipy >=1.7
.github/workflows/python-publish.yml actions
  • actions/checkout master composite
  • actions/setup-python v4 composite
  • pypa/gh-action-pypi-publish release/v1 composite