您现在的位置:首页 >> ★免费资源 >> 源码下载 >> 内容

MATLAB代做|FPGA代做--MLNB算法仿真

时间:2018-10-12 11:51:31 点击:

  核心提示:MLNB...
function [HammingLoss,RankingLoss,OneError,Coverage,Average_Precision,Outputs,Pre_Labels]=MLNB(train_data,train_target,test_data,test_target,pca_remained,Smooth)
%MLNB implements the algorithm proposed in [1]
%
%    Syntax
%
%       [HammingLoss,RankingLoss,OneError,Coverage,Average_Precision,Outputs,Pre_Labels]=MLNB(train_data,train_target,test_data,test_target,pca_remained,Smooth)
%
%    Description
%
%       MLNB_train takes,
%           train_data       - An M1xN array, the ith instance of training instance is stored in train_data(i,:)
%           train_target     - A QxM1 array, if the ith training instance belongs to the jth class, then train_target(j,i) equals +1, otherwise train_target(j,i) equals -1
%           test_data        - An M2xN array, the ith instance of testing instance is stored in test_data(i,:)
%           test_target      - A QxM2 array, if the ith testing instance belongs to the jth class, test_target(j,i) equals +1, otherwise test_target(j,i) equals -1
%           pca_remained     - The number of remained features after performing principal component analysis
%           Smooth           - The smoothing parameter, default=1
%      and returns,
%           Prior            - A Qx1 array, for the ith class Ci, the prior probability of P(Ci) is stored in Prior(i,1)
%           PriorN           - A Qx1 array, for the ith class Ci, the prior probability of P(~Ci) is stored in PriorN(i,1)
%           mu               - A QxN array, where the mean of the Gaussian distribution for the distribution P(xj|Ci) is stored in mu(i,j)
%           muN              - A QxN array, where the mean of the Gaussian distribution for the distribution P(xj|~Ci) is stored in muN(i,j)
%           sigma            - A QxN array, where the standard deviation of the Gaussian distribution for the distribution P(xj|Ci) is stored in sigma(i,j)
%           sigmaN           - A QxN array, where the standard deviation of the Gaussian distribution for the distribution P(xj|~Ci) is stored in sigmaN(i,j)
%
%[1] M.-L. Zhang, J. M. Pe?a, V. Robles. Feature selection for multi-label naive bayes classification. Information Sciences, in press

    if(nargin<5)
        error('Not enough input parameters, please check again.');
    end
    
    if(nargin<6)
        Smooth=1;
    end

    %Performing PCA
    [num_class,num_train]=size(train_target);
    num_test=size(test_data,1);
    
    ave=mean(train_data);
    train_data=(train_data'-concur(ave',num_train))';
    
    covar=cov(train_data);
    
    [u,s,v]=svd(covar);
    
    t_matrix=u(:,1:pca_remained)';
    
    train_data=(t_matrix*train_data')';
    
    test_data=(test_data'-concur(ave',num_test))';
    test_data=(t_matrix*test_data')';
    
    %Perfoming GA    
    [num_train,Dim]=size(train_data);
    
    eval_fold=10;
    popsize=20;
    gensize=100;
    
    eval_fold_size=floor(num_train/eval_fold);

    cut_points=[0,eval_fold_size:eval_fold_size:(eval_fold-1)*eval_fold_size,num_train];

    eval_train_data=cell(eval_fold,1);
    eval_train_target=cell(eval_fold,1);
    eval_test_data=cell(eval_fold,1);
    eval_test_target=cell(eval_fold,1);

    eval_Prior=cell(eval_fold,1);
    eval_PriorN=cell(eval_fold,1);
    eval_mu=cell(eval_fold,1);
    eval_muN=cell(eval_fold,1);
    eval_sigma=cell(eval_fold,1);
    eval_sigmaN=cell(eval_fold,1);

    for i=1:eval_fold
        for j=1:cut_points(i)
            eval_train_data{i,1}=[eval_train_data{i,1};train_data(j,:)];
            eval_train_target{i,1}=[eval_train_target{i,1},train_target(:,j)];
        end
        for j=(cut_points(i)+1):cut_points(i+1)
            eval_test_data{i,1}=[eval_test_data{i,1};train_data(j,:)];
            eval_test_target{i,1}=[eval_test_target{i,1},train_target(:,j)];
        end
        for j=(cut_points(i+1)+1):num_train
            eval_train_data{i,1}=[eval_train_data{i,1};train_data(j,:)];
            eval_train_target{i,1}=[eval_train_target{i,1},train_target(:,j)];
        end
        [eval_Prior{i,1},eval_PriorN{i,1},eval_mu{i,1},eval_muN{i,1},eval_sigma{i,1},eval_sigmaN{i,1}]=MLNB_Basic_train(eval_train_data{i,1},eval_train_target{i,1},Smooth);
    end
    
    objfun=@(x) MLNB_fitfunc(x,eval_test_data,eval_test_target,eval_Prior,eval_PriorN,eval_mu,eval_muN,eval_sigma,eval_sigmaN);

    options=gaoptimset('PopulationType','bitstring','PopulationSize',popsize,'Display','iter','StallTimeLimit',Inf,'Generations',gensize);

    [x,fval,reason,output,population,scores]=ga(objfun,Dim,options);
    
    num_retained=sum(x);
    [tempvalue,index]=sort(x,'descend');
    index=index(1:num_retained);
    
    if(isempty(index))
        index=1:Dim;
    end

    [Prior,PriorN,mu,muN,sigma,sigmaN]=MLNB_Basic_train(train_data(:,index),train_target,Smooth);
    [HammingLoss,RankingLoss,OneError,Coverage,Average_Precision,Outputs,Pre_Labels]=MLNB_Basic_test(test_data(:,index),test_target,Prior,PriorN,mu,muN,sigma,sigmaN);

联系:highspeedlogic

QQ :1224848052

微信:HuangL1121

邮箱:1224848052@qq.com

网站:http://www.mat7lab.com/

网站:http://www.hslogic.com/

微信扫一扫:

Tags:MLNB 
作者:MLNB 来源:MLNB
  • 您是如何找到本站的?
  • 百度搜索
  • Google搜索
  • 查阅资料过程中
  • 论坛发现
  • 百度贴吧发现
  • 朋友介绍
本站最新成功开发工程项目案例
相关文章
  • 没有相关文章
相关评论
发表我的评论
  • 大名:
  • 内容:
  • matlab代做|matlab专业代做|matlab淘宝代做(www.hslogic.com) © 2018 版权所有 All Rights Reserved.
  • Email:highspeed_logic@163.com 站长QQ: 1224848052

    专业代做/代写/承接、MATLAB、SIMULINK、FPGA项目、博士/硕士/本科毕业设计、课题设计、论文,毕业论文,Coursework、Eassy、Assignment