Skip to content

Commit

Permalink
Add missing error raising and test for adapt on Multissession (#114)
Browse files Browse the repository at this point in the history
Add missing error raising and test
  • Loading branch information
CeliaBenquet authored Dec 15, 2023
1 parent e2d9831 commit b8d9424
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cebra/integrations/sklearn/cebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ def _adapt_model(

dataset, is_multisession = self._prepare_data(X, y)

if is_multisession:
if is_multisession or isinstance(self.model_, nn.ModuleList):
raise NotImplementedError(
"The adapt option with a multisession training is not handled. Please use adapt=True for single-trained estimators only."
)
Expand Down
42 changes: 42 additions & 0 deletions tests/test_sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,48 @@ def check_first_layer_dim(model, X):
cebra_model.fit([X, X_s2], [y_c1, y_c1_s2], adapt=True)


@_util.parametrize_slow(
arg_names="model_architecture,device",
fast_arguments=list(
itertools.islice(
itertools.product(
cebra_sklearn_cebra.CEBRA.supported_model_architectures(),
_DEVICES),
2,
)),
slow_arguments=list(
itertools.product(
cebra_sklearn_cebra.CEBRA.supported_model_architectures(),
_DEVICES)),
)
def test_sklearn_adapt_multisession(model_architecture, device):
num_hidden_units = 32
cebra_model = cebra_sklearn_cebra.CEBRA(
model_architecture=model_architecture,
time_offsets=10,
learning_rate=3e-4,
max_iterations=5,
max_adapt_iterations=1,
device=device,
output_dimension=4,
num_hidden_units=num_hidden_units,
batch_size=42,
verbose=True,
)

# example dataset
Xs = [np.random.uniform(0, 1, (1000, 50)) for i in range(3)]
ys = [np.random.uniform(0, 1, (1000, 5)) for i in range(3)]

X_new = np.random.uniform(0, 1, (1000, 50))
y_new = np.random.uniform(0, 1, (1000, 5))

cebra_model.fit(Xs, ys)

with pytest.raises(NotImplementedError, match=".*multisession.*"):
cebra_model.fit(X_new, y_new, adapt=True)


@_util.parametrize_slow(
arg_names="model_architecture,device,pad_before_transform",
fast_arguments=list(
Expand Down

0 comments on commit b8d9424

Please sign in to comment.