<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Miguel Henry &#8211; Aptech</title>
	<atom:link href="https://www.aptech.com/blog/author/miguelh/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aptech.com</link>
	<description>GAUSS Software - Fastest Platform for Data Analytics</description>
	<lastBuildDate>Wed, 26 Feb 2020 21:48:45 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Permutation Entropy</title>
		<link>https://www.aptech.com/blog/permutation-entropy/</link>
					<comments>https://www.aptech.com/blog/permutation-entropy/#respond</comments>
		
		<dc:creator><![CDATA[Miguel Henry]]></dc:creator>
		<pubDate>Wed, 12 Dec 2018 00:19:30 +0000</pubDate>
				<category><![CDATA[Econometrics]]></category>
		<category><![CDATA[Time Series]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=18901</guid>

					<description><![CDATA[Permutation Entropy (PE) is a robust time series tool which provides a quantification measure of the complexity of a dynamic system by capturing the order relations between values of a time series and extracting a probability distribution of the ordinal patterns  <a href="https://www.mdpi.com/2225-1146/7/1/10">(see Henry and Judge, 2019)</a>.  Today, we will learn about the PE methodology and will demonstrate its use through a toy example. 
]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Permutation Entropy (PE) is a robust time series tool which provides a quantification measure of the complexity of a dynamic system by capturing the order relations between values of a time series and extracting a probability distribution of the ordinal patterns (see <a href="https://www.mdpi.com/2225-1146/7/1/10">Henry and Judge, 2019</a>).</p>
<p>Among its main features, the PE approach:</p>
<ul>
<li>Is non-parametric and is free of restrictive parametric model assumptions.</li>
<li>Is robust with respect to noise, computationally efficient, flexible, and invariant with respect to non-linear monotonic transformations of the data.</li>
<li>Relies on the notions of entropy and symbolic dynamics.</li>
<li>Accounts for the temporal ordering structure (time causality) of a given time series of real values.</li>
<li>Allows the user to unlock the complex dynamic content of nonlinear time series.</li>
</ul>
<p>Today, we will learn about the PE methodology and will demonstrate its use through a toy example. In a future blog, we will demonstrate the application of this technique to real-world data and show how to estimate time-varying PE estimates.</p>
<h2 id="methodology">Methodology</h2>
<p>The starting point of PE analysis is a one-dimensional time series. For illustration purposes, we will use the example given by <a href="https://pdfs.semanticscholar.org/04de/9ce062c6ac999fa009b9c264da20a8d8a282.pdf">Bandt and Pompe (2002)</a>.</p>
<p>$$\begin{equation}S(t) = \{\ 4, 7, 9, 10, 6, 11, 3\ \}\label{example_ts}\end{equation}$$</p>
<h3 id="partitioning-the-state-space">Partitioning the State Space</h3>
<p>The first step is to partition the one-dimensional time series into a matrix of overlapping column vectors. This partitioning uses two hyperparameters:</p>
<table>
<thead>
<tr>
<th> </th>
<th>$\tau$</th>
<th>D</th>
</tr>
</thead>
<tbody>
<tr>
<td>Description</td>
<td>The <em>embedding time delay</em> which controls the number of time periods between elements of each of the new column vectors.</td>
<td>The <em>embedding dimension</em> which controls the length of each of the new column vectors.</td>
</tr>
<tr>
<td>Valid range</td>
<td>Any positive integer.</td>
<td>Any integer &gt; 1.</td>
</tr>
<tr>
<td>Recommended value(s)</td>
<td>1</td>
<td>3 ≤ D ≤ 7<sup>*</sup></td>
</tr>
</tbody>
</table>
<div style="font-size: 0.7em"><sup>*</sup>For practical purposes, Band and Pompe (2002) suggest to use $3\le D\le7$ with $\tau = 1$. However, other values $\tau$ can be chosen depending upon the application and on the time series under study.</div>
<p> </p>
<p>Using $D=3$ and $\tau = 1$, our sample data in $(\ref{example_ts})$ is partitioned as follows</p>
<p>$$ \begin{equation}\begin{bmatrix} 4 &7 &9 &10 &6 \\ 7 &9 &10 &6 &11 \\ 9 &10 &6 &11 &3 \end{bmatrix}\label{SSPM}\end{equation} $$</p>
<p>Each column vector has 3 elements because the embedding dimension, <em>D</em>, is set to 3. In addition, there is a single time period between each element in the vectors because our the embedded time delay, $\tau$, is set to 1.</p>
<p>The number of column vectors created for a $T$ dimensional vector will be $T - (D - 1)\tau$. The matrix shown in $(\ref{SSPM})$ contains $7 - 1(3 - 1) = 5$ column vectors.</p>
<h3 id="finding-the-ordinal-patterns">Finding the Ordinal Patterns</h3>
<p>After partitioning the one-dimensional time series, the D-dimensional vectors in $(\ref{SSPM})$ are mapped into unique permutations that capture the ordinal <em>rankings</em> of the data:</p>
<p>$$ \pi = \{\ r_0, r_1, \ldots, r_{D-1} \}\ = \{\ 0, 1, \ldots, D-1 \}$$</p>
<p>Following with the example above, there are $3! = 6$ different possible permutations (ordinal patterns) in total:</p>
<p>$$ \pi_1 = \{ 0, 1, 2 \} \\ \pi_2 = \{ 0, 2, 1 \} \\ \pi_3 = \{ 1, 0 ,2 \} \\ \pi_4 = \{ 1, 2, 0 \} \\ \pi_5= \{ 2, 0 ,1 \} \\ \pi_6 = \{ 2, 1, 0 \} $$</p>
<p>These permutations assign values to each partitioned vector based on the ordinal position of the values within the vector. As an example, let’s consider the first 3-dimensional vector in $(\ref{SSPM})$</p>
<p>$$ \begin{bmatrix} 4 \\ 7 \\ 9 \end{bmatrix} $$</p>
<p>The permutation for this vector is $\pi_1 = \{ 0, 1, 2 \}$ because $4 < 7 < 9$. Therefore, for our example data the permutation matrix is given by</p>
<p>$$ \begin{equation}\begin{bmatrix} 0 &0 &1 &1 &1 \\ 1 &1 &2 &0 &2 \\ 2 &2 &0 &2 &0 \end{bmatrix}\end{equation} $$</p>
<p>If an input vector contains two or more elements with the same value, the rank is determined by their order in the sequence.</p>
<p>Alternatively, ties may be broken by adding white noise with the strength of the random term being smaller than the smallest distance between values.</p>
<h3 id="calculating-the-relative-frequencies">Calculating the Relative Frequencies</h3>
<p>The relative frequency of each permutation can be calculated by counting the number of times the permutation is found in the time series divided by the total number of sequences.</p>
<table>
<thead>
<tr>
<th style="text-align: center;">Permutation</th>
<th style="text-align: center;">Number of Occurrences</th>
<th style="text-align: center;">$p_i$</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center;">$\pi_1$</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">$2/5$</td>
</tr>
<tr>
<td style="text-align: center;">$\pi_2$</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">$0/5$</td>
</tr>
<tr>
<td style="text-align: center;">$\pi_3$</td>
<td style="text-align: center;">1</td>
<td style="text-align: center;">$1/5$</td>
</tr>
<tr>
<td style="text-align: center;">$\pi_4$</td>
<td style="text-align: center;">2</td>
<td style="text-align: center;">$2/5$</td>
</tr>
<tr>
<td style="text-align: center;">$\pi_5$</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">$0/5$</td>
</tr>
<tr>
<td style="text-align: center;">$\pi_6$</td>
<td style="text-align: center;">0</td>
<td style="text-align: center;">$0/5$</td>
</tr>
</tbody>
</table>
<h3 id="computing-the-pe">Computing the PE</h3>
<p>Finally, the previous probabilities are used to compute the PE of order $D$ of the time series, which is given by</p>
<p>$$\begin{equation}PE_D = - \sum_{i=1}^{D!} p_i log_2 p_i\label{compute_PE}\end{equation}$$</p>
<p>Continuing with the toy example, the PE of order 3 is</p>
<p>$$PE_3 = -(2/5 log_2(2/5) + 1/5 log_2(1/5) + 2/5 log_2(2/5)) \approx 1.5219$$</p>
<p>The PE measure in $(\ref{compute_PE})$ can also be normalized such that</p>
<p>$$PE_{D, norm} = -\frac{1}{log_2 D!} \sum_{i=0}^{D!} p_i log_2 p_i, $$</p>
<p>which is restricted between 0 and 1. Using the toy example,</p>
<p>$$PE_{3, norm} = -\frac{1}{log_2 3!} 1.5219 = 0.5887$$</p>
<h3 id="interpreting-the-pe-value">Interpreting the PE value</h3>
<p>The smaller the $PE_{D, norm}$ is, the more regular and more deterministic the time series is. Contrarily, the closer to 1 the $PE_{D, norm}$ is, the more noisy and random the time series is.</p>
<p>For example, suppose our 7 data observations were very noisy and each partition fell into a different permutation group. In this case our normalized PE measure will be:</p>
<p>$$PE_3 = -\frac{1}{log_2 3!} (1/5 log_2(1/5) + 1/5 log_2(1/5) + 1/5 log_2(1/5) +\\ 1/5 log_2(1/5) + 1/5 log_2(1/5)) \approx 0.898 .$$ </p>
<p>Conversely, if observations were completely deterministic, each partition would fall into the same permutation group. In this case our normalized PE measure will be:</p>
<p>$$PE_3 = -\frac{1}{log_2 3!} (5/5 log_2(5/5)) = 0.000 .$$ </p>
<h2 id="computing-pe-in-gauss">Computing PE in GAUSS</h2>
<p>Our <a href="https://github.com/ec78/gauss_blog/tree/master/time_series/permutation-entropy-12.13.18">GAUSS code</a> can be used to compute the permutation entropy of time series. Using the function <code>pentropy</code> we can
compute the permutation of our toy example.</p>
<p>The function <code>pentropy</code> has three required inputs:</p>
<hr />
<dl>
<dt>x</dt>
<dd>Vector, the one-dimensional time series.</dd>
<dt>tau</dt>
<dd>Scalar, the <em>embedded time delay</em> that determines the time separation between $x_t$ values.</dd>
<dt>D</dt>
<dd>Scalar, the <em>embedding dimension</em>.</dd>
</dl>
<hr />
<p>It has one return, an instance of the <code>peOut</code> structure with the following structure members:</p>
<hr />
<dl>
<dt>peOut.h</dt>
<dd>Scalar, the PE measure.</dd>
<dt>peOut.h_norm</dt>
<dd>Scalar, the normalized PE measure.</dd>
<dt>peOut.relfreq</dt>
<dd>Vector, relative frequencies of the ordinal patterns.</dd>
</dl>
<hr />
<p>Using GAUSS to find our permutation entropy measures:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">library pe;

x = {4, 7, 9, 10, 6, 11, 3};

// Define output structure
struct peOut pOut;

// Define embedding dimension
D = 3;

// Define embedded time delay
tau = 1;

// Call pentropy
pOut = pentropy(x, D, tau);

print "The permutation entropy is:";
print pOut.h;

print "The normalized permutation entropy is:";
print pOut.h_norm;

print "The relative frequencies of the ordinal patterns:";
print pOut.relfreq;</code></pre>
<p>Yields the following:</p>
<pre>The permutation entropy is:
1.5219281
The normalized permutation entropy is:
0.58876216
The relative frequencies of the ordinal patterns:

0.40000000
0.20000000
0.40000000</pre>
<h3 id="conclusions">Conclusions</h3>
<p>Today we've learned the basics of permutation entropy using a toy example. After today you should have a better understanding of:</p>
<ol>
<li>The features of permutation entropy.</li>
<li>The permutation entropy methodology.</li>
<li>How to use GAUSS to find permutation entropy measures.</li>
</ol>
<p>Code and data from this blog can be found <a href="https://github.com/aptech/gauss_blog/tree/master/time_series/permutation-entropy-12.13.18">here</a>.</p>
<h2 id="references">References</h2>
<p>Bandt, C. and B. Pompe, 2002, “Permutation Entropy: A Natural Complexity Measure for Time Series,” <em>Physics Review Letters</em>, 88, 174102:1-174102:4.</p>
<p><a href="https://www.mdpi.com/2225-1146/7/1/10">Henry, M. and G. Judge, 2019</a>, “Permutation Entropy and Information Recovery in Nonlinear Dynamic Economic Time Series,” <em>Econometrics</em>, 7(1), 10.</p>
<p>
    <!-- MathJax configuration -->
    <style>
        .mjx-svg-href {
            fill: "inherit" !important;
            stroke: "inherit" !important;
        }
    </style>
    <script type="text/x-mathjax-config">
        MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "AMS"} } });
    </script>
    <script type="text/javascript">
