%LDSVRDEMO	The example of LDSVR algorithm.
%
%	Description  
%   To adapt the standard SVR into the LLD framework, we use MSVR to 
%   output multiple variables simultaneously and fit a sigmoid function 
%   to each component of the label distribution simultaneously. 
%   Here is an example of this LDSVR algorithm.
%
%   Statement
%   For regression tasks, the sigmoid function could directly act as the 
%   target model of the regression instead of a post-process. 
%
%	See also   
%   LDSVRPREDICT, LDSVRTRAIN
%
%   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 ldsvrTestData.
load ldsvrTrainData;
load ldsvrTestData;
% Initialize the model parameters.
para.tol  = 1e-10; %tolerance during the iteration
para.epsi = 0.1; %instances whose distance computed is more than epsi should be penalized
para.C    = 1; %penalty parameter
para.ker  = 'rbf'; %type of kernel function ('lin', 'poly', 'rbf', 'sam')
para.par  = 1*mean(pdist(trainFeature)); %parameter of kernel function

tic;
% The training part of LDSVR algorithm.
modelpara = ldsvrtrain(trainFeature,trainDistribution,para);
fprintf('training time: %8.7f \n', toc);

% Prediction
fprintf('the results of prediction is presented in the figures.\n');
for i=1:testNum
    testfeature = testFeature(i,:);
    % Use trained model parameters to predict the distribution.
    distribution = ldsvrpredict(testfeature, trainFeature, modelpara);
    % 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);
end


