Example #1
0
def test_QuadraticForm_extrema():
    # TODO: add some real test
    # check H with negligible linear term
    noise = 1e-8
    tol = 1e-6
    x = numx_rand.random((10,))
    H = numx.outer(x, x) + numx.eye(10)*0.1
    f = noise*numx_rand.random((10,))
    q = utils.QuadraticForm(H, f)
    xmax, xmin = q.get_extrema(utils.norm2(x), tol=tol)
    assert_array_almost_equal(x, xmax, 5)
    # check I + linear term
    H = numx.eye(10, dtype='d')
    f = x
    q = utils.QuadraticForm(H, f=f)
    xmax, xmin = q.get_extrema(utils.norm2(x), tol=tol)
    assert_array_almost_equal(f, xmax, 5)
Example #2
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)
Example #3
0
 def _get_eye(self):
     # return an identity matrix with the right dimensions and type
     return numx.eye(self._effective_input_dim, dtype=self.dtype)
Example #4
0
 def _get_eye(self):
     # return an identity matrix with the right dimensions and type
     return numx.eye(self._effective_input_dim, dtype=self.dtype)