Code covered by the BSD License  

Highlights from
Mutual Information In probability theory and information theory

from Mutual Information In probability theory and information theory by Guangdi Li
Code for marginally and conditional mutual information in probability and information theory

ConditionalProbability( MDCObj,CurrentVar,VarParent,VectorValue )
function LogProbability = ConditionalProbability( MDCObj,CurrentVar,VarParent,VectorValue )
% P(CurrentVar | VarParent )
% VectorValue = [ CurrentVarValue, VarparentValue ];
% C = size( ClassSample,2 );
        MDC = struct( MDCObj );
        N = MDC.CaseLength;
        
        if VectorValue( CurrentVar ) == -1 
           LogProbability = 0;
           return
        end
       
        OriginalSample = MDC.OriginalSample;
        VarRangeLength = MDC.AllRangeLength( CurrentVar );
        ParentClassValue = VectorValue( VarParent );
        VarParent = VarParent( find( ParentClassValue ~= -1 )); %#ok<FNDSB> 
        UsedSample = DiscardNoneExist( OriginalSample,[ CurrentVar,VarParent ] );    
        M = N - sum( UsedSample ) ;
        
        if isempty( VarParent ) == 1 % no parent for Topo(q)
           counter = 0;
           for p=1:N
                if UsedSample( p )==0 && OriginalSample( p,CurrentVar ) == VectorValue( CurrentVar )
                   counter = counter + 1;
                end
           end
           counter1 = M;       
       elseif isempty( VarParent ) == 0 % At least one parent
              % calculate P(Vi |Parent(Vi)),s1 is for how many samples takes the value in VectorValue 
              counter=0;counter1=0; D = size( VarParent,2 );  
                for p=1:N
                    if UsedSample( p ) == 0
                         Symbol = 1;
                         for u = 1:D
                               if VectorValue( VarParent( u ) ) >= 0 && OriginalSample( p,VarParent( u ) ) ~= VectorValue( VarParent( u ) )
                                    Symbol = 0;
                                    break;
                               end     
                         end
                         if Symbol == 1                      
                               counter1 = counter1 + 1;
                               if OriginalSample( p,CurrentVar ) == VectorValue( CurrentVar )
                                  counter = counter + 1;
                               end
                         end
                    end 
                end
        end
       %    counter
       %    counter1
      
       %if counter1 == 0
       %     LogProbability = -log(N);
       % elseif counter == 0 
       %     LogProbability = -log(counter1 + VarRangeLength) ;
       % else
       %     LogProbability = log2( counter/counter1 );
       % end
            % The laplace method for adjusting parameter is used here.
            LogProbability = log2(( counter + 1 )/( counter1 + VarRangeLength   ));

  end
          

Contact us at files@mathworks.com