Shannon Information Entropy Calculation in a dataset

12 visualizaciones (últimos 30 días)
Dario Krpan
Dario Krpan el 3 de Feb. de 2017
Comentada: Dario Krpan el 6 de Feb. de 2017
I have a dataset where column A corresponds to participant id, and column B corresponds to a string consisting of certain numbers.
Example:
My aim is to calculate Shannon Information Entropy (see Shannon Information Entropy for formula) for a string corresponding to each participant, and then output the values into a csv file where column A would correspond to participant id and column B to Shannon entropy value for each participant.
I have tried different approaches but have not been successful so far, so I would appreciate any advice that could point me in the right direction.
Thanks!

Respuesta aceptada

Carl
Carl el 6 de Feb. de 2017
If I understand correctly, you would like to calculate the Shannon entropy for each ParticipantId, given the probabilities that they are associated with each String. You can do something like the following:
% Assuming that ParticipantId and String are in separate, named arrays
unique_strings = unique(String(ParticipantId == 1)); % unique strings for participant 1
for index = 1:length(unique_strings)
str = unique_strings(index);
% Calculate the information,
% given probability of the current str
end
% Sum the information to get an entropy value
Note that the code above is just a brief example to show how you might structure your code. It can differ significantly depending on your use case and data format. However, it does show how you can get the unique strings for each participant, and loop through them to calculate the information. You can sum these at the end to calculate the entropy.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by