⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bnbestfit.m

📁 Speaker Verification Toolbox
💻 M
📖 第 1 页 / 共 2 页
字号:
            %yy = squeeze(Fhat(dn,j,:))';
            yy = OptF(dn,:)';
        
            % Compare the computed output to the desired one. Note that this
            % also takes into account possible multiplisities in measurements,
            % i.e., computes new weights for those measurements that appear
            % several times in T (and/or F).
            Et(i,:) = sum((yy~=Yt).*Wt,2)';
        end % if TestBit
        
        
        % The next variable combinations (in lexicographical ordering)
        %I = nextnchoosek(I,n);
        
        % Display something.
        %if mod(i,1000)==0
        %    disp([num2str(i),'/',num2str(stopi)]);
        %    %save(file,'Fhat','i','I');
        %end % if mod(i,1000)==0
        
    end % for i=starti:stopi
    
else
    % If F is non-empty matrix, then the function class is defined in F,
    % i.e., the inference below is constrained by F.
    
    % The different representations of F (i.e., whether it's binary matrix
    % or integer vector) are handled separately.

    %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    % F is a binary matrix.
    %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    if bi==0

        nf = size(F,2); % The number of functions in F.
        maxerror = sum(w) + 1; % The largest possible error plus one.
        ones_ni_1 = ones(ni,1);
        ones_1_nf = ones(1,nf);
        ones_ni_1_minus = -ones(ni,1);

        % Weights in a matrix form (assume w is a row vector).
        Wc = w'*ones(1,nf);

        %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        % Run through all variable combinations.
        %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        for i=starti:stopi

            % The current variable combinations (in lexicographical ordering).
            I = IAll(i,:);
                        
            % All the inputs as decimal number.
            dn = X(I,:)'*b + 1;
            
            % Output values of all the functions for all the inputs.
            yy = F(dn,:);
            
            %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            % Run through all the target genes.
            %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            % Compare output values of all the functions to the desided output
            % of a single target variable.
            for j=1:ni
                
                % Compute the error-size of all the functions for the j:th node.
                E = (yy~=(Y(j,:)'*ones_1_nf)).*Wc;
                esize = sum(E);
                % Find the smallest error-size.
                emin = min(esize);
                % Since there can be several functions with the minimum
                % error size, let's find all of them and select one 
                % randomly.
                indmin = find(esize==emin);
                indmin = indmin(unidrnd(length(indmin)));
                % Store the the best candidate function.
                Fhat(:,i,j) = F(:,indmin);
                Ehat(i,j) = emin;
                
            end % for j=1:ni
            
            
            if TestBit % If the test data is provided
                %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                % Apply the Best-Fit functions to the test data.
                %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                % All the inputs on the test data as decimal number.
                dn = Xt(I,:)'*b + 1;
                
                % Output values of the current functions for all the inputs.
                yy = squeeze(Fhat(dn,i,:))';
                
                % Compare the computed output to the desired one. Note that this
                % also takes into account possible multiplisities in measurements,
                % i.e., computes new weights for those measurements that appear
                % several times in T (and/or F).
                Et(i,:) = sum((yy~=Yt).*Wt,2)';
            end % if TestBit
            
            
            % The next variable combinations (in lexicographical ordering)
            %I = nextnchoosek(I,n);

            % Display something.
            %if mod(i,100)==0
            %    disp([num2str(i),'/',num2str(stopi)]);
            %    %save('resultstemp.mat','E','i','I');
            %end % if mod(i,1000000)==0
            
        end % for i=starti:stopi
        
    else % F is an integer vector (bi = 1).
        
        %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        % F is an integer vector.
        %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        
        nf = length(F); % The number of functions in F.
        bits = [1:2^k];
        
        %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        % Run through all variable combinations.
        %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        for i=starti:stopi
            
            % The current variable combinations (in lexicographical ordering).
            I = IAll(i,:);
            
            %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            % Run through all the target genes.
            %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            % Compare output values of all the functions to the desided output
            % of a single target variable.
            for j=1:ni
                % Initialize the errorsizes.
                errorsizes = zeros(1,nf);
                
                % Remove multiplicities from the inputs and modify the
                % weight vector accordingly (i.e., sum the weights of the
                % measurements occuring multiple times). This is done
                % because the error size calculations (below) can be
                % very time-consuming, especially for large function
                % classes.
                dn = (X(I,:)'*b)' + 1; % All the input as decimal numbers.
                dnr = [1:kk,1:kk]; % All possible inputs (twice), kk = 2^k.
                YY = [zeros(1,kk),ones(1,kk)]; % Both outputs, 0 and 1.
                ww = zeros(1,2*kk); % New weight vector.
                %++++++++++++++++++++++++++++++++++++++++++++
                % Run through all the samples/time points.
                %++++++++++++++++++++++++++++++++++++++++++++
                % Sum up the weights.
                for k=1:m
                    ww(Y(j,k)*kk + dn(k)) = ww(Y(j,k)*kk + dn(k)) + w(k);
                end
                ind = find(ww>0); % Find the positive weights.
                ww = ww(ind);
                dnr = dnr(ind);
                YY = YY(ind);
                
                %++++++++++++++++++++++++++++++++++++++++++++
                % Run through all the inputs.
                %++++++++++++++++++++++++++++++++++++++++++++
                for k=1:length(dnr)
                    % Keep adding the errors.
                    errorsizes = errorsizes + (bitget(F,dnr(k))~=YY(k))*ww(k);
                end % for k=1:m
                
                % The minimum error size for the j:th target variable.
                emin = min(errorsizes);
                
                % Since there can be several functions with the minimum
                % error size, let's find all of them and select one
                % randomly.
                indmin = find(errorsizes==emin);
                indmin = indmin(unidrnd(length(indmin)));
                % Store the best values.
                Fhat(:,i,j) = bitget(F(indmin),bits);
                Ehat(i,j) = emin;
            end % for j=1:ni
            
            
            if TestBit % If the test data is provided
                %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                % Apply the Best-Fit functions to the test data.
                %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                % All the inputs on the test data as decimal number.
                dn = Xt(I,:)'*b + 1;
                
                % Output values of the current functions for all the inputs.
                yy = squeeze(Fhat(dn,i,:))';
                %yy = squeeze(Fhat(dn,1,1))';
                %Pred(i,:) = yy;
                
                % Compare the computed output to the desired one. Note that this
                % also takes into account possible multiplisities in measurements,
                % i.e., computes new weights for those measurements that appear
                % several times in T (and/or F).
                Et(i,:) = sum((yy~=Yt).*Wt,2)';
            end % if TestBit

            % The next variable combinations (in lexicographical ordering)
            %I = nextnchoosek(I,n);

            % Display something.
            %if mod(i,10)==0
            %disp([num2str(i),'/',num2str(stopi)]);
            %save('resultstemp.mat','E','i','I');
            %end % if mod(i,1000000)==0

        end % for i=starti:stopi
        
    end % if bi==0
    
end % if isempty(F)

% % Scale the computed errors.
% Ehat = Ehat/sum(w);
% 
% if TestBit
%     Et = Et/sum(wt);
% end % if TestBit

⌨️ 快捷键说明

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