mirror of https://github.com/jlizier/jidt
82 lines
3.2 KiB
Matlab
Executable File
82 lines
3.2 KiB
Matlab
Executable File
% function [names, entropies, winRates, lossRates] = computeConditionalEntropyForAllPlayers()
|
|
%
|
|
% Compute the conditional entropy of moves for each player, conditioned on their previous move,
|
|
% across all games/iterations
|
|
%
|
|
|
|
function [names, entropies, winRates, lossRates] = computeConditionalEntropyForAllPlayers()
|
|
|
|
% Step 1: load all of the player's names:
|
|
names = listPlayers();
|
|
|
|
% Step 2: compute conditional entropy for each player:
|
|
index = 1;
|
|
entropies = zeros(length(names),1);
|
|
winRates = zeros(length(names),1);
|
|
lossRates = zeros(length(names),1);
|
|
for name = names
|
|
[calculatedEntropy, winRate, lossRate, numGames] = ...
|
|
computeConditionalEntropyForPlayer(name{:});
|
|
fprintf('%s: %.4f bits,\twin rate = %.4f,\tloss rate = %.4f, num games = %d\n', ...
|
|
name{:}, calculatedEntropy, winRate, lossRate, numGames);
|
|
|
|
entropies(index) = calculatedEntropy;
|
|
winRates(index) = winRate;
|
|
lossRates(index) = lossRate;
|
|
|
|
index = index + 1;
|
|
end
|
|
|
|
% Plot the winRates and lossRates versus entropies:
|
|
figure(1);
|
|
plot(entropies, winRates, 'x');
|
|
title('Win rates versus cond entropies of single players');
|
|
xlabel('Entropy of moves (bits)');
|
|
ylabel('Win rate');
|
|
figure(2);
|
|
plot(entropies, lossRates, 'x');
|
|
title('Loss rates versus cond entropies of single players');
|
|
xlabel('Entropy of moves (bits)');
|
|
ylabel('Loss rate');
|
|
|
|
% Compute correlations and check if these are statistically significant:
|
|
% Are these statistically significant?
|
|
if (exist ('OCTAVE_VERSION', 'builtin'))
|
|
% This is running on Octave (not Matlab), so do this the hard way:
|
|
winToEntropyCorr = corr(winRates, entropies);
|
|
lossToEntropyCorr = corr(lossRates, entropies);
|
|
% Now compute the pValues:
|
|
winToEntropyCorrTValue = winToEntropyCorr ./ ...
|
|
sqrt((1-winToEntropyCorr.^2) ./ (length(names)-2));
|
|
lossToEntropyCorrTValue = lossToEntropyCorr ./ ...
|
|
sqrt((1-lossToEntropyCorr.^2) ./ (length(names)-2));
|
|
% Using two-tailed tests:
|
|
winToEntropyCorrTCdf = tcdf(winToEntropyCorrTValue, length(names)-2);
|
|
if (winToEntropyCorrTCdf < 0.5)
|
|
% Account for the probability mass on the other tail of the distribution:
|
|
winToEntropyCorrPValue = winToEntropyCorrTCdf .* 2;
|
|
else
|
|
% Account for the probability mass on the other tail of the distribution:
|
|
winToEntropyCorrPValue = 2.*(1 - winToEntropyCorrTCdf);
|
|
end
|
|
lossToEntropyCorrTCdf = tcdf(lossToEntropyCorrTValue, length(names)-2);
|
|
if (lossToEntropyCorrTCdf < 0.5)
|
|
% Account for the probability mass on the other tail of the distribution:
|
|
lossToEntropyCorrPValue = lossToEntropyCorrTCdf .* 2;
|
|
else
|
|
% Account for the probability mass on the other tail of the distribution:
|
|
lossToEntropyCorrPValue = 2.*(1 - lossToEntropyCorrTCdf);
|
|
end
|
|
else
|
|
% We're running on Matlab, so do this the easy way:
|
|
[winToEntropyCorr, winToEntropyCorrPValue] = corr(winRates, entropies);
|
|
[lossToEntropyCorr, lossToEntropyCorrPValue] = corr(lossRates, entropies);
|
|
end
|
|
fprintf('Correlation of win rate to cond entropy is: %.4f (pValue %.4f)\n', ...
|
|
winToEntropyCorr, winToEntropyCorrPValue);
|
|
fprintf('Correlation of loss rate to cond entropy is: %.4f (pValue %.4f)\n', ...
|
|
lossToEntropyCorr, lossToEntropyCorrPValue);
|
|
|
|
end
|
|
|