Calculates shannon entropy in bits.

    Parameters
    ----------
    p : np.array
        array of probabilities

    Returns
    -------
    shannon entropy in bits
511775
def shannon_entropy(p):
    
    return -np.sum(np.where(p!=0, p * np.log2(p), 0))
198313
def entropy_calc(item, POP):
    
    try:
        result = 0
        for i in item.keys():
            likelihood = item[i] / POP[i]
            if likelihood != 0:
                result += likelihood * math.log(likelihood, 2)
        return -result
    except Exception:
        return "None"
636208
def binaryEntropyVectorized(x):
  
  entropy = - x*np.log2(x) - (1-x)*np.log2(1-x)
  entropy[x*(1 - x) == 0] = 0
  return entropy
582471
def mp2q(p, q):
    
    p, q = flatten(p), flatten(q)
    entropy_dist = 1 / len(p)
    return sum(entropy_dist * np.nan_to_num((p ** 2) / q * np.log(p / q)))
361440
def entropy_bits(
            lst: Union[
                List[Union[int, str, float, complex]],
                Tuple[Union[int, str, float, complex]]
            ]
    ) -> float:
        
        if not isinstance(lst, (tuple, list)):
            raise TypeError('lst must be a list or a tuple')

        size = len(lst)
        if (
                size == 2
                and isinstance(lst[0], (int, float))
                and isinstance(lst[1], (int, float))
        ):
            return calc_entropy_bits_nrange(lst[0], lst[1])

        return calc_entropy_bits(lst)
1275014
def P(self):
        
        P = np.r_[np.c_[self.S, self.t], np.array([0,0,0,1])]
        return P
139177
def _get_image_entropy(self, image):
        """"""
        hist = image.histogram()
        hist_size = sum(hist)
        hist = [float(h) / hist_size for h in hist]
        return -sum([p * math.log(p, 2) for p in hist if p != 0])
573930
def generated_passphrase_entropy(self) -> float:
        """"""
        if (
                self.amount_w is None
                or self.amount_n is None
                or not self.wordlist
        ):
            raise ValueError("Can't calculate the passphrase entropy: "
                             "wordlist is empty or amount_n or "
                             "amount_w isn't set")

        if self.amount_n == 0 and self.amount_w == 0:
            return 0.0

        entropy_n = self.entropy_bits((self.randnum_min, self.randnum_max))

        # The entropy for EFF Large Wordlist is ~12.9, no need to calculate
        entropy_w = self._wordlist_entropy_bits \
            if self._wordlist_entropy_bits \
            else self.entropy_bits(self.wordlist)

        return calc_passphrase_entropy(
            self.amount_w,
            entropy_w,
            entropy_n,
            self.amount_n
        )
1243182
public static float entropy(float[] c) {
		
		float e = 0.0f;
		for(int i=0;i<c.length;i++){
			if(c[i]!=0.0&&c[i]!=1){
				e -= c[i]*Math.log(c[i]);
			}
			
		}
		return e;
	}
299203
def entropy(args):
    
    p = OptionParser(entropy.__doc__)
    p.add_option("--threshold", default=0, type="int",
                help="Complexity needs to be above")
    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    kmc_out, = args
    fp = open(kmc_out)
    for row in fp:
        kmer, count = row.split()
        score = entropy_score(kmer)
        if score >= opts.threshold:
            print(" ".join((kmer, count, "{:.2f}".format(score))))
504577
def bits(self):
        
        try:
            return self._bits
        except AttributeError:
            if self.dtype.name.startswith(('uint', 'int')):
                nbits = self.itemsize * 8
                self.bits = Bits(['Bit %d' % b for b in range(nbits)],
                                 channel=self.channel, epoch=self.epoch)
                return self.bits
            elif hasattr(self.channel, 'bits'):
                self.bits = self.channel.bits
                return self.bits
            return None
432676
def maxEntropy(n,k):
  

  s = float(k)/n
  if s > 0.0 and s < 1.0:
    entropy = - s * math.log(s,2) - (1 - s) * math.log(1 - s,2)
  else:
    entropy = 0

  return n*entropy
1303801
def get_entropy(self):
        
        dim = self.mu.shape[0]
        entropy = 0.5 * (dim * (numpy.log(2. * numpy.pi) + 1.) + numpy.log(self.det))
        return entropy
787693
public static double Entropy( int[] values ){
        int     n = values.length;
        int     total = 0;
        double  entropy = 0;
        double  p;

        // calculate total amount of hits
        for ( int i = 0; i < n; i++ )
        {
            total += values[i];
        }

        if ( total != 0 )
        {
            // for all values
            for ( int i = 0; i < n; i++ )
            {
                // get item's probability
                p = (double) values[i] / total;
                // calculate entropy
                if ( p != 0 )
                    entropy += ( -p * (Math.log10(p)/Math.log10(2)) );
            }
        }
        return entropy;
    }
970184
def bits_in(length, keyspace):
    
    keyspace = len(keyspace)
    length_per_cycle = 64
    if length > length_per_cycle:
        bits = 0
        length_processed = 0
        cycles = ceil(length / length_per_cycle)
        for _ in range(int(cycles)):
            if length_processed + length_per_cycle > length:
                length_per_cycle = length - length_processed
            bits += calc_bits_in(length_per_cycle, keyspace)
            length_processed += length_per_cycle
    else:
        bits = calc_bits_in(length, keyspace)
    return float(abs(bits))
363134
def entropy(self, params):
        
        log_std = params[:, :, 1]
        return (log_std + 0.5 * (self.LOG2PI + 1)).sum(dim=-1)
122789
def entropy(s):
    
    return -sum(
        p*np.log(p) for i in range(len(s)) for p in [prop(s[i], s)]
    )