function [y_pre_init_tr_r,y_pre_init_tr_b] = firstPre(X_train,y_train,numLabel,lambda,write_file)
%FIRSTPRE 此处显示有关此函数的摘要
%   此处显示详细说明
    %basic functions called by CLIM
    addpath('basic_functions');
    %optimization function
    addpath('minFunc');
    addpath('minFunc/compiled');

    all_fid = write_file.file_id;
    head_str = write_file.head_str;
    verbose = write_file.verbose;

    num_tr = size(X_train,1);%number of training samples
    X_train = [ones(num_tr,1),X_train];%add bias
    num_dim = length(numLabel);%number of dimensions
    num_attr = size(X_train,2);%number of input attributes

    if verbose
        temp_str = [head_str,'(1) First time prediction (',disp_time(clock,0),')...'];
        fprintf(all_fid,temp_str);fprintf(all_fid,'\n');
    end
    y_pre_init_tr_r = zeros(size(y_train));%y_predict_initialization_train_real
    y_pre_init_tr_b = zeros(size(y_train));%y_predict_initialization_train_binary
    RL_init_tr = zeros(num_dim,1);%RankingLoss_initialization_train
    theta_init = cell(num_dim,1);%theta_initialization
    TH_init = zeros(num_dim,1);%threshold_initialization

    for dd=1:num_dim
        %label index for dd-th dimension
        idx_dim_b = sum(numLabel(1:dd-1))+1;
        idx_dim_e = sum(numLabel(1:dd));
        %label matrix for dd-th dimension
        y_train_dd = y_train(:,idx_dim_b:idx_dim_e);
        %gradient descent
        theta_0 = rand(num_attr,numLabel(dd)-1)*0.001;%d*(q-1)
        options = struct('MaxIter', 200);
        theta_vec = minFunc(@costFunc, theta_0(:), options, X_train, y_train_dd, lambda);
        theta_mtx = reshape(theta_vec,num_attr,[]);%d*(q-1)
        Theta = [theta_mtx,zeros(num_attr,1)];%d*q
        theta_init{dd} = Theta;
        linR = X_train*Theta;%m*q
        eR = exp(linR);%m*q
        eR_sumrow = sum(eR,2);%m*1
        eR_sum_row_mtx = repmat(eR_sumrow,1,numLabel(dd));%m*q
        softR = eR./eR_sum_row_mtx;%m*q, predicted label matrix in probability style
        %ranking loss over training set
        RL_init_tr(dd) = Ranking_loss(softR',y_train_dd');
        %save predicted label matrix in probability style for training examples
        y_pre_init_tr_r(:,idx_dim_b:idx_dim_e) = softR;
        %determine threshold with MAP rule
        [TH_init(dd), y_predict_bin] = THfunc(softR, y_train_dd);
        %save predicted label matrix in binary style for training examples
        y_pre_init_tr_b(:,idx_dim_b:idx_dim_e) = y_predict_bin;
    end
end

