Skip to content

Commit feea4a8

Browse files
committed
Update license headers, fix additional ruff errors
1 parent 14687f3 commit feea4a8

File tree

13 files changed

+314
-102
lines changed

13 files changed

+314
-102
lines changed

NOTICE.yml

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,81 @@
3737
- 'conda/**/*.yml'
3838

3939
- header: |
40-
Regularized contrastive learning implementation.
40+
CEBRA: Consistent EmBeddings of high-dimensional Recordings using Auxiliary variables
41+
© Mackenzie W. Mathis & Steffen Schneider (v0.4.0+)
42+
Source code:
43+
https://github.com/AdaptiveMotorControlLab/CEBRA
44+
45+
Please see LICENSE.md for the full license document:
46+
https://github.com/AdaptiveMotorControlLab/CEBRA/blob/main/LICENSE.md
47+
48+
Adapted from https://github.com/rpatrik96/nl-causal-representations/blob/master/care_nl_ica/dep_mat.py,
49+
licensed under the following MIT License:
50+
51+
MIT License
52+
53+
Copyright (c) 2022 Patrik Reizinger
54+
55+
Permission is hereby granted, free of charge, to any person obtaining a copy
56+
of this software and associated documentation files (the "Software"), to deal
57+
in the Software without restriction, including without limitation the rights
58+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
59+
copies of the Software, and to permit persons to whom the Software is
60+
furnished to do so, subject to the following conditions:
61+
62+
The above copyright notice and this permission notice shall be included in all
63+
copies or substantial portions of the Software.
4164
42-
Not licensed yet. Distribution for review.
43-
Code will be open-sourced upon publication.
65+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
66+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
67+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
68+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
69+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
70+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
71+
SOFTWARE.
4472
4573
include:
46-
- 'cebra/solver/multiobjective.py'
47-
- 'cebra/solver/regularized.py'
48-
- 'cebra/solver/metrics.py'
49-
- 'cebra/models/multiobjective.py'
50-
- 'cebra/models/multi_criterions.py'
51-
- 'cebra/data/multiobjective.py'
52-
- 'cebra/attribution/*.py'
53-
- 'tests/test_multiobjective.py'
74+
- 'cebra/attribution/jacobian.py'
75+
5476

