commsubspace 0.3.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commsubspace
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Communication subspaces between neural populations: CCA, reduced-rank regression and contrastive communication subspaces (cCS).
5
5
  Author-email: Eliezyer de Oliveira <eliezyer.deoliveira@gmail.com>
6
6
  License-Expression: MIT
@@ -5,6 +5,6 @@ from .communication_subspace import CrossDecomposition, ReducedRankRegress
5
5
  from .contrastive_communication_subspace import cCS
6
6
 
7
7
  # Keep in sync with ``version`` in pyproject.toml (checked by tests/test_packaging.py).
8
- __version__ = "0.3.0"
8
+ __version__ = "0.4.0"
9
9
 
10
10
  __all__ = ["cCS", "CrossDecomposition", "ReducedRankRegress", "__version__"]
@@ -24,12 +24,21 @@ condition, of either sign, lies inside it. By default the basis is truncated
24
24
  by numerical rank (condition number; ``basis_truncation='condition_number'``,
25
25
  tolerance ``max(shape) * eps`` like ``numpy.linalg.matrix_rank``).
26
26
 
27
- Noise floor (advanced, off by default)
28
- --------------------------------------
29
- ``noise_floor`` ('none' by default; 'analytic', 'shuffle', or a number) lets users
30
- who want to control weakly coupled directions put a lower bound on the singular
31
- values that enter the denominators of the generalized objectives. With the
32
- default 'none' the denominators are used as estimated. See the class docstring.
27
+ Noise floor (on by default)
28
+ ---------------------------
29
+ ``noise_floor`` ('analytic' by default; 'shuffle', 'none', or a number) puts a lower
30
+ bound on the singular values that enter the denominators of the generalized
31
+ objectives, so directions that are pure noise in one condition cannot reach large
32
+ contrast values. With 'none' the denominators are used as estimated. See the
33
+ class docstring.
34
+
35
+ Component order
36
+ ---------------
37
+ Components are sorted by signed sigma, sigma * sign(dominance_), descending:
38
+ components whose coupling is stronger in A come first, in decreasing sigma;
39
+ components stronger in B come last, the one with the largest sigma at the very end.
40
+ A component whose coupling flips sign between conditions has |a| ~ |b|, so its
41
+ dominance_ is near 0 and its sign, hence its position (front or end), is arbitrary.
33
42
 
34
43
  Attributes set by ``fit`` (trailing underscore = fitted):
35
44
  region1_loadings_, region2_loadings_ : unit-norm loadings, (p, N_dim) and (q, N_dim),
@@ -40,7 +49,11 @@ Attributes set by ``fit`` (trailing underscore = fitted):
40
49
  > 0: coupling stronger in A, < 0: stronger in B
41
50
  sign_reversal_ : bool, (N_dim,); True where a * b < 0 (coupling flips sign between
42
51
  conditions; dominance_ is then near 0 although sigma can be large)
43
- All component-wise attributes are sorted by dominance_, descending (A-dominant first).
52
+ signed_sigma_ : sigma * sign(dominance_) per component, (N_dim,), units of sigma;
53
+ the sort key of the components (non-increasing): > 0 for A-dominant,
54
+ < 0 for B-dominant components
55
+ All component-wise attributes are sorted by sigma * sign(dominance_), descending
56
+ (A-dominant first by sigma, B-dominant last; see "Component order").
44
57
  region{1,2}_scores_cond{A,B} : fitted data projected on the loadings, (n_samples, N_dim)
45
58
  region1_basis_, region2_basis_ : orthonormal support bases, (p, m1) and (q, m2)
46
59
  basis_dims_ : (m1, m2)
@@ -63,7 +76,10 @@ from ._linalg import floored_polar_roots, psd_inverse_sqrt_factor
63
76
  from ._noise_floor import (analytic_noise_floor, random_circular_shift,
64
77
  shuffle_noise_floor)
65
78
 
66
- ANALYSIS_VERSION = "cCS-0.3.0" # 0.3.0: components sorted by dominance_ instead of contrast value
79
+ # 0.3.0: components sorted by dominance_ instead of contrast value.
80
+ # 0.4.0: components sorted by signed sigma (sigma * sign(dominance_)); noise_floor
81
+ # defaults to 'analytic' instead of 'none'.
82
+ ANALYSIS_VERSION = "cCS-0.4.0"
67
83
 
68
84
  _METHODS = ('difference', 'ratio', 'normalized_difference', 'normalized_index')
69
85
  _NOISE_FLOOR_MODES = ('analytic', 'shuffle', 'none')
@@ -112,20 +128,20 @@ class cCS:
112
128
  for ``shuffle_null``.
113
129
  random_state : int
114
130
  Seed of the random generator used by the shuffle procedures.
