def rebalance(self):
        """Rescales factors across modes so that all norms match.
        """

        # Compute norms along columns for each factor matrix
        norms = [sci.linalg.norm(f, axis=0) for f in self.factors]

        # Multiply norms across all modes
        lam = sci.multiply.reduce(norms) ** (1/self.ndim)

        # Update factors
        self.factors = [f * (lam / fn) for f, fn in zip(self.factors, norms)]
        return self
def rebalance ( self ) : norms = [ sci . linalg . norm ( f , axis = 0 ) for f in self . factors ] lam = sci . multiply . reduce ( norms ) ** ( 1 / self . ndim ) self . factors = [ f * ( lam / fn ) for f , fn in zip ( self . factors , norms ) ] return self
Rescales factors across modes so that all norms match.