Allow last mode to be fixed in decompositions
Problem
In response to #72 and for a few months now, Tensorly has allowed to fix some modes in decompositions, e.g. using the following syntax for parafac:
out = parafac(tensor, rank, fixed_modes=[0,1])
In the above example, the first two modes are fixed, meaning they will not be updated during the iterations of the optimization algorithm.
However, for technical reasons, the last mode may not be fixed, i.e. if the data is a three-way tensor,
out = parafac(tensor, rank, fixed_modes=[0,2])
will raise a warning and mode 2 will not be fixed.
Solution
Note the following two facts:
- the last mode should never be fixed inside the optimization algorithm since the last mode update rule allows for fast error estimation.
- if all modes are fixed then the decomposition should just return the initialization
Therefore, a quick patch would be:
- check if all modes are fixed. If true, then don't run the optimization algorithm.
- Otherwise, if the last mode is fixed, then permute a non-fixed mode with the last one at the beginning of the algorithm, and permute it back in place at the end of the algorithm.
Who can PR for this issue
Anyone :) This is not a difficult fix, so feel free to tackle this issue to get started in Tensorly!
Hi,
Can I try to add code for first part of the solution suggested - check if all modes are fixed. If true, then don't run the optimization algorithm?
-Parvathy