Skip to content

Commit cf67678

Browse files
authored
Add parameter transformation module with new bijective transforms and Jacobian computation (#64)
1 parent 2833ff8 commit cf67678

File tree

3 files changed

+177
-27
lines changed

3 files changed

+177
-27
lines changed

changelog.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,45 @@
11
# Release Notes
22

33

4+
## Version 0.1.5
5+
6+
### New Features
7+
8+
#### Parameter Transformation Module (`braintools.param`)
9+
- **7 new bijective transforms** for constrained optimization and probabilistic modeling:
10+
- **Positive**: Constrains parameters to (0, +∞) using exponential transformation
11+
- **Negative**: Constrains parameters to (-∞, 0) using negative softplus
12+
- **ScaledSigmoid**: Sigmoid with adjustable sharpness/temperature parameter (beta)
13+
- **Power**: Box-Cox family power transformation for variance stabilization
14+
- **Ordered**: Ensures monotonically increasing output vectors (useful for cutpoints in ordinal regression)
15+
- **Simplex**: Stick-breaking transformation for probability vectors summing to 1
16+
- **UnitVector**: Projects vectors onto the unit sphere (L2 norm = 1)
17+
- **Jacobian computation**: Added `log_abs_det_jacobian()` method to Transform base class and implementations for probabilistic modeling
18+
- Implemented for: Identity, Sigmoid, Softplus, Log, Exp, Affine, Chain, Positive
19+
20+
#### Surrogate Gradient Enhancements (`braintools.surrogate`)
21+
22+
- Gradient computation of hyperparameters of surrogate gradient functions.
23+
- Fix batching issue in surrogate gradient functions
24+
25+
26+
### Improvements
27+
28+
#### API Enhancements
29+
- **`__repr__` methods**: Added string representations to all Transform classes and Param class for better debugging
30+
- **Enhanced documentation**: Updated `docs/apis/param.rst` with comprehensive API reference
31+
- Organized sections: Base Classes, Parameter Wrapper, Bounded Transforms, Positive/Negative Transforms, Advanced Transforms, Composition Transforms
32+
- Descriptive explanations for each transform's use case
33+
34+
#### Code Quality
35+
- **Comprehensive test coverage**: Added 28 new tests for param module (45 total tests passing)
36+
- Tests for all new transforms: roundtrip, constraints, repr methods
37+
- Tests for `log_abs_det_jacobian` correctness
38+
- Tests for edge cases and numerical stability
39+
40+
41+
42+
443
## Version 0.1.4
544

645
### New Features

docs/apis/braintools.rst

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,30 +50,3 @@ combining encoder outputs.
5050
spike_bitwise_ixor
5151
spike_bitwise
5252

53-
54-
55-
Parameter Transformations
56-
-------------------------
57-
58-
Smooth and invertible transforms used to keep optimization parameters within
59-
valid domains during training.
60-
61-
.. autosummary::
62-
:toctree: generated/
63-
:nosignatures:
64-
:template: classtemplate.rst
65-
66-
Transform
67-
IdentityTransform
68-
SigmoidTransform
69-
SoftplusTransform
70-
NegSoftplusTransform
71-
LogTransform
72-
ExpTransform
73-
TanhTransform
74-
SoftsignTransform
75-
AffineTransform
76-
ChainTransform
77-
MaskedTransform
78-
CustomTransform
79-
ClippedTransform

docs/apis/param.rst

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
``braintools.param`` module
2+
===========================
3+
4+
.. currentmodule:: braintools.param
5+
.. automodule:: braintools.param
6+
7+
Parameter transformation module for constrained optimization and probabilistic modeling.
8+
Provides bijective transforms that map between unconstrained and constrained parameter spaces.
9+
10+
Overview
11+
--------
12+
13+
The ``braintools.param`` module provides:
14+
15+
- **Bijective transformations** for mapping parameters between constrained and unconstrained domains
16+
- **Parameter wrapper** (``Param``) that automatically applies transforms during optimization
17+
- **Jacobian computation** via ``log_abs_det_jacobian`` for probabilistic modeling
18+
- **Composition utilities** for building complex transforms from simple ones
19+
20+
Base Classes
21+
------------
22+
23+
These classes provide the foundational architecture for all transforms in the module.
24+
The ``Transform`` class defines the common interface with ``forward``, ``inverse``,
25+
and ``log_abs_det_jacobian`` methods.
26+
27+
.. autosummary::
28+
:toctree: generated/
29+
:nosignatures:
30+
:template: classtemplate.rst
31+
32+
Transform
33+
Identity
34+
35+
Parameter Wrapper
36+
-----------------
37+
38+
The ``Param`` class wraps parameter values and automatically applies bijective
39+
transformations. It stores values in unconstrained space internally while exposing
40+
constrained values via the ``.data`` property.
41+
42+
.. autosummary::
43+
:toctree: generated/
44+
:nosignatures:
45+
:template: classtemplate.rst
46+
47+
Param
48+
49+
Bounded Transforms
50+
------------------
51+
52+
These transforms map unbounded values to bounded intervals. They are useful for
53+
parameters that must lie within specific ranges, such as probabilities, correlation
54+
coefficients, or physical quantities with known bounds.
55+
56+
.. autosummary::
57+
:toctree: generated/
58+
:nosignatures:
59+
:template: classtemplate.rst
60+
61+
Sigmoid
62+
ScaledSigmoid
63+
Tanh
64+
Softsign
65+
Clip
66+
67+
- **Sigmoid**: Maps ℝ → [lower, upper] using the logistic sigmoid function
68+
- **ScaledSigmoid**: Sigmoid with adjustable sharpness/temperature parameter
69+
- **Tanh**: Maps ℝ → (lower, upper) using hyperbolic tangent
70+
- **Softsign**: Maps ℝ → (lower, upper) using softsign function
71+
- **Clip**: Hard clipping to bounds (non-bijective)
72+
73+
Positive/Negative Transforms
74+
----------------------------
75+
76+
These transforms constrain parameters to be strictly positive or negative.
77+
They are commonly used for variance parameters, rate constants, and other
78+
quantities that must maintain a specific sign.
79+
80+
.. autosummary::
81+
:toctree: generated/
82+
:nosignatures:
83+
:template: classtemplate.rst
84+
85+
Softplus
86+
NegSoftplus
87+
Log
88+
Exp
89+
Positive
90+
Negative
91+
92+
- **Softplus**: Maps ℝ → [lower, ∞) using log(1 + exp(x))
93+
- **NegSoftplus**: Maps ℝ → (-∞, upper] using negative softplus
94+
- **Log/Exp**: Maps ℝ → (lower, ∞) using exponential transformation
95+
- **Positive**: Convenience class for (0, ∞) constraint
96+
- **Negative**: Convenience class for (-∞, 0) constraint
97+
98+
Advanced Transforms
99+
-------------------
100+
101+
These transforms implement sophisticated constraints for specialized applications
102+
in probabilistic modeling, ordinal regression, and directional statistics.
103+
104+
.. autosummary::
105+
:toctree: generated/
106+
:nosignatures:
107+
:template: classtemplate.rst
108+
109+
Power
110+
Ordered
111+
Simplex
112+
UnitVector
113+
114+
- **Power**: Box-Cox family power transformation for variance stabilization
115+
- **Ordered**: Ensures monotonically increasing output vectors (useful for cutpoints)
116+
- **Simplex**: Stick-breaking transformation for probability vectors summing to 1
117+
- **UnitVector**: Projects vectors onto the unit sphere (L2 norm = 1)
118+
119+
Composition Transforms
120+
----------------------
121+
122+
These transforms allow building complex transformations from simpler ones.
123+
They support chaining, masking, and custom user-defined transformations.
124+
125+
.. autosummary::
126+
:toctree: generated/
127+
:nosignatures:
128+
:template: classtemplate.rst
129+
130+
Affine
131+
Chain
132+
Masked
133+
Custom
134+
135+
- **Affine**: Linear transformation y = ax + b
136+
- **Chain**: Composes multiple transforms sequentially
137+
- **Masked**: Applies transform selectively based on boolean mask
138+
- **Custom**: User-defined transformation with custom forward/inverse functions

0 commit comments

Comments
 (0)