(cls, X, y, weights=None, center=True, scale=True, dim=2, p=1,
                initial=None, maxiter=500, alpha=0.1, atol=1e-5, is_class_discrete=False)
return embeddings, A, center, scale
FreeViz

        Compute a linear lower dimensional projection to optimize separation
        between classes ([1]_).

        Parameters
        ----------
        X : (N, P) ndarray
            The input data instances
        y : (N, ) ndarray
            The instance class labels
        weights : (N, ) ndarray, optional
            Instance weights
        center : bool or (P,) ndarray
            If `True` then X will have mean subtracted out, if False no
            centering is performed. Alternatively can be a P vector to subtract
            from X.
        scale : bool or (P,) ndarray
            If `True` the X's column will be scaled by 1/SD, if False no scaling
            is performed. Alternatively can be a P vector to divide X by.
        dim : int
            The dimension of the projected points/embedding.
        p : positive number
            The force 'power', e.g. if p=1 (default) the attractive/repulsive
            forces follow linear/inverse linear law, for p=2 the forces follow
            square/inverse square law, ...
        initial : (P, dim) ndarray, optional
            Initial projection matrix
        maxiter : int
            Maximum number of iterations.
        alpha : float
            The step size ('learning rate')
        atol : float
            Terminating numerical tolerance (absolute).

        Returns
        -------
        embeddings : (N, dim) ndarray
            The point projections (`= X.dot(P)`)
        projection : (P, dim)
            The projection matrix.
        center : (P,) ndarray or None
            The translation applied to X (if any).
        scale : (P,) ndarray or None
            The scaling applied to X (if any).

        .. [1] Janez Demsar, Gregor Leban, Blaz Zupan
               FreeViz - An Intelligent Visualization Approach for Class-Labeled
               Multidimensional Data Sets, Proceedings of IDAMAP 2005, Edinburgh.
FreeViz
FreeViz
def freeviz(cls, X, y, weights=None, center=True, scale=True, dim=2, p=1,
                initial=None, maxiter=500, alpha=0.1, atol=1e-5, is_class_discrete=False):
        """
        FreeViz

        Compute a linear lower dimensional projection to optimize separation
        between classes ([1]_).

        Parameters
        ----------
        X : (N, P) ndarray
            The input data instances
        y : (N, ) ndarray
            The instance class labels
        weights : (N, ) ndarray, optional
            Instance weights
        center : bool or (P,) ndarray
            If `True` then X will have mean subtracted out, if False no
            centering is performed. Alternatively can be a P vector to subtract
            from X.
        scale : bool or (P,) ndarray
            If `True` the X's column will be scaled by 1/SD, if False no scaling
            is performed. Alternatively can be a P vector to divide X by.
        dim : int
            The dimension of the projected points/embedding.
        p : positive number
            The force 'power', e.g. if p=1 (default) the attractive/repulsive
            forces follow linear/inverse linear law, for p=2 the forces follow
            square/inverse square law, ...
        initial : (P, dim) ndarray, optional
            Initial projection matrix
        maxiter : int
            Maximum number of iterations.
        alpha : float
            The step size ('learning rate')
        atol : float
            Terminating numerical tolerance (absolute).

        Returns
        -------
        embeddings : (N, dim) ndarray
            The point projections (`= X.dot(P)`)
        projection : (P, dim)
            The projection matrix.
        center : (P,) ndarray or None
            The translation applied to X (if any).
        scale : (P,) ndarray or None
            The scaling applied to X (if any).

        .. [1] Janez Demsar, Gregor Leban, Blaz Zupan
               FreeViz - An Intelligent Visualization Approach for Class-Labeled
               Multidimensional Data Sets, Proceedings of IDAMAP 2005, Edinburgh.
        """
        needcopy = center is not False or scale is not False
        X = np.array(X, copy=needcopy)
        y = np.asarray(y)
        N, P = X.shape
        _N, = y.shape
        if N != _N:
            raise ValueError("X and y must have the same length")

        if weights is not None:
            weights = np.asarray(weights)

        if isinstance(center, bool):
            if center:
                center = np.mean(X, axis=0)
            else:
                center = None
        else:
            center = np.asarray(center, dtype=X.dtype)
            if center.shape != (P, ):
                raise ValueError("center.shape != (X.shape[1], ) ({} != {})"
                                 .format(center.shape, (X.shape[1], )))

        if isinstance(scale, bool):
            if scale:
                scale = np.std(X, axis=0)
            else:
                scale = None
        else:
            scale = np.asarray(scale, dtype=X.dtype)
            if scale.shape != (P, ):
                raise ValueError("scale.shape != (X.shape[1],) ({} != {}))"
                                 .format(scale.shape, (P, )))

        if initial is not None:
            initial = np.asarray(initial)
            if initial.ndim != 2 or initial.shape != (P, dim):
                raise ValueError
        else:
            initial = cls.init_random(P, dim)
            # initial = np.random.random((P, dim)) * 2 - 1

        # Center/scale X if requested
        if center is not None:
            X -= center

        if scale is not None:
            scalenonzero = np.abs(scale) > np.finfo(scale.dtype).eps
            X[:, scalenonzero] /= scale[scalenonzero]

        A = initial
        embeddings = np.dot(X, A)

        step_i = 0
        while step_i < maxiter:
            G = cls.freeviz_gradient(X, y, embeddings, p=p, weights=weights,
                                     is_class_discrete=is_class_discrete)

            # Scale the changes (the largest anchor move is alpha * radius)
            with np.errstate(divide="ignore"):  # inf's will be ignored by min
                step = np.min(np.linalg.norm(A, axis=1)
                              / np.linalg.norm(G, axis=1))
                if not np.isfinite(step):
                    break
            step = alpha * step
            Anew = A - step * G

            # Center anchors (?? This does not seem right; it changes the
            # projection axes direction somewhat arbitrarily)
            Anew = Anew - np.mean(Anew, axis=0)

            # Scale (so that the largest radius is 1)
            maxr = np.max(np.linalg.norm(Anew, axis=1))
            if maxr >= 0.001:
                Anew /= maxr

            change = np.linalg.norm(Anew - A, axis=1)
            if cls.allclose(change, 0, atol=atol):
                break

            A = Anew
            embeddings = np.dot(X, A)
            step_i = step_i + 1

        if dim == 2:
            A = cls._rotate(A)

        return embeddings, A, center, scale
