%IISLLDDEMO	The example of IISLLD algorithm.
%
%	Description
%   We establish a maximum entropy model and use IIS algorithm to estimate
%   the parameters. In this way, we can get our LDL model. Then a new 
%   distribution can be predicted based on this model.
% 
%	See also
%	LLDPREDICT, IISLLDTRAIN
%	
%   Copyright: Xin Geng (xgeng@seu.edu.cn)
%   School of Computer Science and Engineering, Southeast University
%   Nanjing 211189, P.R.China
%
clear;
clc;
% Load the trainData and iislldTestData.
load trainData;
load iislldTestData;
% Initialize the model parameters.

para.minValue = 1e-7; % the feature value to replace 0, default: 1e-7
para.iter = 200; % learning iterations, default: 50
para.minDiff = 1e-4; % minimum log-likelihood difference for convergence, default: 1e-7
para.regfactor = 0; % regularization factor, default: 0
prediction = []; 

% The training part of IISLLD algorithm.
[weights] = iislldtrain(para, trainFeature, trainDistribution);
geneNum = testNum;

for i=1:geneNum
    testfeature = testFeature(i,:);
    % Use trained weights to predict the distribution.
    distribution = lldpredict(weights,testfeature);
    % Show the comparisons between the predicted distribution
    % and the real distribution.
    dist(1)=kldist(testDistribution(i,:),distribution);
    dist(2)=euclideandist(testDistribution(i,:),distribution);  
    dist(3)=sorensendist(testDistribution(i,:),distribution);
    dist(4)=squaredxdist(testDistribution(i,:),distribution);
    dist(5)=fidelity(testDistribution(i,:),distribution);
    dist(6)=intersection(testDistribution(i,:),distribution);
    % Draw the picture of the real and prediced distribution.
    drawdistribution(testDistribution(i,:),distribution,dist);
    sign=input('Press any key to continue:');
end
