# MATLAB: Hidden Markov Models - Computing Alpha

## Implementation

function a = alpha_dynamic(M,p,B,v)
% ALPHA DYNAMIC(M,p,B,v) calculates the matrix of alpha's the
% hmm with transition matrix M, emission matrix B, and initial
% probabilities p, given the observations v

[np, ~]     = size(p);
[N, ~]      = size(M);
T           = length(v);
%initialise alphas
a           = zeros(N,T);
% making sure p is a column
if np == 1
p = p';
end
% alpha 1 from initial probability
a(:,1) = p.*B(:,v(1));
%subsequent alphas
for t = 2:T
a(:,t) = M' * a(:,t-1) .* B(:,v(t));
end
end
{"ft_lang_label":"__label__en","ft_lang_prob":0.74679965,"math_prob":0.9999491,"size":546,"snap":"2022-40-2023-06","text_gpt3_token_len":175,"char_repetition_ratio":0.105166055,"word_repetition_ratio":0.0,"special_character_ratio":0.35164836,"punctuation_ratio":0.2519084,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":1.0000013,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-10-03T03:55:49Z\",\"WARC-Record-ID\":\"<urn:uuid:3415bcb4-92e0-478c-8d7a-1606b70a783d>\",\"Content-Length\":\"12266\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d7fe4b15-0f79-4553-b391-31db5dadf103>\",\"WARC-Concurrent-To\":\"<urn:uuid:41565b76-d083-4812-a6ba-1253636cab23>\",\"WARC-IP-Address\":\"185.199.110.153\",\"WARC-Target-URI\":\"https://adrian.ng/matlab/hmm/alpha/\",\"WARC-Payload-Digest\":\"sha1:SDKZZFXCW6DMWIWEUGFQQAPGQYVGPPVB\",\"WARC-Block-Digest\":\"sha1:UAMUGN6YFKKP4FCRJKFPGIZWASZ23Q3C\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030337398.52_warc_CC-MAIN-20221003035124-20221003065124-00635.warc.gz\"}"}