%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Likelihood function or posterior distribution of normal mixture
%%% N(a,b^2) : Normal distribution, average a and variance b^2
%%% Model p=(1-aa) N(0,std^2) + aa N(b,std^2)
%%% True q=(1-AA)N(0,STD^2) + AA N(BB,STD^2)
%%% Uniform distribution is used as prior.
%%% You can rotate 3D figure by dragging the mouse.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Clear All %%%%%%%%%%%%%%%%%%%%%%%%%%%
clf;
clear;
close all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Constants %%%%%%%%%%%%%%%%%%%%
NNN=100; %%% Number of Samples
AA=0.2; %%% True Mixture ratio
BB=0.5; %%% True paramater BB
TTT1=12345; %%% Random seed of Ratio
TTT2=12345; %%% Random seed of Each normal distribution
STD=1.0; %%% Standard deviation of the true distribution
std=1.0; %%% Stanard deviation of the statistical model
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% You can change random samples by using other natural number for TTT1 and TTT2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Generate Samples %%%%%%%%%%%%%%%%%%%%%%%%%%%
rand('state',TTT1);
randn('state',TTT2);
YY=rand(1,NNN);
XX=STD*randn(1,NNN);
for i=1:1:NNN
if(YY(i)