Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
10cf530
relax atol tolerance for consistence with other single precision tests
garrettwrong Apr 20, 2020
ebb169c
Add simple daily build for master and develop branches
garrettwrong Apr 20, 2020
fedc45d
Merge pull request #146 from ComputationalCryoEM/dbg_ci_windows
garrettwrong Apr 24, 2020
cd0f195
rough draft of a BlockDiagonal class
garrettwrong Apr 8, 2020
019696e
add unit tests and port apply/solve
garrettwrong Apr 14, 2020
28566ea
Use BlockDiagonal in Basis subclass' fb_mat (filter_to_fb_mat)
garrettwrong Apr 14, 2020
38ca17d
remove cython setup for now, can optimize later if required
garrettwrong Apr 15, 2020
39040a0
Zeros~>Ones typo in test name
garrettwrong Apr 15, 2020
c3b282f
Change BlockDiagonal module to blk_diag_matrix module
garrettwrong Apr 16, 2020
a9b68ce
replace BlockDiagonal class name with BlkDiagMatrix
garrettwrong Apr 16, 2020
e4086c9
rm stray debugging comments from implementation changeover
garrettwrong Apr 16, 2020
e74c37b
cleanup a dtype setter, rm warning todo note
garrettwrong Apr 16, 2020
9958fc5
deprecate 'BlkDiagMatrix.minus'
garrettwrong Apr 16, 2020
3a3cbf3
name change
garrettwrong Apr 16, 2020
25c1fab
address style improvement comments
garrettwrong Apr 16, 2020
4b2416d
ensure all methods and top of file have doc string
garrettwrong Apr 16, 2020
6036965
address isscalar and isnumeric, adds test
garrettwrong Apr 16, 2020
6abb190
rm note to self comment
garrettwrong Apr 17, 2020
ccc2459
correct corner case ndarray overloading
garrettwrong Apr 17, 2020
1680fa1
tidy up top level docstring breif
garrettwrong Apr 17, 2020
4c63c76
revert cols abbrv, docstring formatting
garrettwrong Apr 20, 2020
aa043a7
discern getter/setter function doc string
garrettwrong Apr 20, 2020
e9d7820
Pep8 style compliance
garrettwrong Apr 20, 2020
a7f08f1
Cleanup based on request feedback
garrettwrong Apr 24, 2020
d30660e
Add some periods to doc strings
garrettwrong Apr 24, 2020
ac08f67
address the easier merge request review comments
garrettwrong Apr 24, 2020
741e5eb
Implement a utility function for id() checks of in place BlkDiagMatri…
garrettwrong Apr 27, 2020
03eb340
Refactor to use BlkDiagMatrix.*_like(). Fix a rebasing conflict
garrettwrong Apr 27, 2020
4caa6ac
Continue _like conversion, removing most of get_partition
garrettwrong Apr 27, 2020
179717e
convert constructor to partition, and add empty/append methods
garrettwrong Apr 27, 2020
f83a6b4
refactor methods to use inplace arg
garrettwrong Apr 27, 2020
91e3718
rm stray debug print
garrettwrong Apr 27, 2020
993e9fa
rm import that is no longer called here
garrettwrong Apr 27, 2020
227000e
Remove redundant newaxis for BlkDiagMatrix.apply in cov2d
garrettwrong Apr 28, 2020
e690cbd
add square array check for BlkDiagMatrix constructor, setter, and doc
garrettwrong Apr 28, 2020
ebbf0ed
Remove circular dependence by moving mat_to_blk_diag into from_mat in…
garrettwrong Apr 28, 2020
e57e195
Add the parameter to pass the size of images explicitly
junchaoxia Apr 28, 2020
79a925e
Correct PR suggestions
garrettwrong Apr 30, 2020
c18ce12
Move staticmethods together at end of class
garrettwrong Apr 30, 2020
ee24ec2
Implement the derived class for Dirac basis
junchaoxia Apr 14, 2020
41307ba
Initially add the class for 2D polar Fourier basis function
junchaoxia Apr 21, 2020
2380b98
Improve and refactor DiracBasis class
junchaoxia Apr 28, 2020
06ac878
Improve and refactor PolarBasis2D class
junchaoxia Apr 30, 2020
b322b6f
Add unit test for evaluate function of PolarFourier class
junchaoxia Apr 30, 2020
e8e3472
Merge pull request #144 from garrettwrong/blk_diag_class
garrettwrong May 1, 2020
dfb2805
Rearrange the constructor and _build function
junchaoxia May 5, 2020
64b6ee3
Move expand function to base class
junchaoxia May 7, 2020
5ce61a9
Change representing dimensions and add normalization factor in PolarF…
junchaoxia May 8, 2020
fefb446
Add unit test for ajoint operator and remove the normalization factor
junchaoxia May 11, 2020
7f0d93b
fix typos in names
junchaoxia May 11, 2020
a732bf8
Add an example contributors table in markdown (#147)
garrettwrong May 19, 2020
c110cb6
Update PF2D adjoint test
janden May 28, 2020
07946b8
Rename pf → x
janden May 28, 2020
756e93e
Only use half of freqs in PolarBasis2D.evaluate
janden May 28, 2020
bb1363a
Merge pull request #151 from ComputationalCryoEM/orientation
junchaoxia May 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
ASPIRE has contributions from a growing team of collaborators.
To learn more about them please visit our `Team webpage <http://spr.math.princeton.edu/team>`_.

Developers of the Python and Matlab collection of ASPIRE codes are listed below.


|


.. table:: Python Contributors

+------------------+--------------+---------------------------+----------------------+
| Name | GithubID | Email | Affiliations |
+==================+==============+===========================+======================+
| Joakim Andén | janden | [email protected] | Princeton University |
+------------------+--------------+---------------------------+----------------------+
| Vineet Bansal | vineetbansal | [email protected] | Princeton University |
+------------------+--------------+---------------------------+----------------------+
| Robbie Brook | rbrook | [email protected] | Princeton University |
+------------------+--------------+---------------------------+----------------------+
| Ayelet Heimowitz | ayeltg | [email protected] | Princeton University |
+------------------+--------------+---------------------------+----------------------+
| Gabi Pragier | pgabi | [email protected] | Tel Aviv University |
+------------------+--------------+---------------------------+----------------------+
| Itay Sason | itaysason | [email protected] | Tel Aviv University |
+------------------+--------------+---------------------------+----------------------+
| Yoel Shkolnisky | yoelsh | [email protected] | Tel Aviv University |
+------------------+--------------+---------------------------+----------------------+
| Amit Singer | amitsinger | [email protected] | Princeton University |
+------------------+--------------+---------------------------+----------------------+
| Garrett Wright | garrettwrong | [email protected] | Princeton University |
+------------------+--------------+---------------------------+----------------------+
| Junchao Xia | junchaoxia | [email protected] | Princeton University |
+------------------+--------------+---------------------------+----------------------+

|


.. table:: Additional MATLAB Contributors not listed above:


+-------------+----------+-------+----------------------+
| Name | GithubID | Email | Affiliations |
+=============+==========+=======+======================+
| Mar Cohen | | | Tel Aviv University |
+-------------+----------+-------+----------------------+
| Lanhui Wang | | | Princeton University |
+-------------+----------+-------+----------------------+
| Jane Zhao | | | Princeton University |
+-------------+----------+-------+----------------------+


If we've missed you or would like to update your details, please contact us and we'll be happy to do so.
17 changes: 13 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
schedules:
- cron: "0 0 * * *" # cron syntax defining a schedule
displayName: Daily Build
branches:
include:
- master
- develop
always: true # Always run the Daily Build

jobs:
- job:
displayName: ubuntu-latest
Expand Down Expand Up @@ -36,7 +45,7 @@ jobs:

# - bash: conda update -q -y conda
# displayName: Update conda

- bash: conda env create --name myEnvironment --file environment.yml
displayName: Create Anaconda environment

Expand Down Expand Up @@ -96,10 +105,10 @@ jobs:

- bash: conda clean -i -t -y
displayName: Removing conda cached package tarballs.

- bash: conda env create --name myEnvironment --file environment.yml
displayName: Create Anaconda environment

- bash: |
source activate myEnvironment
python setup.py install
Expand Down Expand Up @@ -149,7 +158,7 @@ jobs:

- script: conda update -q -y conda
displayName: Update conda

- script: |
call activate myEnvironment
python setup.py install
Expand Down
4 changes: 4 additions & 0 deletions docs/source/authors.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Authors
=======

.. include:: ../../CONTRIBUTORS.rst
3 changes: 2 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ linear and nonlinear dimensionality reduction, randomized algorithms in numerica
installation
quickstart
modules
authors


Indices and tables
Expand All @@ -30,4 +31,4 @@ Indices and tables
References
==========

.. bibliography:: references.bib
.. bibliography:: references.bib
59 changes: 31 additions & 28 deletions src/aspire/basis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Basis:
Define a base class for expanding 2D particle images and 3D structure volumes

"""
def __init__(self, size, ell_max=None):
def __init__(self, size, ell_max=None, dtype=np.float64):
"""
Initialize an object for the base of basis class

Expand All @@ -36,6 +36,9 @@ def __init__(self, size, ell_max=None):
self.count = 0
self.ell_max = ell_max
self.ndim = ndim
self.dtype = dtype
if self.dtype != np.float64:
raise NotImplementedError("Currently only implemented for default double (np.float64) type")

self._build()

Expand Down Expand Up @@ -149,46 +152,46 @@ def mat_evaluate_t(self, X):
"""
return mdim_mat_fun_conj(X, len(self.sz), 1, self.evaluate_t)

def expand(self, v):
def expand(self, x):
"""
Expand array in basis
Obtain coefficients in the basis from those in standard coordinate basis

This is a similar function to `evaluate_t` but with more accuracy by
using the cg optimizing of linear equation, Ax=b.
This is a similar function to evaluate_t but with more accuracy by using
the cg optimizing of linear equation, Ax=b.

If `v` is a matrix of size `basis.ct`-by-..., `B` is the change-of-basis
matrix of this basis, and `x` is a matrix of size `self.sz`-by-...,
the function calculates v = (B' * B)^(-1) * B' * x, where the rows
of `B` and columns of `x` are read as vectorized arrays.

:param v: An array whose first few dimensions are to be expanded in this basis.
These dimensions must equal `self.sz`.
:return: The coefficients of `v` expanded in this basis. If more than
one array of size `self.sz` is found in `v`, the second and higher
dimensions of the return value correspond to those higher dimensions of `v`.
:param x: An array whose first two or three dimensions are to be expanded
the desired basis. These dimensions must equal `self.sz`.
:return : The coefficients of `v` expanded in the desired basis.
The first dimension of `v` is with size of `count` and the
second and higher dimensions of the return value correspond to
those higher dimensions of `x`.

"""
ensure(v.shape[:self.ndim] == self.sz, f'First {self.ndim} dimensions of v must match {self.sz}.')
# ensure the first dimensions with size of self.sz
x, sz_roll = unroll_dim(x, self.ndim + 1)
ensure(x.shape[:self.ndim] == self.sz,
f'First {self.ndim} dimensions of x must match {self.sz}.')

v, sz_roll = unroll_dim(v, self.ndim + 1)
b = self.evaluate_t(v)
operator = LinearOperator(
shape=(self.count, self.count),
matvec=lambda x: self.evaluate_t(self.evaluate(x))
)
operator = LinearOperator(shape=(self.count, self.count),
matvec=lambda v: self.evaluate_t(self.evaluate(v)))

# TODO: (from MATLAB implementation) - Check that this tolerance make sense for multiple columns in v
tol = 10 * np.finfo(v.dtype).eps
tol = 10*np.finfo(x.dtype).eps
logger.info('Expanding array in basis')
v, info = cg(operator, b, tol=tol)

v = v[..., np.newaxis]
# number of image samples
n_data = np.size(x, self.ndim)
v = np.zeros((self.count, n_data), dtype=x.dtype)

if info != 0:
raise RuntimeError('Unable to converge!')
for isample in range(0, n_data):
b = self.evaluate_t(x[..., isample])
# TODO: need check the initial condition x0 can improve the results or not.
v[..., isample], info = cg(operator, b, tol=tol)
if info != 0:
raise RuntimeError('Unable to converge!')

# return v coefficients with the first dimension of self.count
v = roll_dim(v, sz_roll)

return v

def expand_t(self, v):
Expand Down
71 changes: 70 additions & 1 deletion src/aspire/basis/dirac.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,74 @@
import logging
import numpy as np

from aspire.basis import Basis
from aspire.utils.matrix import roll_dim, unroll_dim
from aspire.utils.matlab_compat import m_flatten, m_reshape

logger = logging.getLogger(__name__)


class DiracBasis(Basis):
pass
"""
Define a derived class for Dirac basis
"""
def __init__(self, sz, mask=None):
"""
Initialize an object for Dirac basis
:param sz: The shape of the vectors for which to define the basis.
:param mask: A boolean _mask of size sz indicating which coordinates
to include in the basis (default np.full(sz, True)).
"""
if mask is None:
mask = np.full(sz, True)
self._mask = m_flatten(mask)

super().__init__(sz)

def _build(self):
"""
Build the internal data structure to Dirac basis
"""
logger.info('Expanding object in a Dirac basis.')
self.count = np.sum(self._mask)
self._sz_prod = self.nres ** self.ndim

def evaluate(self, v):
"""
Evaluate coefficients in standard coordinate basis from those in Dirac basis

:param v: A coefficient vector (or an array of coefficient vectors) to
be evaluated. The first dimension must equal `self.count`.
:return: The evaluation of the coefficient vector(s) `v` for this basis.
This is an array whose first dimensions equal `self.sz` and the remaining
dimensions correspond to dimensions two and higher of `v`.
"""
v, sz_roll = unroll_dim(v, 2)
x = np.zeros(shape=(self._sz_prod,) + v.shape[1:])
x[self._mask, ...] = v
x = m_reshape(x, self.sz + x.shape[1:])
x = roll_dim(x, sz_roll)

return x

def evaluate_t(self, x):
"""
Evaluate coefficient in Dirac basis from those in standard coordinate basis

:param x: The coefficient array to be evaluated. The first dimensions
must equal `self.sz`.
:return: The evaluation of the coefficient array `v` in the dual basis
of `basis`. This is an array of vectors whose first dimension equals
`self.count` and whose remaining dimensions correspond to
higher dimensions of `v`.
"""
x, sz_roll = unroll_dim(x, self.ndim + 1)
x = m_reshape(x, new_shape=(self._sz_prod,) + x.shape[self.ndim:])
v = np.zeros(shape=(self.count, ) + x.shape[1:])
v = x[self._mask, ...]
v = roll_dim(v, sz_roll)

return v

def expand(self, x):
return self.evaluate_t(x)
45 changes: 0 additions & 45 deletions src/aspire/basis/ffb_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
from numpy import pi
from scipy.special import jv
from scipy.fftpack import ifft, fft
from scipy.sparse.linalg import LinearOperator, cg

from aspire.nfft import anufft3, nufft3

from aspire.utils import ensure
from aspire.utils.matrix import roll_dim, unroll_dim
from aspire.utils.matlab_compat import m_reshape
from aspire.basis.basis_utils import lgwt
Expand Down Expand Up @@ -246,45 +243,3 @@ def evaluate_t(self, x):
# return v coefficients with the first dimension of self.count
v = roll_dim(v, sz_roll)
return v

def expand(self, x):
"""
Obtain coefficients in FB basis from those in standard 2D coordinate basis

This is a similar function to evaluate_t but with more accuracy by using
the cg optimizing of linear equation, Ax=b.

:param x: An array whose first two dimensions are to be expanded in FB basis.
These dimensions must equal `self.sz`.
:return : The coefficients of `v` expanded in FB basis. The first dimension
of `v` is with size of `count` and the second and higher dimensions
of the return value correspond to those higher dimensions of `x`.

"""
# ensure the first two dimensions with size of self.sz
x, sz_roll = unroll_dim(x, self.ndim + 1)
x = m_reshape(x, (self.sz[0], self.sz[1], -1))
ensure(x.shape[:self.ndim] == self.sz,
f'First {self.ndim} dimensions of x must match {self.sz}.')

operator = LinearOperator(shape=(self.count, self.count),
matvec=lambda v: self.evaluate_t(self.evaluate(v)))

# TODO: (from MATLAB implementation) - Check that this tolerance make sense for multiple columns in v
tol = 10*np.finfo(x.dtype).eps
logger.info('Expanding array in basis')

# number of image samples
n_data = np.size(x, self.ndim)
v = np.zeros((self.count, n_data), dtype=x.dtype)

for isample in range(0, n_data):
b = self.evaluate_t(x[..., isample])
# TODO: need check the initial condition x0 can improve the results or not.
v[..., isample], info = cg(operator, b, tol=tol)
if info != 0:
raise RuntimeError('Unable to converge!')

# return v coefficients with the first dimension of self.count
v = roll_dim(v, sz_roll)
return v
Loading