function accuracy = PLENL_predict(detector,stream_data,k,alpha,M,options_osvm)

% PLENL [1] deals with partial label learning with emerging new labels
%
% Syntax
%
%       accuracy = PLENL_predict(detector,train_data,stream_data,k,alpha,M,options_osvm)
%
% Description
%
%       PLENL takes,
%           detector    - A 2 dimensional vector, label_pair(1) and label_pair(2) represent for a pair of class labels 
%           train_data       - A binary classifier based on label_pair
%           stream_data     - A cell, test_data in each period, target,
%           label list in current period and the flag list denotes the
%           instance belongs to new label or not

%       and returns,
%            accuarcy               - Predictive accuracy on the stream set
  
%
%  [2] C. C. Chang, C. J. Lin. LIBSVM: A library for support vector machines. ACM Transactions on Intelligent Systems and Technology, 2011, 2(3): Article 27.


Tst_data = [];
Tst_lbs = [];
anomaly_state_p=[];

data_0 = stream_data{1,1};
klb_list_0 = stream_data{1,4};
target_0 = stream_data{1,2}(klb_list_0,:);
partial_target_0 = stream_data{1,5}((stream_data{1,4})',:);
glblist_0 = repmat(klb_list_0',1,size(target_0,2));
glblist_0 = sum(target_0.*glblist_0,1);

Trn_lbs = [];
data_pool = data_0;


trainTarget = partial_target_0;
for i=2:size(stream_data,1)
    update_flag = 0;
    data_p = stream_data{i,1};
    klb_list_p = stream_data{i,4};
    target_p = stream_data{i,2}(klb_list_p,:);
    
    anomaly_state_p = stream_data{i,3};
    glblist_p = repmat(klb_list_p',1,size(target_p,2));
    glblist_p = sum(target_p.*glblist_p,1);
    cur_nlb = setdiff(stream_data{i,4},stream_data{i-1,4});
    
    c_S = estimate_cS(data_p,detector);
    
    if sum(c_S(size(c_S,1),:))>M & (update_flag==0)
        idx_tmptmp = 1:size(data_p,1);
        lastcol= c_S(size(c_S,1),:);
        idx_tmptmp = idx_tmptmp(1,(lastcol')==1);
        idx_tmptmp = idx_tmptmp(1,1:M);
        data_nlb = data_p(idx_tmptmp,:);
        detector = update_detector(options_osvm,data_nlb,detector);
        update_flag =1;
    end
    c_S(size(c_S,1),:)=1;
    
    trainTarget = [trainTarget;zeros(1,size(trainTarget,2))]; 
    trainTarget = [trainTarget,c_S];
    
    y = trainTarget'; 
    label_num = size(trainTarget,1);
    y = y./repmat(sum(y,2),1,label_num); 
    y_u = y(size(data_pool,1)+1:end,:);
    
    y_u = y_u./repmat(sum(y_u,2),1,label_num);
    y(size(data_pool,1)+1:end,:) = y_u;
    
    model = predict_LCP([data_pool;data_p],trainTarget,y',k,alpha);
    preds_nlb = repmat((1:size(model.disambiguatedLabel,1))',1,size(model.disambiguatedLabel,2));
    preds_nlb = sum(preds_nlb.*model.disambiguatedLabel,1);
    preds_p = preds_nlb(1,size(data_pool,1)+1:end);
    
    if i==2
        grb_nlb = glblist_p;
        preds_nlb = preds_nlb(1,size(data_pool,1)+1:end);
        acc_u = sum(grb_nlb==preds_p)/length(grb_nlb);
    else
        grb_nlb = glblist_p;
        acc_u = sum(grb_nlb==preds_p)/length(grb_nlb);
    end
    target_p = model.disambiguatedLabel(:,size(data_pool,1)+1:end);
    trainTarget(:,size(data_pool,1)+1:end) = target_p;

    [data_pool,Trn_lbs,trainTarget,y] = update_P(data_pool,Trn_lbs,data_p,[],preds_p,klb_list_p,trainTarget,y',M);
    y = y';
    data_nlb = data_p(preds_p==cur_nlb,:);
    if update_flag==0
        detector = update_detector(options_osvm,data_nlb,detector);
    end
end
accuracy = acc_u;
end
