%BFGSLLDDEMO	The example of BFGSLLD algorithm.
%
%	Description
%   In order to optimize the IIS-LLD algorithm, we follow the idea of an
%   effective quasi-Newton method BFGS to further improve IIS-LLD. 
%   Here is an example of BFGSLLD algorithm.
%	
%	See also
%	LLDPREDICT, BFGSLLDTRAIN
%	
%   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 bfgslldTestData.
load trainData;
load bfgslldTestData;
% Initialize the model parameters.
prediction=[];
geneNum = testNum;

item=eye(size(trainFeature,2),size(trainDistribution,2));

% The training part of BFGSLLD algorithm.
% The function of bfgsprocess provides a target function and the gradient.
[weights,fval] = bfgslldtrain(@bfgsprocess,item);
for i=1:geneNum
    testfeature = testFeature(i,:);
    % Use LDL model to predict the distribution.
    distribution = lldpredict(weights,testfeature);
    % Show the comparisons between the real distribution and the predicted 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