5577
- header: |
56-
Copyright (c) Facebook, Inc. and its affiliates.
78+
CEBRA: Consistent EmBeddings of high-dimensional Recordings using Auxiliary variables
79+
© Mackenzie W. Mathis & Steffen Schneider (v0.4.0+)
80+
Source code:
81+
https://github.com/AdaptiveMotorControlLab/CEBRA
82+
83+
Please see LICENSE.md for the full license document:
84+
https://github.com/AdaptiveMotorControlLab/CEBRA/blob/main/LICENSE.md
85+
86+
This file contains the PyTorch implementation of Jacobian regularization described in [1].
87+
Judy Hoffman, Daniel A. Roberts, and Sho Yaida,
88+
"Robust Learning with Jacobian Regularization," 2019.
89+
[arxiv:1908.02729](https://arxiv.org/abs/1908.02729)
90+
91+
Adapted from https://github.com/facebookresearch/jacobian_regularizer/blob/main/jacobian/jacobian.py
92+
licensed under the following MIT License:
93+
94+
MIT License
95+
96+
Copyright (c) Facebook, Inc. and its affiliates.
5797
58-
This source code is licensed under the MIT license found in the
59-
LICENSE file in the root directory of this source tree.
98+
Permission is hereby granted, free of charge, to any person obtaining a copy
99+
of this software and associated documentation files (the "Software"), to deal
100+
in the Software without restriction, including without limitation the rights
101+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
102+
copies of the Software, and to permit persons to whom the Software is
103+
furnished to do so, subject to the following conditions:
60104
61-
PyTorch implementation of Jacobian regularization described in [1].
105+
The above copyright notice and this permission notice shall be included in all
106+
copies or substantial portions of the Software.
62107
63-
[1] Judy Hoffman, Daniel A. Roberts, and Sho Yaida,
64-
"Robust Learning with Jacobian Regularization," 2019.
65-
[arxiv:1908.02729](https://arxiv.org/abs/1908.02729)
108+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
109+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
110+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
111+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
112+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
113+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
114+
SOFTWARE.
66115
67116
include:
68117
- 'cebra/models/jacobian_regularizer.py'

cebra/attribution/__init__.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
#
2-
# Regularized contrastive learning implementation.
2+
# CEBRA: Consistent EmBeddings of high-dimensional Recordings using Auxiliary variables
3+
# © Mackenzie W. Mathis & Steffen Schneider (v0.4.0+)
4+
# Source code:
5+
# https://github.com/AdaptiveMotorControlLab/CEBRA
36
#
4-
# Not licensed yet. Distribution for review.
5-
# Code will be open-sourced upon publication.
7+
# Please see LICENSE.md for the full license document:
8+
# https://github.com/AdaptiveMotorControlLab/CEBRA/blob/main/LICENSE.md
9+
#
10+
# Licensed under the Apache License, Version 2.0 (the "License");
11+
# you may not use this file except in compliance with the License.
12+
# You may obtain a copy of the License at
13+
#
14+
# http://www.apache.org/licenses/LICENSE-2.0
15+
#
16+
# Unless required by applicable law or agreed to in writing, software
17+
# distributed under the License is distributed on an "AS IS" BASIS,
18+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
# See the License for the specific language governing permissions and
20+
# limitations under the License.
621
#
722
import cebra.registry
823

cebra/attribution/attribution_models.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
#
2-
# Regularized contrastive learning implementation.
2+
# CEBRA: Consistent EmBeddings of high-dimensional Recordings using Auxiliary variables
3+
# © Mackenzie W. Mathis & Steffen Schneider (v0.4.0+)
4+
# Source code:
5+
# https://github.com/AdaptiveMotorControlLab/CEBRA
36
#
4-
# Not licensed yet. Distribution for review.
5-
# Code will be open-sourced upon publication.
7+
# Please see LICENSE.md for the full license document:
8+
# https://github.com/AdaptiveMotorControlLab/CEBRA/blob/main/LICENSE.md
9+
#
10+
# Licensed under the Apache License, Version 2.0 (the "License");
11+
# you may not use this file except in compliance with the License.
12+
# You may obtain a copy of the License at
13+
#
14+
# http://www.apache.org/licenses/LICENSE-2.0
15+
#
16+
# Unless required by applicable law or agreed to in writing, software
17+
# distributed under the License is distributed on an "AS IS" BASIS,
18+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
# See the License for the specific language governing permissions and
20+
# limitations under the License.
621
#
722
import dataclasses
823
import time

cebra/attribution/jacobian.py

Lines changed: 31 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
11
#
2-
# Regularized contrastive learning implementation.
2+
# CEBRA: Consistent EmBeddings of high-dimensional Recordings using Auxiliary variables
3+
# © Mackenzie W. Mathis & Steffen Schneider (v0.4.0+)
4+
# Source code:
5+
# https://github.com/AdaptiveMotorControlLab/CEBRA
36
#
4-
# Not licensed yet. Distribution for review.
5-
# Code will be open-sourced upon publication.
7+
# Please see LICENSE.md for the full license document:
8+
# https://github.com/AdaptiveMotorControlLab/CEBRA/blob/main/LICENSE.md
9+
#
10+
# Adapted from https://github.com/rpatrik96/nl-causal-representations/blob/master/care_nl_ica/dep_mat.py,
11+
# licensed under the following MIT License:
12+
#
13+
# MIT License
14+
#
15+
# Copyright (c) 2022 Patrik Reizinger
16+
#
17+
# Permission is hereby granted, free of charge, to any person obtaining a copy
18+
# of this software and associated documentation files (the "Software"), to deal
19+
# in the Software without restriction, including without limitation the rights
20+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21+
# copies of the Software, and to permit persons to whom the Software is
22+
# furnished to do so, subject to the following conditions:
23+
#
24+
# The above copyright notice and this permission notice shall be included in all
25+
# copies or substantial portions of the Software.
26+
#
27+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33+
# SOFTWARE.
634
#
7-
"""
8-
Source: https://github.com/rpatrik96/nl-causal-representations/blob/master/care_nl_ica/dep_mat.py
9-
MIT License
10-
Copyright (c) 2022 Patrik Reizinger
11-
Permission is hereby granted, free of charge, to any person obtaining a copy
12-
of this software and associated documentation files (the "Software"), to deal
13-
in the Software without restriction, including without limitation the rights
14-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15-
copies of the Software, and to permit persons to whom the Software is
16-
furnished to do so, subject to the following conditions:
17-
The above copyright notice and this permission notice shall be included in all
18-
copies or substantial portions of the Software.
19-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25-
SOFTWARE.
26-
"""
2735

2836
import torch
2937

30-
_FUNCTORCH_AVAILABLE = False
31-
try:
32-
from functorch import jacfwd
33-
from functorch import jacrev
34-
from functorch import vmap
35-
36-
_FUNCTORCH_AVAILABLE = True
37-
except ModuleNotFoundError:
38-
import warnings
39-
40-
warnings.warn("Could not import functorch. "
41-
"Jacobian computation will be limited "
42-
"to autograd mode.")
43-
4438

4539
def tensors_to_cpu_and_double(vars_):
4640
cpu_vars = []
@@ -103,15 +97,6 @@ def compute_jacobian(
10397

10498
jacobian = torch.stack(jacob, dim=1)
10599

106-
elif mode == "functorch":
107-
if not _FUNCTORCH_AVAILABLE:
108-
raise ModuleNotFoundError("functorch")
109-
else:
110-
# TODO (if required in the future)
111-
raise NotImplementedError
112-
113-
# jacobian_mean = jacobian.abs().mean(0).detach().cpu()
114-
# jacobian_max = jacobian.abs().max(0)[0].detach().cpu()
115100
jacobian = jacobian.detach().cpu()
116101

117102
if convert_to_numpy:

cebra/attribution/jacobian_attribution.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
#
2-
# Regularized contrastive learning implementation.
2+
# CEBRA: Consistent EmBeddings of high-dimensional Recordings using Auxiliary variables
3+
# © Mackenzie W. Mathis & Steffen Schneider (v0.4.0+)
4+
# Source code:
5+
# https://github.com/AdaptiveMotorControlLab/CEBRA
36
#
4-
# Not licensed yet. Distribution for review.
5-
# Code will be open-sourced upon publication.
7+
# Please see LICENSE.md for the full license document:
8+
# https://github.com/AdaptiveMotorControlLab/CEBRA/blob/main/LICENSE.md
9+
#
10+
# Licensed under the Apache License, Version 2.0 (the "License");
11+
# you may not use this file except in compliance with the License.
12+
# You may obtain a copy of the License at
13+
#
14+
# http://www.apache.org/licenses/LICENSE-2.0
15+
#
16+
# Unless required by applicable law or agreed to in writing, software
17+
# distributed under the License is distributed on an "AS IS" BASIS,
18+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
# See the License for the specific language governing permissions and
20+
# limitations under the License.
621
#
722
"""Tools for computing attribution maps."""
823

@@ -47,7 +62,6 @@ def get_attribution_map(
4762
The result is a `(num_inputs, num_features)` attribution map.
4863
"""
4964
assert aggregate in ["mean", "sum", "max"]
50-
agg = getattr(np, aggregate)
5165

5266
input_data = _prepare_inputs(input_data)
5367
model = _prepare_model(model)

cebra/data/multiobjective.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
#
2-
# Regularized contrastive learning implementation.
2+
# CEBRA: Consistent EmBeddings of high-dimensional Recordings using Auxiliary variables
3+
# © Mackenzie W. Mathis & Steffen Schneider (v0.4.0+)
4+
# Source code:
5+
# https://github.com/AdaptiveMotorControlLab/CEBRA
36
#
4-
# Not licensed yet. Distribution for review.
5-
# Code will be open-sourced upon publication.
7+
# Please see LICENSE.md for the full license document:
8+
# https://github.com/AdaptiveMotorControlLab/CEBRA/blob/main/LICENSE.md
9+
#
10+
# Licensed under the Apache License, Version 2.0 (the "License");
11+
# you may not use this file except in compliance with the License.
12+
# You may obtain a copy of the License at
13+
#
14+
# http://www.apache.org/licenses/LICENSE-2.0
15+
#
16+
# Unless required by applicable law or agreed to in writing, software
17+
# distributed under the License is distributed on an "AS IS" BASIS,
18+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
# See the License for the specific language governing permissions and
20+
# limitations under the License.
621
#
722

823
import literate_dataclasses as dataclasses

cebra/models/jacobian_regularizer.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,43 @@
11
#
2-
# Copyright (c) Facebook, Inc. and its affiliates.
2+
# CEBRA: Consistent EmBeddings of high-dimensional Recordings using Auxiliary variables
3+
# © Mackenzie W. Mathis & Steffen Schneider (v0.4.0+)
4+
# Source code:
5+
# https://github.com/AdaptiveMotorControlLab/CEBRA
36
#
4-
# This source code is licensed under the MIT license found in the
5-
# LICENSE file in the root directory of this source tree.
7+
# Please see LICENSE.md for the full license document:
8+
# https://github.com/AdaptiveMotorControlLab/CEBRA/blob/main/LICENSE.md
69
#
7-
# PyTorch implementation of Jacobian regularization described in [1].
10+
# This file contains the PyTorch implementation of Jacobian regularization described in [1].
11+
# Judy Hoffman, Daniel A. Roberts, and Sho Yaida,
12+
# "Robust Learning with Jacobian Regularization," 2019.
13+
# [arxiv:1908.02729](https://arxiv.org/abs/1908.02729)
814
#
9-
# [1] Judy Hoffman, Daniel A. Roberts, and Sho Yaida,
10-
# "Robust Learning with Jacobian Regularization," 2019.
11-
# [arxiv:1908.02729](https://arxiv.org/abs/1908.02729)
15+
# Adapted from https://github.com/facebookresearch/jacobian_regularizer/blob/main/jacobian/jacobian.py
16+
# licensed under the following MIT License:
1217
#
18+
# MIT License
19+
#
20+
# Copyright (c) Facebook, Inc. and its affiliates.
21+
#
22+
# Permission is hereby granted, free of charge, to any person obtaining a copy
23+
# of this software and associated documentation files (the "Software"), to deal
24+
# in the Software without restriction, including without limitation the rights
25+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26+
# copies of the Software, and to permit persons to whom the Software is
27+
# furnished to do so, subject to the following conditions:
28+
#
29+
# The above copyright notice and this permission notice shall be included in all
30+
# copies or substantial portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
#
40+
1341
from __future__ import division
1442

1543
import torch

cebra/models/multi_criterions.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
#
2-
# Regularized contrastive learning implementation.
2+
# CEBRA: Consistent EmBeddings of high-dimensional Recordings using Auxiliary variables
3+
# © Mackenzie W. Mathis & Steffen Schneider (v0.4.0+)
4+
# Source code:
5+
# https://github.com/AdaptiveMotorControlLab/CEBRA
36
#
4-
# Not licensed yet. Distribution for review.
5-
# Code will be open-sourced upon publication.
7+
# Please see LICENSE.md for the full license document:
8+
# https://github.com/AdaptiveMotorControlLab/CEBRA/blob/main/LICENSE.md
9+
#
10+
# Licensed under the Apache License, Version 2.0 (the "License");
11+
# you may not use this file except in compliance with the License.
12+
# You may obtain a copy of the License at
13+
#
14+
# http://www.apache.org/licenses/LICENSE-2.0
15+
#
16+
# Unless required by applicable law or agreed to in writing, software
17+
# distributed under the License is distributed on an "AS IS" BASIS,
18+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
# See the License for the specific language governing permissions and
20+
# limitations under the License.
621
#
722
from typing import Tuple
823

0 commit comments

Comments
 (0)