def entropy_conditional(rho,selB,base=e,sparse=False): """ Calculates the conditional entropy :math:`S(A|B)=S(A,B)-S(B)` of a slected density matrix component. Parameters ---------- rho : qobj Density matrix of composite object selB : int/list Selected components for density matrix B base : {e,2} Base of logarithm. sparse : {False,True} Use sparse eigensolver. Returns ------- ent_cond : float Value of conditional entropy """ if rho.type!='oper': raise TypeError("Input must be density matrix.") if isinstance(selB,int): selB=[selB] B=ptrace(rho,selB) out=entropy_vn(rho,base,sparse=sparse)-entropy_vn(B,base,sparse=sparse) return out
def entropy_conditional(rho, selB, base=e, sparse=False): """ Calculates the conditional entropy :math:`S(A|B)=S(A,B)-S(B)` of a slected density matrix component. Parameters ---------- rho : qobj Density matrix of composite object selB : int/list Selected components for density matrix B base : {e,2} Base of logarithm. sparse : {False,True} Use sparse eigensolver. Returns ------- ent_cond : float Value of conditional entropy """ if rho.type != 'oper': raise TypeError("Input must be density matrix.") if isinstance(selB, int): selB = [selB] B = ptrace(rho, selB) out = entropy_vn(rho, base, sparse=sparse) - entropy_vn( B, base, sparse=sparse) return out
def entropy_mutual(rho, selA, selB, base=e, sparse=False): """ Calculates the mutual information S(A:B) between selection components of a system density matrix. Parameters ---------- rho : qobj Density matrix for composite quantum systems selA : int/list `int` or `list` of first selected density matrix components. selB : int/list `int` or `list` of second selected density matrix components. base : {e,2} Base of logarithm. sparse : {False,True} Use sparse eigensolver. Returns ------- ent_mut : float Mutual information between selected components. """ if isinstance(selA, int): selA = [selA] if isinstance(selB, int): selB = [selB] if rho.type != 'oper': raise TypeError("Input must be a density matrix.") if (len(selA) + len(selB)) != len(rho.dims[0]): raise TypeError( "Number of selected components must match total number.") rhoA = ptrace(rho, selA) rhoB = ptrace(rho, selB) out = entropy_vn(rhoA, base, sparse=sparse) + entropy_vn( rhoB, base, sparse=sparse) - entropy_vn(rho, base, sparse=sparse) return out
def entropy_mutual(rho,selA,selB,base=e,sparse=False): """ Calculates the mutual information S(A:B) between selection components of a system density matrix. Parameters ---------- rho : qobj Density matrix for composite quantum systems selA : int/list `int` or `list` of first selected density matrix components. selB : int/list `int` or `list` of second selected density matrix components. base : {e,2} Base of logarithm. sparse : {False,True} Use sparse eigensolver. Returns ------- ent_mut : float Mutual information between selected components. """ if isinstance(selA,int): selA=[selA] if isinstance(selB,int): selB=[selB] if rho.type!='oper': raise TypeError("Input must be a density matrix.") if (len(selA)+len(selB))!=len(rho.dims[0]): raise TypeError("Number of selected components must match total number.") rhoA=ptrace(rho,selA) rhoB=ptrace(rho,selB) out=entropy_vn(rhoA,base,sparse=sparse)+entropy_vn(rhoB,base,sparse=sparse)-entropy_vn(rho,base,sparse=sparse) return out