Esempio n. 1
0
def test_random_rot():
    dim = 20
    tlen = 10
    for i in xrange(tlen):
        x = utils.random_rot(dim, dtype='f')
        assert x.dtype.char=='f', 'Wrong dtype'
        y = utils.mult(x.T, x)
        assert_almost_equal(numx_linalg.det(x), 1., 4)
        assert_array_almost_equal(y, numx.eye(dim), 4)
Esempio n. 2
0
def test_symeig_fake_LAPACK_bug():
    # bug. when input matrix is almost an identity matrix
    # but not exactly, the lapack dgeev routine returns a
    # matrix of eigenvectors which is not orthogonal.
    # this bug was present when we used numx_linalg.eig
    # instead of numx_linalg.eigh .
    # Note: this is a LAPACK bug.
    y = numx_rand.random((4,4))*1E-16
    y = (y+y.T)/2
    for i in xrange(4):
        y[i,i]=1
    val, vec = utils._symeig._symeig_fake(y)
    assert_almost_equal(abs(numx_linalg.det(vec)), 1., 12)
Esempio n. 3
0
    def _stop_training(self):
        self.labels = self._cov_objs.keys()
        self.labels.sort()
        nitems = 0
        for lbl in self.labels:
            cov, mean, p = self._cov_objs[lbl].fix()
            nitems += p
            self._sqrt_def_covs.append(numx.sqrt(numx_linalg.det(cov)))
            if self._sqrt_def_covs[-1] == 0.0:
                err = "The covariance matrix is singular for at least " "one class."
                raise mdp.NodeException(err)
            self.means.append(mean)
            self.p.append(p)
            self.inv_covs.append(utils.inv(cov))

        for i in range(len(self.p)):
            self.p[i] /= float(nitems)

        del self._cov_objs
Esempio n. 4
0
    def _stop_training(self):
        self.labels = self._cov_objs.keys()
        self.labels.sort()
        nitems = 0
        for lbl in self.labels:
            cov, mean, p = self._cov_objs[lbl].fix()
            nitems += p
            self._sqrt_def_covs.append(numx.sqrt(numx_linalg.det(cov)))
            if self._sqrt_def_covs[-1] == 0.0:
                err = ("The covariance matrix is singular for at least "
                       "one class.")
                raise mdp.NodeException(err)
            self.means.append(mean)
            self.p.append(p)
            self.inv_covs.append(utils.inv(cov))

        for i in range(len(self.p)):
            self.p[i] /= float(nitems)

        del self._cov_objs