Exemplo n.º 1
0
    def __init__(self,
                 incoming,
                 uvec=lasagne.init.Normal(1),
                 b=lasagne.init.Constant(0),
                 **kwargs):
        super(OrthogonalFlow, self).__init__(incoming, **kwargs)
        num_inputs = self.input_shape[1]

        n = num_inputs
        n_triu_entries = (n * (n + 1)) // 2
        r = T.arange(n)
        tmp_mat = r[np.newaxis, :] + (n_triu_entries - n -
                                      (r * (r + 1)) // 2)[::-1, np.newaxis]
        triu_index_matrix = T.tril(tmp_mat.T) - r[np.newaxis, :]
        tmp_mat1 = T.tril(tmp_mat.T) - r[np.newaxis, :]
        skew_index_mat = T.tril(tmp_mat1 - T.diag(T.diag(tmp_mat1)))

        self.uvec = self.add_param(uvec,
                                   ((num_inputs - 1) * (num_inputs) / 2, ),
                                   name='uvec')
        vec0 = T.concatenate([T.zeros(1), self.uvec])
        skw_matrix = vec0[skew_index_mat] - vec0[skew_index_mat].T

        self.U = expm(skw_matrix)

        self.b = self.add_param(b, (num_inputs, ), name='b')  # scalar
Exemplo n.º 2
0
def hky_transition_probs_expm(kappa, pi, t):
	Q_nodiag = make_tensor([
		[0, kappa*pi[C], pi[A], pi[G]],
		[kappa*pi[T], 0, pi[A], pi[G]],
		[pi[T], pi[C], 0, kappa*pi[G]],
		[pi[T], pi[C], kappa*pi[A], 0]	
	])
	
	Q_unnormalised = Q_nodiag - tt.diag(Q_nodiag.sum(axis = 1))
	average_subs = -tt.nlinalg.trace(tt.dot(Q_unnormalised, tt.diag(pi)))

	return tsl.expm(Q * t / average_subs)
Exemplo n.º 3
0
def test_expm():
    scipy = pytest.importorskip("scipy")
    rng = np.random.RandomState(utt.fetch_seed())
    A = rng.randn(5, 5).astype(config.floatX)

    ref = scipy.linalg.expm(A)

    x = tensor.matrix()
    m = expm(x)
    expm_f = function([x], m)

    val = expm_f(A)
    np.testing.assert_array_almost_equal(val, ref)
Exemplo n.º 4
0
def test_expm():
    if not imported_scipy:
        raise SkipTest("Scipy needed for the expm op.")
    rng = np.random.RandomState(utt.fetch_seed())
    A = rng.randn(5, 5).astype(config.floatX)

    ref = scipy.linalg.expm(A)

    x = tensor.matrix()
    m = expm(x)
    expm_f = function([x], m)

    val = expm_f(A)
    np.testing.assert_array_almost_equal(val, ref)
Exemplo n.º 5
0
def test_expm():
    if not imported_scipy:
        raise SkipTest("Scipy needed for the expm op.")
    rng = numpy.random.RandomState(utt.fetch_seed())
    A = rng.randn(5, 5).astype(config.floatX)

    ref = scipy.linalg.expm(A)

    x = tensor.matrix()
    m = expm(x)
    expm_f = function([x], m)

    val = expm_f(A)
    numpy.testing.assert_array_almost_equal(val, ref)
                            deph2), TT.dot(m, conjU3ten[:, :, i])))) *
                           deph3)))) * inhom14
            return (1j * 1j * 1j) * h1 * h2 * h3vec[i] * (
                r1 + r2 + r3 + r4 - TT.conj(r1) - TT.conj(r2) - TT.conj(r3) -
                TT.conj(r4))

        response, updates = theano.scan(fn=resfunc,
                                        outputs_info=None,
                                        sequences=iscan,
                                        non_sequences=[
                                            xvec, y, h1, h2, h3vec, U1, U2,
                                            U3ten, conjU1, conjU2, conjU3ten
                                        ])

        # Theano time propagator expression
        timeprop = TTslinalg.expm(-1j * w * (x - y))

        #############################
        # Declare theano functions
        f_response = theano.function(
            [xvec, y, h1, h2, h3vec, U1, U2, U3ten, conjU1, conjU2, conjU3ten],
            response,
            allow_input_downcast=True,
            on_unused_input='warn')
        f_timeprop = theano.function([x, y], timeprop)

        #############################
        # Calculate the time domain response function for single quantum excitation scans
        U3array = np.zeros((n_states, n_states, NEmi), dtype=complex)
        conjU3array = np.zeros((n_states, n_states, NEmi), dtype=complex)
        h3temparray = np.zeros(NEmi, dtype=int)