window.MathJax = {
  tex2jax: {
    inlineMath: [ ['$','$'] ],
    displayMath: [ ['$$','$$'] ],
    processEscapes: true,
    processEnvironments: true
  },
  // Center justify equations in code and markdown cells. Elsewhere
  // we use CSS to left justify single line equations in code cells.
  displayAlign: 'center',
  "HTML-CSS": {
    styles: {'.MathJax_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  "SVG": {
    styles: {'.MathJax_SVG_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  showProcessingMessages: false,
  messageStyle: "none",
  menuSettings: { zoom: "Click" },
  AuthorInit: function() {
    MathJax.Hub.Register.StartupHook("End", function() {
            var timeout = false, // holder for timeout id
            delay = 250; // delay after event is "complete" to run callback
            var shrinkMath = function() {
              //var dispFormulas = document.getElementsByClassName("formula");
              var dispFormulas = document.getElementsByClassName("MathJax_SVG_Display");
              if (dispFormulas){
                // caculate relative size of indentation
                var contentTest = document.getElementsByTagName("body")[0];
                var nodesWidth = contentTest.offsetWidth;
                // if you have indentation
                var mathIndent = MathJax.Hub.config.displayIndent; //assuming px's
                var mathIndentValue = mathIndent.substring(0,mathIndent.length - 2);
                for (var i=0; i<dispFormulas.length; i++){
                  var dispFormula = dispFormulas[i];
                  var wrapper = dispFormula;
                  //var wrapper = dispFormula.getElementsByClassName("MathJax_Preview")[0].nextSibling;
                  var child = wrapper.firstChild;
                  wrapper.style.transformOrigin = "center"; //or top-left if you left-align your equations
                  var oldScale = child.style.transform;
                  //var newValue = Math.min(0.80*dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newValue = Math.min(dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newScale = "scale(" + newValue + ")";
                  if(newValue != "NaN" && !(newScale === oldScale)){
                    wrapper.style.transform = newScale;
                    wrapper.style["margin-left"]= Math.pow(newValue,4)*mathIndentValue + "px";
                    var wrapperStyle = window.getComputedStyle(wrapper);
                    var wrapperHeight = parseFloat(wrapperStyle.height);
                    wrapper.style.height = "" + (wrapperHeight * newValue) + "px";
                    if(newValue === "1.00"){
                      wrapper.style.cursor = "";
                      wrapper.style.height = "";
                    }
                    else {
                      wrapper.style.cursor = "zoom-in";
                    }
                  }

                }
            }
            };
            shrinkMath();
            window.addEventListener('resize', function() {
              clearTimeout(timeout);
              timeout = setTimeout(shrinkMath, delay);
            });
          });
  }
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS_SVG"></script></p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/permutation-entropy/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
