
load model.mat u_of_c v_of_c log_root_det p_w_given_c p_c

[num_concepts, num_features ] = size(u_of_c);

[num_concepts, num_words ] = size(p_w_given_c);

con_item_mp = load('2_continuous_item_mp');

[ num_blobs, num_features ] = size(con_item_mp);
num_images = num_blobs / 10

dis_item_mp = load('2_discrete_item_sparse_mp');
[ num_images_2, max_num_words_per_image ] = size(dis_item_mp);

num_words = max(max(dis_item_mp));

fid = fopen('scores','w');

for i = 1:num_images
    fprintf(fid, '2 %d ', i);

    for b = 1 : 10
        p_word = zeros(num_words,1);

        for w = 1 : num_words
           p_b_given_c = zeros(num_concepts, 1);

           for c = 1:num_concepts
               x = con_item_mp((i-1) * 10 + b,:);
               u = u_of_c(c,:);
               v = v_of_c(c,:);

               p_b_given_c(c) = (1 / exp(log_root_det(c))) * exp(-0.5 * sum((x-u).*(x-u) ./ v));
           end

           p_word(w) = sum(p_b_given_c .* p_w_given_c(:,w) .* p_c');
       end

       [max_value, max_index ] = max(p_word);

       fprintf(fid, ' %d ', max_index);

    end

    fprintf(fid, '\n', max_index);
end

