theano

2016-06-26 3 views
0

에서 반복 방정식 구현 (HTK와 비슷한 델타 계수 찾기) 델타 계수를 계산하기 위해 scan표현으로 다음과 같은 회귀 함수를 구현하고 싶습니다. 그러나 이전 단계의 theta 입력을 전달하는 방법을 알 수 없습니다. delta가 대응하는 고정 된 계수 coeff-coeff 환산 계산 시간 t에서 델타 계수가theano

delta coefficient

. theta의 값은 구성 매개 변수 DELTAWINDOW를 사용하여 설정됩니다. 델타 계수에 동일한 공식이 적용되어 가속 계수를 얻습니다. 단,이 경우 윈도우 크기는 ACCWINDOW로 설정됩니다. 식 5.16은 과거와 미래의 스피치 파라미터 값에 의존하기 때문에, 스피치의 시작과 끝에서 약간의 변경이 필요하다. 기본 동작은 필요에 따라 첫 번째 또는 마지막 벡터를 복제하여 회귀 창을 채 웁니다.

I가 사용하고있는 DELTAWINDOW 9이고 입력 매트릭스 예이다

[[1,1,1,1,1,1,1,1,1], 
[2,2,2,2,2,2,2,2,2], 
[3,3,3,3,3,3,3,3,3], 
[4,4,4,4,4,4,4,4,4]]  

기준 물질이 용 theano 식을 제작하는 본 link

답변

1

시도에서 찾을 수있다.

import numpy as np 
import theano 
import theano.tensor as T 


def delta_theta(theta, curr_delta, t, THETA, Y): 
    """ 
    compute a delta theta component at delta time step t 
    :param theta: current time step theta component 
    :param curr_delta: current accumulated delta_t 
    :param t: current delta_t to be computed 
    :param THETA: window size 
    :param Y: input sequence 
    :return: delta theta component for time step t 
    """ 
    # accumulator is shaped (1, no_features), transpose to perform column wise element operations 
    temp = curr_delta.T 
    d_theta = theta * (Y[:, THETA + t + theta] - Y[:, THETA + t - theta])/(2 * theta * theta) 
    temp += d_theta 
    temp = temp.astype('float32') 
    curr_delta = temp.T 
    return curr_delta 


def delta_t(t, THETA, Y): 
    """ 
    compute delta at time step t 
    :param t: time step 
    :param THETA: window size 
    :param Y: sequence in shape (number_of_features, time_step) 
    :return: delta coefficient at time step t 
    """ 
    theta = T.arange(1, THETA + 1, dtype='int32') 
    results, _ = theano.scan(delta_theta, outputs_info=T.zeros_like(Y), 
          sequences=theta, non_sequences=[t, THETA, Y]) 
    # only interested in the final results, discard the intermediate values 
    final_results = results[-1] 
    return final_results 


def delta_coeff(A, theta): 
    """ 
    compute delta coefficients given a sequence. 
    :param A: input sequence in shape (time_step, number_of_features) 
    :param theta: window size 
    :return: delta coefficients for the input sequence 
    """ 
    # transpose and repeat 
    X = A.T 
    Y = T.concatenate([T.extra_ops.repeat(X[:, 0], theta).reshape((X.shape[0], theta)), 
         X, T.extra_ops.repeat(X[:, -1], theta).reshape((X.shape[0], theta))], axis=1) 
    results, _ = theano.scan(delta_t, sequences=[T.arange(0, X.shape[1], dtype='int32')], non_sequences=[theta, Y]) 
    # transpose the results back to shape (time_step, number_of_features) 
    return results[:, :, -1].reshape(A.shape) 


def main(): 
    """ 
    test runner, computes delta for an array of sequences 
    :return: None 
    """ 
    A = T.tensor3('A', dtype='float32') 
    theta = T.iscalar('theta') 

    # compute delta coefficients for multiple sequences 
    results, updates = theano.scan(delta_coeff, sequences=A, non_sequences=theta) 
    compute_deltas = theano.function([A, theta], outputs=results, updates=updates) 

    seqs = np.array([[[1, 2, 3, 4, 5], 
         [10, 12, 13, 14, 15], 
         [300, 1, 23, 56, 22]], 
        [[1, 1, 1, 1, 1], 
         [1, 1, 100, 1, 1], 
         [1, 1, 1, 1, 1]]], dtype='float32') 
    res = compute_deltas(seqs, 1) 
    print(res) 

if __name__ == '__main__': 
    main() 

실수가있는 경우 알려 주시기 바랍니다. 감사합니다.