def freeviz ( cls , X , y , weights = None , center = True , scale = True , dim = 2 , p = 1 , initial = None , maxiter = 500 , alpha = 0.1 , atol = 1e-5 , is_class_discrete = False ) : needcopy = center is not False or scale is not False X = np . array ( X , copy = needcopy ) y = np . asarray ( y ) N , P = X . shape _N , = y . shape if N != _N : raise ValueError ( "X and y must have the same length" ) if weights is not None : weights = np . asarray ( weights ) if isinstance ( center , bool ) : if center : center = np . mean ( X , axis = 0 ) else : center = None else : center = np . asarray ( center , dtype = X . dtype ) if center . shape != ( P , ) : raise ValueError ( "center.shape != (X.shape[1], ) ({} != {})" . format ( center . shape , ( X . shape [ 1 ] , ) ) ) if isinstance ( scale , bool ) : if scale : scale = np . std ( X , axis = 0 ) else : scale = None else : scale = np . asarray ( scale , dtype = X . dtype ) if scale . shape != ( P , ) : raise ValueError ( "scale.shape != (X.shape[1],) ({} != {}))" . format ( scale . shape , ( P , ) ) ) if initial is not None : initial = np . asarray ( initial ) if initial . ndim != 2 or initial . shape != ( P , dim ) : raise ValueError else : initial = cls . init_random ( P , dim ) # initial = np.random.random((P, dim)) * 2 - 1 # Center/scale X if requested if center is not None : X -= center if scale is not None : scalenonzero = np . abs ( scale ) > np . finfo ( scale . dtype ) . eps X [ : , scalenonzero ] /= scale [ scalenonzero ] A = initial embeddings = np . dot ( X , A ) step_i = 0 while step_i < maxiter : G = cls . freeviz_gradient ( X , y , embeddings , p = p , weights = weights , is_class_discrete = is_class_discrete ) # Scale the changes (the largest anchor move is alpha * radius) with np . errstate ( divide = "ignore" ) : # inf's will be ignored by min step = np . min ( np . linalg . norm ( A , axis = 1 ) / np . linalg . norm ( G , axis = 1 ) ) if not np . isfinite ( step ) : break step = alpha * step Anew = A - step * G # Center anchors (?? This does not seem right; it changes the # projection axes direction somewhat arbitrarily) Anew = Anew - np . mean ( Anew , axis = 0 ) # Scale (so that the largest radius is 1) maxr = np . max ( np . linalg . norm ( Anew , axis = 1 ) ) if maxr >= 0.001 : Anew /= maxr change = np . linalg . norm ( Anew - A , axis = 1 ) if cls . allclose ( change , 0 , atol = atol ) : break A = Anew embeddings = np . dot ( X , A ) step_i = step_i + 1 if dim == 2 : A = cls . _rotate ( A ) return embeddings , A , center , scale