From 9af6e82de1aef4eade4fcbf60ffb847b9a307e95 Mon Sep 17 00:00:00 2001 From: tekhnofiend Date: Mon, 12 Nov 2007 05:31:22 +0000 Subject: [PATCH] added more spacing entropy estimators --- .../u/niche/entropy/jackknifed_m_spacing.m | 22 ++++++++++ fastlib/u/niche/entropy/kee/entropy_l2e.tex | 3 +- fastlib/u/niche/entropy/m_spacing.m | 44 ++++++++++++++++--- fastlib/u/niche/entropy/test_m_spacing.m | 11 +++++ 4 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 fastlib/u/niche/entropy/jackknifed_m_spacing.m create mode 100644 fastlib/u/niche/entropy/test_m_spacing.m diff --git a/fastlib/u/niche/entropy/jackknifed_m_spacing.m b/fastlib/u/niche/entropy/jackknifed_m_spacing.m new file mode 100644 index 0000000000..cfe0fd5090 --- /dev/null +++ b/fastlib/u/niche/entropy/jackknifed_m_spacing.m @@ -0,0 +1,22 @@ +% jackknifed_m_spacing() - get an unbiased estimate of entropy +% using jackknifed m-spacing +function H = jackknifed_m_spacing(n); + +% the vanilla m-spacing estimator for reference +%{ +sum_logs = 0; +for i = 1:n + if (i + m) > n + sum_logs = sum_logs + log( (n/(2*m)) * (Z(n) - Z(i-m))); + elseif (i-m) < 1 + sum_logs = sum_logs + log( (n/(2*m)) * (Z(i+m) - Z(1))); + else + sum_logs = sum_logs + log( (n/(2*m)) * (Z(i+m) - Z(i-m))); + end +end +%} + +H = 1; + +% consider leaving out i + diff --git a/fastlib/u/niche/entropy/kee/entropy_l2e.tex b/fastlib/u/niche/entropy/kee/entropy_l2e.tex index 1f1eca5879..a5c579b626 100644 --- a/fastlib/u/niche/entropy/kee/entropy_l2e.tex +++ b/fastlib/u/niche/entropy/kee/entropy_l2e.tex @@ -1,4 +1,3 @@ -%\documentclass{amsart} \documentclass{article} \usepackage{amsmath, amsthm} \usepackage[colorlinks=true]{hyperref} @@ -118,7 +117,7 @@ \section{Expanded $L_2E$ objective function} \begin{displaymath} - \frac{1}{\vert Q \vert} \sum_{q \in Q} \left( T_{\log} \left( \frac{1}{N} \sum_{i=1}^n K_h(d(q,x_i)) \right) \right) ^2 - 2 \sum_{i=1}^n \log \hat{f}_{h_E,-i}(x_i) \hat{f}_{h,-i}(x_i) \log \hat{f}_{h,-i}(x_i) + \arg \min_h \frac{1}{\vert Q \vert} \sum_{q \in Q} \left( T_{\log} \left( \frac{1}{N} \sum_{i=1}^n K_h(d(q,x_i)) \right) \right) ^2 - 2 \sum_{i=1}^n \log \hat{f}_{h_E,-i}(x_i) \hat{f}_{h,-i}(x_i) \log \hat{f}_{h,-i}(x_i) \end{displaymath} where $ T_{\log}(p) = p \log(p) $ and $Q$ is a set of sample points on the range of $X$ (e.g. linear spacing of $M$ points) diff --git a/fastlib/u/niche/entropy/m_spacing.m b/fastlib/u/niche/entropy/m_spacing.m index ba548d201b..7e0c6ee218 100644 --- a/fastlib/u/niche/entropy/m_spacing.m +++ b/fastlib/u/niche/entropy/m_spacing.m @@ -1,15 +1,45 @@ % m_spacing() - estimate entropy using m-spacing -function H = m_spacing(X, m); +function H = m_spacing(n); + +randn('seed', sum(100*clock)); + +X = normrnd(zeros(n, 1), 1); + +m = round(sqrt(n)/2); -X = X / std(X); -N = length(X); Z = sort(X, 'ascend'); -sum = 0; -for i = 1 : (N - m) - sum = sum + log2( (N / m) * (Z(i + m) - Z(i)) ); +sum_logs = 0; +%for i = (m+1):(n-m) +for i = 1:n + if (i + m) > n + sum_logs = sum_logs + log( (n/(2*m)) * (Z(n) - Z(i-m))); + elseif (i-m) < 1 + sum_logs = sum_logs + log( (n/(2*m)) * (Z(i+m) - Z(1))); + else + sum_logs = sum_logs + log( (n/(2*m)) * (Z(i+m) - Z(i-m))); + end end -H = sum / N; \ No newline at end of file +H = sum_logs / n; +%H = sum_logs / (n-2*m); + +% Vasicek's bias correction + +sum_psi = 0; +for i=1:m + sum_psi = sum_psi + psi(i+m-1); +end + +bias = ... + + log(n) ... + - log(2*m) ... + + (1 - 2*m/n) * psi(2*m) ... + - psi(n+1) ... + + (2/n) * sum_psi; + + + +H = H - bias; \ No newline at end of file diff --git a/fastlib/u/niche/entropy/test_m_spacing.m b/fastlib/u/niche/entropy/test_m_spacing.m new file mode 100644 index 0000000000..883589fbd1 --- /dev/null +++ b/fastlib/u/niche/entropy/test_m_spacing.m @@ -0,0 +1,11 @@ +function mean_H_minus_opt = test_m_spacing(num_trials, n); + +opt=log(sqrt(2*pi*exp(1))); + +h = zeros(num_trials,1); + +for i=1:num_trials + h(i) = m_spacing(n); +end + +mean_H_minus_opt = mean(h) - opt;