%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Siddhartha Kasivajhula
% PSYCH 221/ EE 362 (Winter 2007-2008)
% Final Project: A Probabilistic Model of the Visual System
% 
% HMM_scene.m
% Hidden Markov Model for the scene. Running this code will result in a scene
% being generated in the matrix 'scene'.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function scene_tprime = HMM_scene(NUM_FEATURES, scene_t)

% the size of the feature space -- use 10
N = NUM_FEATURES;
N_f = size(scene_t, 2);

% uniquely represent all possible features as vectors
all_features = eye(NUM_FEATURES);

% probabilistically evolve the scene
% Note: Correlation between features is not considered, and ought to be (do in future).
% i.e. a corner is likely to be seen if a square is present. so 'square' and 'corner'
% are correlated.

%random number between 1 and N_f. exponentially decreasing probability.
%n_featuresc_p = abs(random('norm', 0,0.15,1,1));
%n_featc = round(n_featuresc_p * 10);

% calculate probabilities of a number of features changing 
% also calculate probability of the number of features in the scene changing
%n_probs = zeros(n_featc, 1);
%n_featp = zeros(n_featc, 1);
%for i=1:n_featc
	%n_probs[i] = normcdf(i/n_featc, 0, 0.1);
	%n_featp[i] = normcdf(i/n_featc, 0, 0.1);
%end


% For now, assume that the number of features in the scene is constant.
% (Not true for dynamically changing scenes, for example. This is a simplifying assumption)

scene_tprime = scene_t;

n_changed = round(N_f * random('normal', 0, 0.1, 1, 1));

% I am replacing the first few features, but this doesn't compromise generality, since the feature order
% is random anyway (or at least, there is no intended order).
for i=1:n_changed
	scene_feature = ceil(N * random('uniform', 0, 1));
	scene_tprime(i, :) = zeros(1,N);
	scene_tprime(i, scene_feature) = 1;
end

	
% Generate the scene
%scene_tprime = GenerateScene(NUM_FEATURES, scene_features);

