## Fastest way to compute entropy in Python

In my project I need to compute the entropy of 0-1 vectors many times. Here’s my code: def entropy(labels): “”” Computes entropy of 0-1 vector. “”” n_labels = len(labels) if n_labels <= 1: return 0 counts = np.bincount(labels) probs = counts[np.nonzero(counts)] / n_labels n_classes = len(probs) if n_classes <= 1: return 0 return – np.sum(probs … Read more

## What is the computer science definition of entropy?

I’ve recently started a course on data compression at my university. However, I find the use of the term “entropy” as it applies to computer science rather ambiguous. As far as I can tell, it roughly translates to the “randomness” of a system or structure. What is the proper definition of computer science “entropy”? Answer … Read more

## PGP: Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy

Setup : Ubuntu Server on Virtual Machine with 6 cores and 3GB of RAM. when I am trying to generate a asymmetric key pair via GPG like this gpg –gen-key . I get the following error : Not enough random bytes available. Please do some other work to give the OS a chance to collect … Read more

## How to calculate the entropy of a file?

How to calculate the entropy of a file? (Or let’s just say a bunch of bytes) I have an idea, but I’m not sure that it’s mathematically correct. My idea is the following: Create an array of 256 integers (all zeros). Traverse through the file and for each of its bytes, increment the corresponding position … Read more

## How to generate random SHA1 hash to use as ID in node.js?

I am using this line to generate a sha1 id for node.js: crypto.createHash(‘sha1’).digest(‘hex’); The problem is that it’s returning the same id every time. Is it possible to have it generate a random id each time so I can use it as a database document id? Answer 243,583,606,221,817,150,598,111,409x more entropy I’d recommend using crypto.randomBytes. It’s … Read more

## How to deal with a slow SecureRandom generator?

If you want a cryptographically strong random numbers in Java, you use SecureRandom. Unfortunately, SecureRandom can be very slow. If it uses /dev/random on Linux, it can block waiting for sufficient entropy to build up. How do you avoid the performance penalty? Has anyone used Uncommon Maths as a solution to this problem? Can anybody … Read more

## Why it is not a Huffman code

I have been given several examples I the aim is to explain why it is not a Huffman code. So, for instance, the first one was: {00,01,10,110} This code is not Huffman becuase it has just one codeword of maximum length whereas there should be two as a minimum. Next, the one I hava a … Read more

## Difference between a regular and a stationary source?

As far as I understand a stationary source is a regular source but it’s not necessarily true the other way around. And a stationary source is a source for which its distribution is unaffected by a “time shift” ? Can someone clarify the definition and difference of the two? Answer AttributionSource : Link , Question … Read more

## How to calculate the entropy of a system with multiple states

I’m stuck in trying to compute an overall entropy calculation with an agent. Let me first introduce some background of the problem. Basically, I’m doing some work with the contextual bandit problems. Let’s say I have an agent with m actions to select from and in different contexts (I use states in the following), it … Read more

## Why does attempting to estimate the entropy of text by randomly choosing chars in it and counting how often they are equal give wildly wrong results?

Why does attempting to estimate the entropy of a string, by randomly choosing pairs of (not necessarily adjacent) characters in it, and counting how often the selected characters in the pairs are equal, give wildly wrong results? Here is a MatLab program that exemplifies that, also available on my blog: % Ovo je MatLabski program … Read more