lasso-net / lassonet

Feature selection in neural networks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Having trouble with backtrack option

p-smirnov opened this issue · comments

I just pulled the latest version, and am trying out training with backtrack on. I am getting an error:

Initialized dense model in 28 epochs, val loss 9.84e-02, regularization 1.39e+01
Traceback (most recent call last):
  File "/home/psmirnov/Code/Github/lassonet_exp/lassonet/examples/ctrpv2_lassonet_path.py", line 103, in <module>
    path = model.path(inner_train_X, inner_train_y.reshape(-1), X_val=valid_X, y_val=valid_y.reshape(-1))
  File "/home/psmirnov/Code/Github/lassonet_exp/lassonet/lassonet/interfaces.py", line 369, in path
    self._train(
  File "/home/psmirnov/Code/Github/lassonet_exp/lassonet/lassonet/interfaces.py", line 270, in _train
    loss = real_loss
UnboundLocalError: local variable 'real_loss' referenced before assignment

I think in your code, it corresponds to line 260 (I added tracking of some metrics other than loss on the validation set).

I suspect this is happening when val_obj < real_best_val_obj condition on line 249 is not met prior to early stopping breaking out of the loop. I think real_loss would be unassigned then.

Indeed, you are right. It's sad because it means the objective didn't improve at all.

I just pushed a fix that uses the running loss of the first epoch as fallback.

Note that the reported loss is not very precise because it's a running loss (if you use mini-batches) and also because we don't recompute it after the last epoch.