115
- noise_floor : {'none', 'analytic', 'shuffle'}, float or (float, float)
116
- Advanced option, off by default. Controls a lower bound ("floor") on the
117
- singular values of each condition's cross-covariance as they enter the
118
- denominators of the generalized objectives ('ratio',
119
- 'normalized_difference', 'normalized_index'); it does not change the
120
- numerator, the support basis (unless ``basis_truncation='noise_floor'``)
121
- or the 'difference' method.
122
- 'none' (default): denominators are used as estimated; directions in which a
123
- denominator is numerically zero (``condition_number_tol`` rule) are left
124
- out of the solution.
125
- 'analytic': floor from a random-matrix estimate of the cross-covariance
126
- estimation error, see ``_noise_floor``. It is a coarse, global estimate
127
- that assumes independent samples and can penalize weak but real
128
- directions, so compare against 'none' before relying on it.
131
+ noise_floor : {'analytic', 'shuffle', 'none'}, float or (float, float)
132
+ Lower bound ("floor") on the singular values of each condition's
133
+ cross-covariance as they enter the denominators of the generalized
134
+ objectives ('ratio', 'normalized_difference', 'normalized_index'); it does
135
+ not change the numerator, the support basis (unless
136
+ ``basis_truncation='noise_floor'``) or the 'difference' method.
137
+ 'analytic' (default since 0.4.0): floor from a random-matrix estimate of
138
+ the cross-covariance estimation error, see ``_noise_floor``. It is a
139
+ coarse, global estimate that assumes independent samples (set
140
+ ``effective_n`` for autocorrelated data, otherwise the floor is too low)
141
+ and can penalize weak but real directions.
142
+ 'none' (default up to 0.3.0): denominators are used as estimated;
143
+ directions in which a denominator is numerically zero
144
+ (``condition_number_tol`` rule) are left out of the solution.
129
145
  'shuffle': floor from circularly shifted data (``n_shuffles`` shifts,
130
146
  seeded).
131
147
  A float, or a (tau_A, tau_B) pair, is used as given, in the units of the
@@ -138,7 +154,7 @@ class cCS:
138
154
  def __init__(self, method='difference', normalize=True, alpha=1.0,
139
155
  max_cond_number=None, basis_truncation='condition_number',
140
156
  condition_number_tol=None, truncate_basis=True, max_basis_dim=None,
141
- effective_n=None, n_shuffles=50, random_state=0, noise_floor='none'):
157
+ effective_n=None, n_shuffles=50, random_state=0, noise_floor='analytic'):
142
158
  if max_cond_number is not None:
143
159
  warnings.warn("max_cond_number is deprecated and ignored; regularization is "
144
160
  "now controlled by noise_floor.", DeprecationWarning, stacklevel=2)
@@ -241,7 +257,7 @@ class cCS:
241
257
  -------
242
258
  ndarray, (n_shuffles, N_dim)
243
259
  Surrogate objective values (sigma) for the first ``N_dim`` components,
244
- each surrogate sorted by its own ``dominance_`` like the fit
260
+ each surrogate sorted by its own signed sigma like the fit
245
261
  (zero-padded if a surrogate has fewer components).
246
262
  """
247
263
  n_shuffles = self.n_shuffles if n_shuffles is None else n_shuffles
@@ -361,7 +377,8 @@ class cCS:
361
377
  def _set_loadings_and_scores(self, contrast_vectors_1, contrast_vectors_2,
362
378
  region1_A, region2_A, region1_B, region2_B):
363
379
  """Map components back to feature space (unit norm), project the fit data, and
364
- sort all components by ``dominance_`` (A-dominant first, B-dominant last)."""
380
+ sort all components by signed sigma, sigma * sign(dominance_), descending
381
+ (A-dominant first in sigma order, B-dominant last, the largest-sigma one at the end)."""
365
382
  loadings_1 = self.region1_basis_ @ contrast_vectors_1 # (p, N_dim)
366
383
  loadings_2 = self.region2_basis_ @ contrast_vectors_2 # (q, N_dim)
367
384
  self.region1_loadings_ = loadings_1 / norm(loadings_1, axis=0)
@@ -377,13 +394,15 @@ class cCS:
377
394
  self.dominance_ = (np.abs(coupling_A) - np.abs(coupling_B)) / (np.abs(coupling_A) + np.abs(coupling_B))
378
395
  self.sign_reversal_ = coupling_A * coupling_B < 0
379
396
 
380
- # Reorder every component-wise output by dominance, descending.
381
- order = np.argsort(-self.dominance_, kind='stable')
397
+ # Reorder every component-wise output by signed sigma, descending.
398
+ signed_sigma = self.contrast_values_ * np.sign(self.dominance_)
399
+ order = np.argsort(-signed_sigma, kind='stable')
382
400
  for name in ('region1_loadings_', 'region2_loadings_', 'region1_scores_condA', 'region2_scores_condA',
383
401
  'region1_scores_condB', 'region2_scores_condB', 'contrast_values_', 'dominance_',
384
402
  'sign_reversal_'):
385
403
  setattr(self, name, getattr(self, name)[..., order])
386
404
  self.sigma_ = self.contrast_values_
405
+ self.signed_sigma_ = self.contrast_values_ * np.sign(self.dominance_) # (N_dim,) sort key, in fitted order
387
406
 
388
407
  def _build_meta(self):
389
408
  """Metadata describing how the fitted result was produced."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: commsubspace
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Communication subspaces between neural populations: CCA, reduced-rank regression and contrastive communication subspaces (cCS).
5
5
  Author-email: Eliezyer de Oliveira <eliezyer.deoliveira@gmail.com>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "commsubspace"
7
- version = "0.3.0"
7
+ version = "0.4.0"
8
8
  description = "Communication subspaces between neural populations: CCA, reduced-rank regression and contrastive communication subspaces (cCS)."
9
9
  readme = "README.md"
10
10
  license = "MIT"
File without changes
File without changes
File without changes