Exemplo n.º 1
0
def test_reconstruct_with_without_rowvar():
    """Tests the reconstruct works with rowvar correctly."""
    np.random.seed(1)
    data = np.random.normal(size=(10, 50))
    pc1 = PrincipalComponents(data)
    pc2 = PrincipalComponents(data.T, rowvar=True)
    pc1._direct()
    pc2._direct()
    check_cols_match_except_sign(pc1.reconstruct(pc1.project(3)), pc2.reconstruct(pc2.project(3)).T)
Exemplo n.º 2
0
def test_project_with_without_rowvar():
    """Tests the project works with rowvar correctly."""
    np.random.seed(1)
    data = np.random.normal(size=(10, 50))
    pc1 = PrincipalComponents(data)
    pc2 = PrincipalComponents(data.T, rowvar=True)
    pc1._direct()
    pc2._direct()
    check_cols_match_except_sign(pc1.project(3), pc2.project(3).T)
    check_cols_match_except_sign(pc1.project(3), pc2.project(3).T)
Exemplo n.º 3
0
class SplineModelPCAGaussianMixture(GaussianMixture):
    """docstring for SplineModelGaussianMixture"""
    def __init__(self, npc=None, *args, **keywords):
        self._pc = PrincipalComponents(data)
        self._pc._direct()
        if npc is None:
            npc = len(self._pc._eigval)
        data = self._pc.project(npc)
        super(SplineModelPCAGaussianMixture, self).__init__(ncomponent,
                                                            data,
                                                            norm=False,
                                                            *args,
                                                            **keywords)

    def display(self,
                covariance=None,
                logalpha=None,
                name=None,
                extra=1,
                k=3,
                figures=(1, 2)):
        """Display covariances and alphas with matplotlib."""
        pyplot.close('all')
        super(SplineModelPCAGaussianMixture,
              self).display(covariance, logalpha, name, figures[0])
        figurenum = figures[1]
        if PLOTTING_AVAILABLE:
            print "Okay plotting"
            pyplot.ioff()
            pyplot.figure(figurenum)
            pyplot.clf()
            rows = cols = np.ceil(np.sqrt(self._ncomponent()))
            if rows * cols == self._ncomponent():
                rows = rows + 1
            ncomp, ndim = self._means.shape
            perspline = (ndim - extra) / 2
            for clust in xrange(self._ncomponent()):
                t = internal_knots(coef2knots(perspline))
                t = np.concatenate((np.zeros(4), t, np.ones(4)))
                pyplot.subplot(rows, cols, clust + 1)
                means = self._pc.reconstruct(self._means[clust, :]).squeeze()
                spline1, spline2 = unmix(means, k=k, extra=extra)
                plot_from_spline(spline1)
                plot_from_spline(spline2)
                pyplot.ylim(-0.2, 1.01)
            pyplot.show()
            pyplot.ion()
Exemplo n.º 4
0
class SplineModelPCAGaussianMixture(GaussianMixture):
    """docstring for SplineModelGaussianMixture"""
    def __init__(self, npc=None, *args, **keywords):
        self._pc = PrincipalComponents(data)
        self._pc._direct()
        if npc is None:
            npc = len(self._pc._eigval)
        data = self._pc.project(npc)
        super(SplineModelPCAGaussianMixture, self).__init__(ncomponent, data,
            norm=False, *args, **keywords)
    
    def display(self, covariance=None, logalpha=None, name=None, extra=1,
        k=3, figures=(1,2)):
        """Display covariances and alphas with matplotlib."""
        pyplot.close('all')
        super(SplineModelPCAGaussianMixture, self).display(covariance,
            logalpha, name, figures[0])
        figurenum = figures[1]
        if PLOTTING_AVAILABLE:
            print "Okay plotting"
            pyplot.ioff()
            pyplot.figure(figurenum)
            pyplot.clf()
            rows = cols = np.ceil(np.sqrt(self._ncomponent()))
            if rows * cols == self._ncomponent():
                rows = rows + 1
            ncomp, ndim = self._means.shape
            perspline = (ndim - extra) / 2
            for clust in xrange(self._ncomponent()):    
                t = internal_knots(coef2knots(perspline))
                t = np.concatenate((np.zeros(4),t,np.ones(4)))
                pyplot.subplot(rows, cols, clust+1)
                means = self._pc.reconstruct(self._means[clust, :]).squeeze()
                spline1, spline2 = unmix(means,k=k,extra=extra)
                plot_from_spline(spline1)
                plot_from_spline(spline2)
                pyplot.ylim(-0.2, 1.01)
            pyplot.show()
            pyplot.ion()