creongramconalfa.m

来自「base implementaion of the protein (start」· M 代码 · 共 142 行

M
142
字号
function Feat=CreoNgramConAlfa(Training,N,alfabeto)
%to implement a N-gram based feature extractor considering the
%alphabet "alfabeto"

if N==1
    tmp=1;
    for i=1:length(alfabeto)
        Tabella(tmp,1)=(i) ;
        tmp=tmp+1;
    end
    Tabella=single(Tabella);
    Feat=single(zeros(size(Training,2),length(alfabeto)^N));
    for i=1:size(Training,2)
        Tr=single(ConvertiAlfabeto(Training{i},alfabeto));
        for j=1:size(Tr,2)
            indice=find(Tabella(:,1)==Tr(j));
            Feat(i,indice)=Feat(i,indice)+1;
        end
        Feat(i,:)=Feat(i,:)./j;
    end

elseif N==2
    tmp=1;
    for i=1:length(alfabeto)
        for j=1:length(alfabeto)
            Tabella(tmp,1)=(i) ;
            Tabella(tmp,2)=(j) ;
            tmp=tmp+1;
        end
    end
    Tabella=single(Tabella);
    Feat=single(zeros(size(Training,2),length(alfabeto)^N));
    for i=1:size(Training,2)
        Tr=single(ConvertiAlfabeto(Training{i},alfabeto));
        Feat(i,:)=cicloVeloce2(Tr,Tabella,Feat(i,:));
        Feat(i,:)=Feat(i,:)./(size(Tr,2)-1);
    end
    
elseif N==3
    
    tmp=1;
    for i=1:length(alfabeto)
        for j=1:length(alfabeto)
            for ij=1:length(alfabeto)
                Tabella(tmp,1)=(i) ;
                Tabella(tmp,2)=(j) ;
                Tabella(tmp,3)=(ij) ;
                tmp=tmp+1;
            end
        end
    end
    Tabella=single(Tabella);
    Feat=single(zeros(size(Training,2),length(alfabeto)^N));
    for i=1:size(Training,2)
        Tr=single(ConvertiAlfabeto(Training{i},alfabeto));
        Feat(i,:)=cicloVeloce3(Tr,Tabella,Feat(i,:));
        Feat(i,:)=Feat(i,:)./(size(Tr,2)-2);
    end
    
elseif N==4
    
    tmp=1;
    for i=1:length(alfabeto)
        for j=1:length(alfabeto)
            for ij=1:length(alfabeto)
                for ii=1:length(alfabeto)
                    Tabella(tmp,1)=(i) ;
                    Tabella(tmp,2)=(j) ;
                    Tabella(tmp,3)=(ij) ;
                    Tabella(tmp,4)=(ii) ;
                    tmp=tmp+1;
                end
            end
        end
    end
    Tabella=single(Tabella);
    Feat=single(zeros(size(Training,2),length(alfabeto)^N));
    for i=1:size(Training,2)
        Tr=single(ConvertiAlfabeto(Training{i},alfabeto));
        Feat(i,:)=cicloVeloce4(Tr,Tabella,Feat(i,:));
        Feat(i,:)=Feat(i,:)./(size(Tr,2)-3);
    end
    
elseif N==5
    
    tmp=1;
    for i=1:length(alfabeto)
        for j=1:length(alfabeto)
            for ij=1:length(alfabeto)
                for ii=1:length(alfabeto)
                    for ji=1:length(alfabeto)
                        Tabella(tmp,1)=(i) ;
                        Tabella(tmp,2)=(j) ;
                        Tabella(tmp,3)=(ij) ;
                        Tabella(tmp,4)=(ii) ;
                        Tabella(tmp,5)=(ji) ;
                        tmp=tmp+1;
                    end
                end
            end
        end
    end
    Tabella=single(Tabella);
    Feat=single(zeros(size(Training,2),length(alfabeto)^N));
    for i=1:size(Training,2)
        Tr=single(ConvertiAlfabeto(Training{i},alfabeto));
        Feat(i,:)=cicloVeloce5(Tr,Tabella,Feat(i,:));
        Feat(i,:)=Feat(i,:)./(size(Tr,2)-4);
    end
    
    
elseif N==6
    
    tmp=1;
    for i=1:length(alfabeto)
        for j=1:length(alfabeto)
            for ij=1:length(alfabeto)
                for ii=1:length(alfabeto)
                    for ji=1:length(alfabeto)
                        for jii=1:length(alfabeto)
                            Tabella(tmp,1)=(i) ;
                            Tabella(tmp,2)=(j) ;
                            Tabella(tmp,3)=(ij) ;
                            Tabella(tmp,4)=(ii) ;
                            Tabella(tmp,5)=(ji) ;
                            Tabella(tmp,6)=(jii) ;
                            tmp=tmp+1;
                        end
                    end
                end
            end
        end
    end
    Tabella=single(Tabella);
    Feat=single(zeros(size(Training,2),length(alfabeto)^N));
    for i=1:size(Training,2)
        Tr=single(ConvertiAlfabeto(Training{i},alfabeto));
        Feat(i,:)=cicloVeloce6(Tr,Tabella,Feat(i,:));
        Feat(i,:)=Feat(i,:)./(size(Tr,2)-5);
    end
    
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?