Skip to content

Commit

Permalink
vaniall cpse resolved #34
Browse files Browse the repository at this point in the history
  • Loading branch information
msuzen committed Sep 17, 2022
1 parent 3bda4d4 commit ce97f96
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@ pip install -upgrade git+https://github.com/msuzen/bristol.git
## Documentation
### Complexity of a deep learning model: cPSE

### Vanilla case

In the vanilla case a list of matrices that are representative of
ordered set of weight matrices can be used to compute cPSE over
layers. As an examples:

```python
from bristol import cPSE
import numpy as np
np.random.seed(42)
matrices = [np.random.normal(size=(64,64)) for _ in range(10)]
(d_layers, cpse) = cPSE.cpse_measure_vanilla(matrices)
```
Even for set of Gaussian matrices, d_layers decrease.
Note that different layer types should be converted to a matrix
format, i.e., CNNs to 2D matrices. See the main paper.

### For torch models
You need to put your model as pretrained model format of PyTorch. An example for vgg,
and use `cPSE.cpse_measure` function simply:

Expand Down
15 changes: 15 additions & 0 deletions bristol/cPSE.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,19 @@ def cpse_measure(pmodel):
d_layers = d_layers_pse(eset_per)
return d_layers, np.mean(np.log10(d_layers))

def cpse_measure_vanilla(matrices):
"""
Given list of weight matrices.
pse on layers and mean log pse Cascading PSE
(d_layers, cpse) : d_layers vector and real number cpse
np.random.seed(42)
matrices = [np.random.normal(size=(64,64)) for _ in range(10)]
(d_layers, cpse) = cPSE.cpse_measure_vanilla(matrices)
"""
eset = get_eigenvals_layer_matrix_set(matrices)
eset_per = eigenvals_set_to_periodic(eset)
d_layers = d_layers_pse(eset_per)
return d_layers, np.mean(np.log10(d_layers))
2 changes: 1 addition & 1 deletion bristol/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__='0.2.11'
__version__='0.2.12'

0 comments on commit ce97f96

Please sign in to comment.