Improving documentation for the Interval and Probabilistic forecasts

This commit is contained in:
Petrônio Cândido 2018-09-28 19:35:07 -03:00
parent 404377acc3
commit c42dea2aca
25 changed files with 432 additions and 111 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -81,7 +81,7 @@
<span class="kn">import</span> <span class="nn">time</span> <span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> <span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span> <span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="k">import</span> <span class="n">FuzzySet</span><span class="p">,</span><span class="n">SortedCollection</span> <span class="kn">from</span> <span class="nn">pyFTS.common</span> <span class="k">import</span> <span class="n">FuzzySet</span><span class="p">,</span> <span class="n">SortedCollection</span>
<span class="kn">from</span> <span class="nn">pyFTS.probabilistic</span> <span class="k">import</span> <span class="n">ProbabilityDistribution</span> <span class="kn">from</span> <span class="nn">pyFTS.probabilistic</span> <span class="k">import</span> <span class="n">ProbabilityDistribution</span>
@ -97,10 +97,10 @@
<span class="n">sigma</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="n">sigma</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">var</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">s</span> <span class="o">=</span> <span class="mi">0</span> <span class="n">s</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">n</span><span class="o">-</span><span class="n">k</span><span class="p">):</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">n</span> <span class="o">-</span> <span class="n">k</span><span class="p">):</span>
<span class="n">s</span> <span class="o">+=</span> <span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">]</span><span class="o">-</span><span class="n">mu</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="o">+</span><span class="n">k</span><span class="p">]</span> <span class="o">-</span> <span class="n">mu</span><span class="p">)</span> <span class="n">s</span> <span class="o">+=</span> <span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">t</span><span class="p">]</span> <span class="o">-</span> <span class="n">mu</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">t</span> <span class="o">+</span> <span class="n">k</span><span class="p">]</span> <span class="o">-</span> <span class="n">mu</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span><span class="o">/</span><span class="p">((</span><span class="n">n</span><span class="o">-</span><span class="n">k</span><span class="p">)</span><span class="o">*</span><span class="n">sigma</span><span class="p">)</span><span class="o">*</span><span class="n">s</span></div> <span class="k">return</span> <span class="mi">1</span> <span class="o">/</span> <span class="p">((</span><span class="n">n</span> <span class="o">-</span> <span class="n">k</span><span class="p">)</span> <span class="o">*</span> <span class="n">sigma</span><span class="p">)</span> <span class="o">*</span> <span class="n">s</span></div>
<div class="viewcode-block" id="rmse"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.rmse">[docs]</a><span class="k">def</span> <span class="nf">rmse</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span> <div class="viewcode-block" id="rmse"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.rmse">[docs]</a><span class="k">def</span> <span class="nf">rmse</span><span class="p">(</span><span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span>
@ -159,9 +159,9 @@
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">forecasts</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">forecasts</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span> <span class="n">forecasts</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">type</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="k">if</span> <span class="nb">type</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">forecasts</span> <span class="o">-</span> <span class="n">targets</span><span class="p">)</span> <span class="o">/</span> <span class="p">((</span><span class="n">forecasts</span> <span class="o">+</span> <span class="n">targets</span><span class="p">)</span><span class="o">/</span><span class="mi">2</span><span class="p">))</span> <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">forecasts</span> <span class="o">-</span> <span class="n">targets</span><span class="p">)</span> <span class="o">/</span> <span class="p">((</span><span class="n">forecasts</span> <span class="o">+</span> <span class="n">targets</span><span class="p">)</span> <span class="o">/</span> <span class="mi">2</span><span class="p">))</span>
<span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span> <span class="k">elif</span> <span class="nb">type</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">forecasts</span> <span class="o">-</span> <span class="n">targets</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span> <span class="o">+</span> <span class="nb">abs</span><span class="p">(</span><span class="n">targets</span><span class="p">))</span> <span class="p">)</span><span class="o">*</span><span class="mi">100</span> <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">forecasts</span> <span class="o">-</span> <span class="n">targets</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span> <span class="o">+</span> <span class="nb">abs</span><span class="p">(</span><span class="n">targets</span><span class="p">)))</span> <span class="o">*</span> <span class="mi">100</span>
<span class="k">else</span><span class="p">:</span> <span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="nb">sum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">forecasts</span> <span class="o">-</span> <span class="n">targets</span><span class="p">))</span> <span class="o">/</span> <span class="nb">sum</span><span class="p">(</span><span class="n">forecasts</span> <span class="o">+</span> <span class="n">targets</span><span class="p">)</span></div> <span class="k">return</span> <span class="nb">sum</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">forecasts</span> <span class="o">-</span> <span class="n">targets</span><span class="p">))</span> <span class="o">/</span> <span class="nb">sum</span><span class="p">(</span><span class="n">forecasts</span> <span class="o">+</span> <span class="n">targets</span><span class="p">)</span></div>
@ -187,8 +187,8 @@
<span class="n">naive</span> <span class="o">=</span> <span class="p">[]</span> <span class="n">naive</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">y</span> <span class="o">=</span> <span class="p">[]</span> <span class="n">y</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="n">l</span><span class="o">-</span><span class="mi">1</span><span class="p">):</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="n">l</span> <span class="o">-</span> <span class="mi">1</span><span class="p">):</span>
<span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">forecasts</span><span class="p">[</span><span class="n">k</span> <span class="p">]</span> <span class="o">-</span> <span class="n">targets</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span> <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">forecasts</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">-</span> <span class="n">targets</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">naive</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">targets</span><span class="p">[</span><span class="n">k</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">targets</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span> <span class="n">naive</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">targets</span><span class="p">[</span><span class="n">k</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="o">-</span> <span class="n">targets</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">**</span> <span class="mi">2</span><span class="p">)</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="nb">sum</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">/</span> <span class="nb">sum</span><span class="p">(</span><span class="n">naive</span><span class="p">))</span></div> <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="nb">sum</span><span class="p">(</span><span class="n">y</span><span class="p">)</span> <span class="o">/</span> <span class="nb">sum</span><span class="p">(</span><span class="n">naive</span><span class="p">))</span></div>
@ -203,11 +203,10 @@
<span class="sd"> &quot;&quot;&quot;</span> <span class="sd"> &quot;&quot;&quot;</span>
<span class="n">res</span> <span class="o">=</span> <span class="n">targets</span> <span class="o">-</span> <span class="n">forecasts</span> <span class="n">res</span> <span class="o">=</span> <span class="n">targets</span> <span class="o">-</span> <span class="n">forecasts</span>
<span class="n">t</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">res</span><span class="p">)</span> <span class="n">t</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
<span class="n">us</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="n">u</span><span class="o">**</span><span class="mi">2</span> <span class="k">for</span> <span class="n">u</span> <span class="ow">in</span> <span class="n">res</span><span class="p">]))</span> <span class="n">us</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="n">u</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="n">u</span> <span class="ow">in</span> <span class="n">res</span><span class="p">]))</span>
<span class="n">ys</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="n">y</span><span class="o">**</span><span class="mi">2</span> <span class="k">for</span> <span class="n">y</span> <span class="ow">in</span> <span class="n">targets</span><span class="p">]))</span> <span class="n">ys</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="n">y</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="n">y</span> <span class="ow">in</span> <span class="n">targets</span><span class="p">]))</span>
<span class="n">fs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="n">f</span><span class="o">**</span><span class="mi">2</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">forecasts</span><span class="p">]))</span> <span class="n">fs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="n">f</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">forecasts</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">us</span> <span class="o">/</span> <span class="p">(</span><span class="n">ys</span> <span class="o">+</span> <span class="n">fs</span><span class="p">)</span></div> <span class="k">return</span> <span class="n">us</span> <span class="o">/</span> <span class="p">(</span><span class="n">ys</span> <span class="o">+</span> <span class="n">fs</span><span class="p">)</span></div>
<div class="viewcode-block" id="BoxPierceStatistic"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.BoxPierceStatistic">[docs]</a><span class="k">def</span> <span class="nf">BoxPierceStatistic</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">h</span><span class="p">):</span> <div class="viewcode-block" id="BoxPierceStatistic"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.BoxPierceStatistic">[docs]</a><span class="k">def</span> <span class="nf">BoxPierceStatistic</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">h</span><span class="p">):</span>
@ -220,10 +219,10 @@
<span class="sd"> &quot;&quot;&quot;</span> <span class="sd"> &quot;&quot;&quot;</span>
<span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">s</span> <span class="o">=</span> <span class="mi">0</span> <span class="n">s</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="n">h</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">h</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">acf</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span> <span class="n">r</span> <span class="o">=</span> <span class="n">acf</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
<span class="n">s</span> <span class="o">+=</span> <span class="n">r</span><span class="o">**</span><span class="mi">2</span> <span class="n">s</span> <span class="o">+=</span> <span class="n">r</span> <span class="o">**</span> <span class="mi">2</span>
<span class="k">return</span> <span class="n">n</span><span class="o">*</span><span class="n">s</span></div> <span class="k">return</span> <span class="n">n</span> <span class="o">*</span> <span class="n">s</span></div>
<div class="viewcode-block" id="BoxLjungStatistic"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.BoxLjungStatistic">[docs]</a><span class="k">def</span> <span class="nf">BoxLjungStatistic</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">h</span><span class="p">):</span> <div class="viewcode-block" id="BoxLjungStatistic"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.BoxLjungStatistic">[docs]</a><span class="k">def</span> <span class="nf">BoxLjungStatistic</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">h</span><span class="p">):</span>
@ -236,10 +235,10 @@
<span class="sd"> &quot;&quot;&quot;</span> <span class="sd"> &quot;&quot;&quot;</span>
<span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">s</span> <span class="o">=</span> <span class="mi">0</span> <span class="n">s</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="n">h</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">h</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">acf</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span> <span class="n">r</span> <span class="o">=</span> <span class="n">acf</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">k</span><span class="p">)</span>
<span class="n">s</span> <span class="o">+=</span> <span class="n">r</span><span class="o">**</span><span class="mi">2</span> <span class="o">/</span> <span class="p">(</span><span class="n">n</span> <span class="o">-</span><span class="n">k</span><span class="p">)</span> <span class="n">s</span> <span class="o">+=</span> <span class="n">r</span> <span class="o">**</span> <span class="mi">2</span> <span class="o">/</span> <span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="n">k</span><span class="p">)</span>
<span class="k">return</span> <span class="n">n</span><span class="o">*</span><span class="p">(</span><span class="n">n</span><span class="o">-</span><span class="mi">2</span><span class="p">)</span><span class="o">*</span><span class="n">s</span></div> <span class="k">return</span> <span class="n">n</span> <span class="o">*</span> <span class="p">(</span><span class="n">n</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">*</span> <span class="n">s</span></div>
<div class="viewcode-block" id="sharpness"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.sharpness">[docs]</a><span class="k">def</span> <span class="nf">sharpness</span><span class="p">(</span><span class="n">forecasts</span><span class="p">):</span> <div class="viewcode-block" id="sharpness"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.sharpness">[docs]</a><span class="k">def</span> <span class="nf">sharpness</span><span class="p">(</span><span class="n">forecasts</span><span class="p">):</span>
@ -248,7 +247,6 @@
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span></div> <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span></div>
<div class="viewcode-block" id="resolution"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.resolution">[docs]</a><span class="k">def</span> <span class="nf">resolution</span><span class="p">(</span><span class="n">forecasts</span><span class="p">):</span> <div class="viewcode-block" id="resolution"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.resolution">[docs]</a><span class="k">def</span> <span class="nf">resolution</span><span class="p">(</span><span class="n">forecasts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Resolution - Standard deviation of the intervals&quot;&quot;&quot;</span> <span class="sd">&quot;&quot;&quot;Resolution - Standard deviation of the intervals&quot;&quot;&quot;</span>
<span class="n">shp</span> <span class="o">=</span> <span class="n">sharpness</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span> <span class="n">shp</span> <span class="o">=</span> <span class="n">sharpness</span><span class="p">(</span><span class="n">forecasts</span><span class="p">)</span>
@ -304,9 +302,9 @@
<span class="k">if</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">target</span> <span class="ow">and</span> <span class="n">target</span> <span class="o">&lt;</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span> <span class="k">if</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">target</span> <span class="ow">and</span> <span class="n">target</span> <span class="o">&lt;</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
<span class="k">return</span> <span class="n">delta</span> <span class="k">return</span> <span class="n">delta</span>
<span class="k">elif</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">target</span><span class="p">:</span> <span class="k">elif</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&gt;</span> <span class="n">target</span><span class="p">:</span>
<span class="k">return</span> <span class="n">delta</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="p">(</span><span class="n">forecast</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">target</span><span class="p">)</span><span class="o">/</span><span class="n">tau</span> <span class="k">return</span> <span class="n">delta</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="p">(</span><span class="n">forecast</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">target</span><span class="p">)</span> <span class="o">/</span> <span class="n">tau</span>
<span class="k">elif</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">target</span><span class="p">:</span> <span class="k">elif</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="n">target</span><span class="p">:</span>
<span class="k">return</span> <span class="n">delta</span> <span class="o">+</span> <span class="mi">2</span><span class="o">*</span><span class="p">(</span><span class="n">target</span> <span class="o">-</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span><span class="o">/</span><span class="n">tau</span></div> <span class="k">return</span> <span class="n">delta</span> <span class="o">+</span> <span class="mi">2</span> <span class="o">*</span> <span class="p">(</span><span class="n">target</span> <span class="o">-</span> <span class="n">forecast</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> <span class="o">/</span> <span class="n">tau</span></div>
<div class="viewcode-block" id="winkler_mean"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.winkler_mean">[docs]</a><span class="k">def</span> <span class="nf">winkler_mean</span><span class="p">(</span><span class="n">tau</span><span class="p">,</span> <span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span> <div class="viewcode-block" id="winkler_mean"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.winkler_mean">[docs]</a><span class="k">def</span> <span class="nf">winkler_mean</span><span class="p">(</span><span class="n">tau</span><span class="p">,</span> <span class="n">targets</span><span class="p">,</span> <span class="n">forecasts</span><span class="p">):</span>
@ -335,7 +333,7 @@
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">score</span><span class="p">)</span> <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">score</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span> <span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="n">d</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">bins</span><span class="p">]))</span> <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">sum</span><span class="p">([</span><span class="n">d</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span><span class="o">.</span><span class="n">bins</span><span class="p">]))</span>
<span class="k">return</span> <span class="nb">sum</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span><span class="o">/</span><span class="nb">len</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span></div> <span class="k">return</span> <span class="nb">sum</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span></div>
<div class="viewcode-block" id="pmf_to_cdf"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.pmf_to_cdf">[docs]</a><span class="k">def</span> <span class="nf">pmf_to_cdf</span><span class="p">(</span><span class="n">density</span><span class="p">):</span> <div class="viewcode-block" id="pmf_to_cdf"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.pmf_to_cdf">[docs]</a><span class="k">def</span> <span class="nf">pmf_to_cdf</span><span class="p">(</span><span class="n">density</span><span class="p">):</span>
@ -345,7 +343,7 @@
<span class="n">prev</span> <span class="o">=</span> <span class="mi">0</span> <span class="n">prev</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">density</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span> <span class="k">for</span> <span class="n">col</span> <span class="ow">in</span> <span class="n">density</span><span class="o">.</span><span class="n">columns</span><span class="p">:</span>
<span class="n">prev</span> <span class="o">+=</span> <span class="n">density</span><span class="p">[</span><span class="n">col</span><span class="p">][</span><span class="n">row</span><span class="p">]</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">density</span><span class="p">[</span><span class="n">col</span><span class="p">][</span><span class="n">row</span><span class="p">])</span> <span class="k">else</span> <span class="mi">0</span> <span class="n">prev</span> <span class="o">+=</span> <span class="n">density</span><span class="p">[</span><span class="n">col</span><span class="p">][</span><span class="n">row</span><span class="p">]</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">np</span><span class="o">.</span><span class="n">isnan</span><span class="p">(</span><span class="n">density</span><span class="p">[</span><span class="n">col</span><span class="p">][</span><span class="n">row</span><span class="p">])</span> <span class="k">else</span> <span class="mi">0</span>
<span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="n">prev</span> <span class="p">)</span> <span class="n">tmp</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">prev</span><span class="p">)</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span> <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">)</span>
<span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">ret</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">density</span><span class="o">.</span><span class="n">columns</span><span class="p">)</span> <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">ret</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">density</span><span class="o">.</span><span class="n">columns</span><span class="p">)</span>
<span class="k">return</span> <span class="n">df</span></div> <span class="k">return</span> <span class="n">df</span></div>
@ -354,6 +352,7 @@
<div class="viewcode-block" id="heavyside"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.heavyside">[docs]</a><span class="k">def</span> <span class="nf">heavyside</span><span class="p">(</span><span class="nb">bin</span><span class="p">,</span> <span class="n">target</span><span class="p">):</span> <div class="viewcode-block" id="heavyside"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.heavyside">[docs]</a><span class="k">def</span> <span class="nf">heavyside</span><span class="p">(</span><span class="nb">bin</span><span class="p">,</span> <span class="n">target</span><span class="p">):</span>
<span class="k">return</span> <span class="mi">1</span> <span class="k">if</span> <span class="nb">bin</span> <span class="o">&gt;=</span> <span class="n">target</span> <span class="k">else</span> <span class="mi">0</span></div> <span class="k">return</span> <span class="mi">1</span> <span class="k">if</span> <span class="nb">bin</span> <span class="o">&gt;=</span> <span class="n">target</span> <span class="k">else</span> <span class="mi">0</span></div>
<div class="viewcode-block" id="heavyside_cdf"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.heavyside_cdf">[docs]</a><span class="k">def</span> <span class="nf">heavyside_cdf</span><span class="p">(</span><span class="n">bins</span><span class="p">,</span> <span class="n">targets</span><span class="p">):</span> <div class="viewcode-block" id="heavyside_cdf"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.heavyside_cdf">[docs]</a><span class="k">def</span> <span class="nf">heavyside_cdf</span><span class="p">(</span><span class="n">bins</span><span class="p">,</span> <span class="n">targets</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span> <span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">targets</span><span class="p">:</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">targets</span><span class="p">:</span>
@ -378,7 +377,7 @@
<span class="n">l</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">densities</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">bins</span><span class="p">)</span> <span class="n">l</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">densities</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">bins</span><span class="p">)</span>
<span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">densities</span><span class="p">)</span> <span class="n">n</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">densities</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">df</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">densities</span><span class="p">):</span> <span class="k">for</span> <span class="n">ct</span><span class="p">,</span> <span class="n">df</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">densities</span><span class="p">):</span>
<span class="n">_crps</span> <span class="o">+=</span> <span class="nb">sum</span><span class="p">([(</span><span class="n">df</span><span class="o">.</span><span class="n">cummulative</span><span class="p">(</span><span class="nb">bin</span><span class="p">)</span> <span class="o">-</span> <span class="p">(</span><span class="mi">1</span> <span class="k">if</span> <span class="nb">bin</span> <span class="o">&gt;=</span> <span class="n">targets</span><span class="p">[</span><span class="n">ct</span><span class="p">]</span> <span class="k">else</span> <span class="mi">0</span><span class="p">))</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="nb">bin</span> <span class="ow">in</span> <span class="n">df</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span> <span class="n">_crps</span> <span class="o">+=</span> <span class="nb">sum</span><span class="p">([(</span><span class="n">df</span><span class="o">.</span><span class="n">cumulative</span><span class="p">(</span><span class="nb">bin</span><span class="p">)</span> <span class="o">-</span> <span class="p">(</span><span class="mi">1</span> <span class="k">if</span> <span class="nb">bin</span> <span class="o">&gt;=</span> <span class="n">targets</span><span class="p">[</span><span class="n">ct</span><span class="p">]</span> <span class="k">else</span> <span class="mi">0</span><span class="p">))</span> <span class="o">**</span> <span class="mi">2</span> <span class="k">for</span> <span class="nb">bin</span> <span class="ow">in</span> <span class="n">df</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span>
<span class="k">return</span> <span class="n">_crps</span> <span class="o">/</span> <span class="nb">float</span><span class="p">(</span><span class="n">l</span> <span class="o">*</span> <span class="n">n</span><span class="p">)</span></div> <span class="k">return</span> <span class="n">_crps</span> <span class="o">/</span> <span class="nb">float</span><span class="p">(</span><span class="n">l</span> <span class="o">*</span> <span class="n">n</span><span class="p">)</span></div>
@ -393,7 +392,7 @@
<span class="sd"> :return: a list with the RMSE, SMAPE and U Statistic</span> <span class="sd"> :return: a list with the RMSE, SMAPE and U Statistic</span>
<span class="sd"> &#39;&#39;&#39;</span> <span class="sd"> &#39;&#39;&#39;</span>
<span class="n">steps_ahead</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;steps_ahead&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="n">steps_ahead</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;steps_ahead&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;point&#39;</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;point&#39;</span>
<span class="n">indexer</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;indexer&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span> <span class="n">indexer</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;indexer&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
@ -411,7 +410,7 @@
<span class="k">if</span> <span class="n">steps_ahead</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> <span class="k">if</span> <span class="n">steps_ahead</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">forecasts</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="n">forecasts</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</span> <span class="ow">and</span> <span class="n">model</span><span class="o">.</span><span class="n">has_seasonality</span><span class="p">:</span> <span class="k">if</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</span> <span class="ow">and</span> <span class="n">model</span><span class="o">.</span><span class="n">has_seasonality</span><span class="p">:</span>
<span class="n">ndata</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">ndata</span><span class="p">)</span> <span class="n">ndata</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">indexer</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">ndata</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span> <span class="k">elif</span> <span class="n">model</span><span class="o">.</span><span class="n">is_multivariate</span><span class="p">:</span>
@ -428,12 +427,12 @@
<span class="k">else</span><span class="p">:</span> <span class="k">else</span><span class="p">:</span>
<span class="n">steps_ahead_sampler</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;steps_ahead_sampler&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="n">steps_ahead_sampler</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;steps_ahead_sampler&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">nforecasts</span> <span class="o">=</span> <span class="p">[]</span> <span class="n">nforecasts</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">ndata</span><span class="p">)</span><span class="o">-</span><span class="n">steps_ahead</span><span class="p">,</span><span class="n">steps_ahead_sampler</span><span class="p">):</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">ndata</span><span class="p">)</span> <span class="o">-</span> <span class="n">steps_ahead</span><span class="p">,</span> <span class="n">steps_ahead_sampler</span><span class="p">):</span>
<span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span> <span class="n">sample</span> <span class="o">=</span> <span class="n">ndata</span><span class="p">[</span><span class="n">k</span> <span class="o">-</span> <span class="n">model</span><span class="o">.</span><span class="n">order</span><span class="p">:</span> <span class="n">k</span><span class="p">]</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="n">tmp</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">nforecasts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span> <span class="n">nforecasts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="n">start</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">+</span> <span class="n">steps_ahead</span> <span class="o">-</span><span class="mi">1</span> <span class="n">start</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">+</span> <span class="n">steps_ahead</span> <span class="o">-</span> <span class="mi">1</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">rmse</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">steps_ahead_sampler</span><span class="p">],</span> <span class="n">nforecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span> <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">rmse</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">steps_ahead_sampler</span><span class="p">],</span> <span class="n">nforecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">mape</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">steps_ahead_sampler</span><span class="p">],</span> <span class="n">nforecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span> <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">mape</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">steps_ahead_sampler</span><span class="p">],</span> <span class="n">nforecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">UStatistic</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">steps_ahead_sampler</span><span class="p">],</span> <span class="n">nforecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span> <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="n">UStatistic</span><span class="p">(</span><span class="n">ndata</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">steps_ahead_sampler</span><span class="p">],</span> <span class="n">nforecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span>
@ -442,7 +441,7 @@
<div class="viewcode-block" id="get_interval_statistics"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.get_interval_statistics">[docs]</a><span class="k">def</span> <span class="nf">get_interval_statistics</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <div class="viewcode-block" id="get_interval_statistics"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.get_interval_statistics">[docs]</a><span class="k">def</span> <span class="nf">get_interval_statistics</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;</span> <span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Condensate all measures for point interval forecasters</span> <span class="sd"> Condensate all measures for point interval forecasters</span>
<span class="sd"> :param data: test data</span> <span class="sd"> :param data: test data</span>
@ -450,7 +449,7 @@
<span class="sd"> :param kwargs:</span> <span class="sd"> :param kwargs:</span>
<span class="sd"> :return: a list with the sharpness, resolution, coverage, .05 pinball mean,</span> <span class="sd"> :return: a list with the sharpness, resolution, coverage, .05 pinball mean,</span>
<span class="sd"> .25 pinball mean, .75 pinball mean and .95 pinball mean.</span> <span class="sd"> .25 pinball mean, .75 pinball mean and .95 pinball mean.</span>
<span class="sd"> &#39;&#39;&#39;</span> <span class="sd"> &quot;&quot;&quot;</span>
<span class="n">steps_ahead</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;steps_ahead&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="n">steps_ahead</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;steps_ahead&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;interval&#39;</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;interval&#39;</span>
@ -475,7 +474,7 @@
<span class="n">tmp</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="n">tmp</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">sample</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">forecasts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span> <span class="n">forecasts</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">tmp</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
<span class="n">start</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">+</span> <span class="n">steps_ahead</span> <span class="o">-</span><span class="mi">1</span> <span class="n">start</span> <span class="o">=</span> <span class="n">model</span><span class="o">.</span><span class="n">max_lag</span> <span class="o">+</span> <span class="n">steps_ahead</span> <span class="o">-</span> <span class="mi">1</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">sharpness</span><span class="p">(</span><span class="n">forecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span> <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">sharpness</span><span class="p">(</span><span class="n">forecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">resolution</span><span class="p">(</span><span class="n">forecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span> <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">resolution</span><span class="p">(</span><span class="n">forecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">coverage</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span> <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">coverage</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">model</span><span class="o">.</span><span class="n">max_lag</span><span class="p">:],</span> <span class="n">forecasts</span><span class="p">),</span> <span class="mi">2</span><span class="p">))</span>
@ -489,14 +488,14 @@
<div class="viewcode-block" id="get_distribution_statistics"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.get_distribution_statistics">[docs]</a><span class="k">def</span> <span class="nf">get_distribution_statistics</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <div class="viewcode-block" id="get_distribution_statistics"><a class="viewcode-back" href="../../../pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.get_distribution_statistics">[docs]</a><span class="k">def</span> <span class="nf">get_distribution_statistics</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">model</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;</span> <span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Get CRPS statistic and time for a forecasting model</span> <span class="sd"> Get CRPS statistic and time for a forecasting model</span>
<span class="sd"> :param data: test data</span> <span class="sd"> :param data: test data</span>
<span class="sd"> :param model: FTS model with probabilistic forecasting capability</span> <span class="sd"> :param model: FTS model with probabilistic forecasting capability</span>
<span class="sd"> :param kwargs:</span> <span class="sd"> :param kwargs:</span>
<span class="sd"> :return: a list with the CRPS and execution time</span> <span class="sd"> :return: a list with the CRPS and execution time</span>
<span class="sd"> &#39;&#39;&#39;</span> <span class="sd"> &quot;&quot;&quot;</span>
<span class="n">steps_ahead</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;steps_ahead&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="n">steps_ahead</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;steps_ahead&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;distribution&#39;</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;distribution&#39;</span>
@ -524,8 +523,6 @@
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">_e1</span> <span class="o">-</span> <span class="n">_s1</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span> <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">_e1</span> <span class="o">-</span> <span class="n">_s1</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span>
<span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">brier_score</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">skip</span><span class="p">],</span> <span class="n">forecasts</span><span class="p">),</span> <span class="mi">3</span><span class="p">))</span> <span class="n">ret</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">brier_score</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="o">-</span><span class="mi">1</span><span class="p">:</span><span class="n">skip</span><span class="p">],</span> <span class="n">forecasts</span><span class="p">),</span> <span class="mi">3</span><span class="p">))</span>
<span class="k">return</span> <span class="n">ret</span></div> <span class="k">return</span> <span class="n">ret</span></div>
</pre></div> </pre></div>
</div> </div>

View File

@ -146,17 +146,23 @@
<span class="sd"> :param ordered_sets: a list with the fuzzy sets names ordered by their centroids.</span> <span class="sd"> :param ordered_sets: a list with the fuzzy sets names ordered by their centroids.</span>
<span class="sd"> :return: A list with the best fuzzy sets that may contain x</span> <span class="sd"> :return: A list with the best fuzzy sets that may contain x</span>
<span class="sd"> &quot;&quot;&quot;</span> <span class="sd"> &quot;&quot;&quot;</span>
<span class="n">max_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">fuzzy_sets</span><span class="p">)</span> <span class="n">max_len</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">fuzzy_sets</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span>
<span class="n">first</span> <span class="o">=</span> <span class="mi">0</span> <span class="n">first</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">last</span> <span class="o">=</span> <span class="n">max_len</span> <span class="n">last</span> <span class="o">=</span> <span class="n">max_len</span>
<span class="k">while</span> <span class="n">first</span> <span class="o">&lt;=</span> <span class="n">last</span><span class="p">:</span> <span class="k">while</span> <span class="n">first</span> <span class="o">&lt;=</span> <span class="n">last</span><span class="p">:</span>
<span class="n">midpoint</span> <span class="o">=</span> <span class="p">(</span><span class="n">first</span> <span class="o">+</span> <span class="n">last</span><span class="p">)</span> <span class="o">//</span> <span class="mi">2</span> <span class="n">midpoint</span> <span class="o">=</span> <span class="p">(</span><span class="n">first</span> <span class="o">+</span> <span class="n">last</span><span class="p">)</span> <span class="o">//</span> <span class="mi">2</span>
<span class="n">fs</span> <span class="o">=</span> <span class="n">ordered_sets</span><span class="p">[</span><span class="n">midpoint</span><span class="p">]</span> <span class="n">fs</span> <span class="o">=</span> <span class="n">ordered_sets</span><span class="p">[</span><span class="n">midpoint</span><span class="p">]</span>
<span class="n">fs1</span> <span class="o">=</span> <span class="n">ordered_sets</span><span class="p">[</span><span class="n">midpoint</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="k">if</span> <span class="n">midpoint</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="n">ordered_sets</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="n">fs1</span> <span class="o">=</span> <span class="n">ordered_sets</span><span class="p">[</span><span class="n">midpoint</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]</span> <span class="k">if</span> <span class="n">midpoint</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="n">ordered_sets</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">fs2</span> <span class="o">=</span> <span class="n">ordered_sets</span><span class="p">[</span><span class="n">midpoint</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="k">if</span> <span class="n">midpoint</span> <span class="o">&lt;</span> <span class="n">max_len</span> <span class="k">else</span> <span class="n">ordered_sets</span><span class="p">[</span><span class="n">max_len</span><span class="p">]</span> <span class="n">fs2</span> <span class="o">=</span> <span class="n">ordered_sets</span><span class="p">[</span><span class="n">midpoint</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="k">if</span> <span class="n">midpoint</span> <span class="o">&lt;</span> <span class="n">max_len</span> <span class="k">else</span> <span class="n">ordered_sets</span><span class="p">[</span><span class="n">max_len</span><span class="p">]</span>
<span class="k">if</span> <span class="n">fuzzy_sets</span><span class="p">[</span><span class="n">fs1</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span> <span class="o">&lt;=</span> <span class="n">x</span> <span class="o">&lt;=</span> <span class="n">fuzzy_sets</span><span class="p">[</span><span class="n">fs2</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span><span class="p">:</span> <span class="k">if</span> <span class="n">fuzzy_sets</span><span class="p">[</span><span class="n">fs1</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span> <span class="o">&lt;=</span> <span class="n">x</span> <span class="o">&lt;=</span> <span class="n">fuzzy_sets</span><span class="p">[</span><span class="n">fs2</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span><span class="p">:</span>
<span class="k">return</span> <span class="p">(</span><span class="n">midpoint</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">midpoint</span><span class="p">,</span> <span class="n">midpoint</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span> <span class="k">return</span> <span class="p">(</span><span class="n">midpoint</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">midpoint</span><span class="p">,</span> <span class="n">midpoint</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">midpoint</span> <span class="o">&lt;=</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">return</span> <span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">elif</span> <span class="n">midpoint</span> <span class="o">&gt;=</span> <span class="n">max_len</span><span class="p">:</span>
<span class="k">return</span> <span class="p">[</span><span class="n">max_len</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span> <span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="n">fuzzy_sets</span><span class="p">[</span><span class="n">fs</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span><span class="p">:</span> <span class="k">if</span> <span class="n">x</span> <span class="o">&lt;</span> <span class="n">fuzzy_sets</span><span class="p">[</span><span class="n">fs</span><span class="p">]</span><span class="o">.</span><span class="n">centroid</span><span class="p">:</span>
<span class="n">last</span> <span class="o">=</span> <span class="n">midpoint</span> <span class="o">-</span> <span class="mi">1</span> <span class="n">last</span> <span class="o">=</span> <span class="n">midpoint</span> <span class="o">-</span> <span class="mi">1</span>
@ -164,6 +170,7 @@
<span class="n">first</span> <span class="o">=</span> <span class="n">midpoint</span> <span class="o">+</span> <span class="mi">1</span> <span class="n">first</span> <span class="o">=</span> <span class="n">midpoint</span> <span class="o">+</span> <span class="mi">1</span>
<div class="viewcode-block" id="fuzzyfy"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.FuzzySet.fuzzyfy">[docs]</a><span class="k">def</span> <span class="nf">fuzzyfy</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <div class="viewcode-block" id="fuzzyfy"><a class="viewcode-back" href="../../../pyFTS.common.html#pyFTS.common.FuzzySet.fuzzyfy">[docs]</a><span class="k">def</span> <span class="nf">fuzzyfy</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">partitioner</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span> <span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> A general method for fuzzyfication.</span> <span class="sd"> A general method for fuzzyfication.</span>

View File

@ -240,7 +240,7 @@
<span class="sd"> :param data: time series data with the minimal length equal to the max_lag of the model</span> <span class="sd"> :param data: time series data with the minimal length equal to the max_lag of the model</span>
<span class="sd"> :param kwargs: model specific parameters</span> <span class="sd"> :param kwargs: model specific parameters</span>
<span class="sd"> :return: a list with the forecasted intervals</span> <span class="sd"> :return: a list with the prediction intervals</span>
<span class="sd"> &quot;&quot;&quot;</span> <span class="sd"> &quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;This model do not perform one step ahead interval forecasts!&#39;</span><span class="p">)</span></div> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;This model do not perform one step ahead interval forecasts!&#39;</span><span class="p">)</span></div>
@ -250,7 +250,7 @@
<span class="sd"> :param data: time series data with the minimal length equal to the max_lag of the model</span> <span class="sd"> :param data: time series data with the minimal length equal to the max_lag of the model</span>
<span class="sd"> :param kwargs: model specific parameters</span> <span class="sd"> :param kwargs: model specific parameters</span>
<span class="sd"> :return: a list with the forecasted Probability Distributions</span> <span class="sd"> :return: a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions</span>
<span class="sd"> &quot;&quot;&quot;</span> <span class="sd"> &quot;&quot;&quot;</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;This model do not perform one step ahead distribution forecasts!&#39;</span><span class="p">)</span></div> <span class="k">raise</span> <span class="ne">NotImplementedError</span><span class="p">(</span><span class="s1">&#39;This model do not perform one step ahead distribution forecasts!&#39;</span><span class="p">)</span></div>

View File

@ -124,7 +124,7 @@
<div class="viewcode-block" id="ConventionalFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.chen.ConventionalFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <div class="viewcode-block" id="ConventionalFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.chen.ConventionalFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy_series</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">)</span> <span class="n">tmpdata</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">partitioner</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;sets&#39;</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_non_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span> <span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_non_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div> <span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div>

View File

@ -136,7 +136,7 @@
<div class="viewcode-block" id="ImprovedWeightedFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ismailefendi.ImprovedWeightedFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <div class="viewcode-block" id="ImprovedWeightedFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.ismailefendi.ImprovedWeightedFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy_series</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">)</span> <span class="n">tmpdata</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">partitioner</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;sets&#39;</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span> <span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div> <span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div>

View File

@ -140,7 +140,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="ExponentialyWeightedFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.sadaei.ExponentialyWeightedFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <div class="viewcode-block" id="ExponentialyWeightedFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.sadaei.ExponentialyWeightedFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy_series</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">)</span> <span class="n">tmpdata</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">partitioner</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;sets&#39;</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span> <span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">c</span><span class="p">)</span></div> <span class="bp">self</span><span class="o">.</span><span class="n">generate_flrg</span><span class="p">(</span><span class="n">flrs</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">c</span><span class="p">)</span></div>

View File

@ -124,7 +124,7 @@
<div class="viewcode-block" id="ConventionalFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.song.ConventionalFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <div class="viewcode-block" id="ConventionalFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.song.ConventionalFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy_series</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">)</span> <span class="n">tmpdata</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">partitioner</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;sets&#39;</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_non_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span> <span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_non_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">operation_matrix</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div> <span class="bp">self</span><span class="o">.</span><span class="n">operation_matrix</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div>

View File

@ -132,7 +132,7 @@
<span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div> <span class="bp">self</span><span class="o">.</span><span class="n">flrgs</span><span class="p">[</span><span class="n">flr</span><span class="o">.</span><span class="n">LHS</span><span class="p">]</span><span class="o">.</span><span class="n">append_rhs</span><span class="p">(</span><span class="n">flr</span><span class="o">.</span><span class="n">RHS</span><span class="p">)</span></div>
<div class="viewcode-block" id="WeightedFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.yu.WeightedFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> <div class="viewcode-block" id="WeightedFTS.train"><a class="viewcode-back" href="../../../pyFTS.models.html#pyFTS.models.yu.WeightedFTS.train">[docs]</a> <span class="k">def</span> <span class="nf">train</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">ndata</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">tmpdata</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy_series</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sets</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">)</span> <span class="n">tmpdata</span> <span class="o">=</span> <span class="n">FuzzySet</span><span class="o">.</span><span class="n">fuzzyfy</span><span class="p">(</span><span class="n">ndata</span><span class="p">,</span> <span class="n">partitioner</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">partitioner</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s1">&#39;maximum&#39;</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;sets&#39;</span><span class="p">)</span>
<span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span> <span class="n">flrs</span> <span class="o">=</span> <span class="n">FLR</span><span class="o">.</span><span class="n">generate_recurrent_flrs</span><span class="p">(</span><span class="n">tmpdata</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">generate_FLRG</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div> <span class="bp">self</span><span class="o">.</span><span class="n">generate_FLRG</span><span class="p">(</span><span class="n">flrs</span><span class="p">)</span></div>

View File

@ -135,10 +135,21 @@
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
<div class="viewcode-block" id="ProbabilityDistribution.set"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.set">[docs]</a> <span class="k">def</span> <span class="nf">set</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">density</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.set"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.set">[docs]</a> <span class="k">def</span> <span class="nf">set</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span> <span class="n">density</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Assert a probability &#39;density&#39; for a certain value &#39;value&#39;, such that P(value) = density</span>
<span class="sd"> :param value: A value in the universe of discourse from the distribution</span>
<span class="sd"> :param density: The probability density to assign to the value</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">k</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">find_ge</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> <span class="n">k</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">find_ge</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">density</span></div> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">density</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.append"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append">[docs]</a> <span class="k">def</span> <span class="nf">append</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.append"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append">[docs]</a> <span class="k">def</span> <span class="nf">append</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Increment the frequency count for the values</span>
<span class="sd"> :param values: A list of values to account the frequency</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;histogram&quot;</span><span class="p">:</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;histogram&quot;</span><span class="p">:</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">values</span><span class="p">:</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">values</span><span class="p">:</span>
<span class="n">v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">find_ge</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="n">v</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">find_ge</span><span class="p">(</span><span class="n">k</span><span class="p">)</span>
@ -152,6 +163,11 @@
<span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">[</span><span class="n">v</span><span class="p">]]</span> <span class="o">=</span> <span class="n">d</span></div> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">[</span><span class="n">v</span><span class="p">]]</span> <span class="o">=</span> <span class="n">d</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.append_interval"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append_interval">[docs]</a> <span class="k">def</span> <span class="nf">append_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">intervals</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.append_interval"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append_interval">[docs]</a> <span class="k">def</span> <span class="nf">append_interval</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">intervals</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Increment the frequency count for all values inside an interval</span>
<span class="sd"> :param intervals: A list of intervals do increment the frequency</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;histogram&quot;</span><span class="p">:</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;histogram&quot;</span><span class="p">:</span>
<span class="k">for</span> <span class="n">interval</span> <span class="ow">in</span> <span class="n">intervals</span><span class="p">:</span> <span class="k">for</span> <span class="n">interval</span> <span class="ow">in</span> <span class="n">intervals</span><span class="p">:</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">inside</span><span class="p">(</span><span class="n">interval</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">interval</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bin_index</span><span class="o">.</span><span class="n">inside</span><span class="p">(</span><span class="n">interval</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">interval</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
@ -159,6 +175,12 @@
<span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span></div> <span class="bp">self</span><span class="o">.</span><span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.density"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.density">[docs]</a> <span class="k">def</span> <span class="nf">density</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.density"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.density">[docs]</a> <span class="k">def</span> <span class="nf">density</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the probability densities for the input values</span>
<span class="sd"> :param values: List of values to return the densities</span>
<span class="sd"> :return: List of probability densities for the input values</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span> <span class="n">ret</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">scalar</span> <span class="o">=</span> <span class="kc">False</span> <span class="n">scalar</span> <span class="o">=</span> <span class="kc">False</span>
@ -183,6 +205,12 @@
<span class="k">return</span> <span class="n">ret</span></div> <span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.differential_offset"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.differential_offset">[docs]</a> <span class="k">def</span> <span class="nf">differential_offset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.differential_offset"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.differential_offset">[docs]</a> <span class="k">def</span> <span class="nf">differential_offset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Auxiliary function for probability distributions of differentiated data</span>
<span class="sd"> :param value:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">nbins</span> <span class="o">=</span> <span class="p">[]</span> <span class="n">nbins</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">dist</span> <span class="o">=</span> <span class="p">{}</span> <span class="n">dist</span> <span class="o">=</span> <span class="p">{}</span>
@ -201,6 +229,11 @@
<span class="bp">self</span><span class="o">.</span><span class="n">qtl</span> <span class="o">=</span> <span class="kc">None</span></div> <span class="bp">self</span><span class="o">.</span><span class="n">qtl</span> <span class="o">=</span> <span class="kc">None</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.expected_value"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.expected_value">[docs]</a> <span class="k">def</span> <span class="nf">expected_value</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.expected_value"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.expected_value">[docs]</a> <span class="k">def</span> <span class="nf">expected_value</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the expected value of the distribution, as E[X] = ∑ x * P(x)</span>
<span class="sd"> :return: The expected value of the distribution</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="n">v</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span></div> <span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">nansum</span><span class="p">([</span><span class="n">v</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">v</span><span class="p">]</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.build_cdf_qtl"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.build_cdf_qtl">[docs]</a> <span class="k">def</span> <span class="nf">build_cdf_qtl</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.build_cdf_qtl"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.build_cdf_qtl">[docs]</a> <span class="k">def</span> <span class="nf">build_cdf_qtl</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
@ -221,7 +254,13 @@
<span class="bp">self</span><span class="o">.</span><span class="n">quantile_index</span> <span class="o">=</span> <span class="n">SortedCollection</span><span class="o">.</span><span class="n">SortedCollection</span><span class="p">(</span><span class="n">iterable</span><span class="o">=</span><span class="n">_keys</span><span class="p">)</span></div> <span class="bp">self</span><span class="o">.</span><span class="n">quantile_index</span> <span class="o">=</span> <span class="n">SortedCollection</span><span class="o">.</span><span class="n">SortedCollection</span><span class="p">(</span><span class="n">iterable</span><span class="o">=</span><span class="n">_keys</span><span class="p">)</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.cummulative"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.cummulative">[docs]</a> <span class="k">def</span> <span class="nf">cummulative</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.cumulative"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.cumulative">[docs]</a> <span class="k">def</span> <span class="nf">cumulative</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the cumulative probability densities for the input values</span>
<span class="sd"> :param values: A list of input values</span>
<span class="sd"> :return: The cumulative probability densities for the input values</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cdf</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">cdf</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">build_cdf_qtl</span><span class="p">()</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_cdf_qtl</span><span class="p">()</span>
@ -235,6 +274,12 @@
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cdf</span><span class="p">[</span><span class="n">values</span><span class="p">]</span></div> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">cdf</span><span class="p">[</span><span class="n">values</span><span class="p">]</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.quantile"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.quantile">[docs]</a> <span class="k">def</span> <span class="nf">quantile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.quantile"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.quantile">[docs]</a> <span class="k">def</span> <span class="nf">quantile</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">values</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the quantile values for the input values</span>
<span class="sd"> :param values: input values</span>
<span class="sd"> :return: The list of the quantile values for the input values</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">qtl</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">qtl</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">build_cdf_qtl</span><span class="p">()</span> <span class="bp">self</span><span class="o">.</span><span class="n">build_cdf_qtl</span><span class="p">()</span>
@ -250,21 +295,43 @@
<span class="k">return</span> <span class="n">ret</span></div> <span class="k">return</span> <span class="n">ret</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.entropy"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.entropy">[docs]</a> <span class="k">def</span> <span class="nf">entropy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.entropy"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.entropy">[docs]</a> <span class="k">def</span> <span class="nf">entropy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the entropy of the probability distribution, H[X] =</span>
<span class="sd"> :return:the entropy of the probability distribution</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">h</span> <span class="o">=</span> <span class="o">-</span><span class="nb">sum</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span> <span class="n">h</span> <span class="o">=</span> <span class="o">-</span><span class="nb">sum</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span>
<span class="k">return</span> <span class="n">h</span></div> <span class="k">return</span> <span class="n">h</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.crossentropy"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.crossentropy">[docs]</a> <span class="k">def</span> <span class="nf">crossentropy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">q</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.crossentropy"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.crossentropy">[docs]</a> <span class="k">def</span> <span class="nf">crossentropy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">q</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Cross entropy between the actual probability distribution and the informed one.</span>
<span class="sd"> :param q: a probabilistic.ProbabilityDistribution object</span>
<span class="sd"> :return: Cross entropy between this probability distribution and the given distribution</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">h</span> <span class="o">=</span> <span class="o">-</span><span class="nb">sum</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">q</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span> <span class="n">h</span> <span class="o">=</span> <span class="o">-</span><span class="nb">sum</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">q</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span>
<span class="k">return</span> <span class="n">h</span></div> <span class="k">return</span> <span class="n">h</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.kullbackleiblerdivergence"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.kullbackleiblerdivergence">[docs]</a> <span class="k">def</span> <span class="nf">kullbackleiblerdivergence</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">q</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.kullbackleiblerdivergence"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.kullbackleiblerdivergence">[docs]</a> <span class="k">def</span> <span class="nf">kullbackleiblerdivergence</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="n">q</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Kullback-Leibler divergence between the actual probability distribution and the informed one.</span>
<span class="sd"> :param q: a probabilistic.ProbabilityDistribution object</span>
<span class="sd"> :return: Kullback-Leibler divergence</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">h</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">/</span><span class="n">q</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span> <span class="n">h</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="o">/</span><span class="n">q</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">])</span>
<span class="k">return</span> <span class="n">h</span></div> <span class="k">return</span> <span class="n">h</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.empiricalloglikelihood"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.empiricalloglikelihood">[docs]</a> <span class="k">def</span> <span class="nf">empiricalloglikelihood</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.empiricalloglikelihood"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.empiricalloglikelihood">[docs]</a> <span class="k">def</span> <span class="nf">empiricalloglikelihood</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Empirical Log Likelihood of the probability distribution</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">_s</span> <span class="o">=</span> <span class="mi">0</span> <span class="n">_s</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">:</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">bins</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">distribution</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
@ -272,6 +339,12 @@
<span class="k">return</span> <span class="n">_s</span></div> <span class="k">return</span> <span class="n">_s</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.pseudologlikelihood"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.pseudologlikelihood">[docs]</a> <span class="k">def</span> <span class="nf">pseudologlikelihood</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.pseudologlikelihood"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.pseudologlikelihood">[docs]</a> <span class="k">def</span> <span class="nf">pseudologlikelihood</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Pseudo log likelihood of the probability distribution with respect to data</span>
<span class="sd"> :param data:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">densities</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="n">densities</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
@ -282,6 +355,12 @@
<span class="k">return</span> <span class="n">_s</span></div> <span class="k">return</span> <span class="n">_s</span></div>
<div class="viewcode-block" id="ProbabilityDistribution.averageloglikelihood"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.averageloglikelihood">[docs]</a> <span class="k">def</span> <span class="nf">averageloglikelihood</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span> <div class="viewcode-block" id="ProbabilityDistribution.averageloglikelihood"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.averageloglikelihood">[docs]</a> <span class="k">def</span> <span class="nf">averageloglikelihood</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Average log likelihood of the probability distribution with respect to data</span>
<span class="sd"> :param data:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">densities</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="n">densities</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

View File

@ -92,6 +92,12 @@
<span class="bp">self</span><span class="o">.</span><span class="n">transf</span> <span class="o">=</span> <span class="n">Transformations</span><span class="o">.</span><span class="n">Scale</span><span class="p">(</span><span class="nb">min</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="nb">max</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">transf</span> <span class="o">=</span> <span class="n">Transformations</span><span class="o">.</span><span class="n">Scale</span><span class="p">(</span><span class="nb">min</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span><span class="nb">max</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<div class="viewcode-block" id="KernelSmoothing.kernel_function"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.kde.KernelSmoothing.kernel_function">[docs]</a> <span class="k">def</span> <span class="nf">kernel_function</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">u</span><span class="p">):</span> <div class="viewcode-block" id="KernelSmoothing.kernel_function"><a class="viewcode-back" href="../../../pyFTS.probabilistic.html#pyFTS.probabilistic.kde.KernelSmoothing.kernel_function">[docs]</a> <span class="k">def</span> <span class="nf">kernel_function</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">u</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Apply the kernel</span>
<span class="sd"> :param u:</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel</span> <span class="o">==</span> <span class="s2">&quot;epanechnikov&quot;</span><span class="p">:</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernel</span> <span class="o">==</span> <span class="s2">&quot;epanechnikov&quot;</span><span class="p">:</span>
<span class="n">tmp</span> <span class="o">=</span> <span class="p">(</span><span class="mi">3</span><span class="o">/</span><span class="mi">4</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">u</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span> <span class="n">tmp</span> <span class="o">=</span> <span class="p">(</span><span class="mi">3</span><span class="o">/</span><span class="mi">4</span><span class="p">)</span><span class="o">*</span><span class="p">(</span><span class="mf">1.0</span> <span class="o">-</span> <span class="n">u</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="k">return</span> <span class="n">tmp</span> <span class="k">if</span> <span class="n">tmp</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span> <span class="k">return</span> <span class="n">tmp</span> <span class="k">if</span> <span class="n">tmp</span> <span class="o">&gt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span>

View File

@ -362,7 +362,7 @@
</li> </li>
<li><a href="pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.crps">crps() (in module pyFTS.benchmarks.Measures)</a> <li><a href="pyFTS.benchmarks.html#pyFTS.benchmarks.Measures.crps">crps() (in module pyFTS.benchmarks.Measures)</a>
</li> </li>
<li><a href="pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.cummulative">cummulative() (pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution method)</a> <li><a href="pyFTS.probabilistic.html#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.cumulative">cumulative() (pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution method)</a>
</li> </li>
<li><a href="pyFTS.common.html#pyFTS.common.Util.current_milli_time">current_milli_time() (in module pyFTS.common.Util)</a> <li><a href="pyFTS.common.html#pyFTS.common.Util.current_milli_time">current_milli_time() (in module pyFTS.common.Util)</a>
</li> </li>

Binary file not shown.

View File

@ -1430,7 +1430,7 @@ Value: the measure value</p>
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted Probability Distributions</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -1451,7 +1451,7 @@ Value: the measure value</p>
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted intervals</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the prediction intervals</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -1505,7 +1505,7 @@ Value: the measure value</p>
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted Probability Distributions</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -1655,7 +1655,7 @@ Value: the measure value</p>
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted Probability Distributions</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -1676,7 +1676,7 @@ Value: the measure value</p>
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted intervals</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the prediction intervals</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@ -1648,7 +1648,7 @@ when the LHS pattern is identified on time t.</p>
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted Probability Distributions</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
@ -1669,7 +1669,7 @@ when the LHS pattern is identified on time t.</p>
</ul> </ul>
</td> </td>
</tr> </tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the forecasted intervals</p> <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">a list with the prediction intervals</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>

View File

@ -118,17 +118,46 @@ If type is KDE the PDF is continuous</p>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append">
<code class="descname">append</code><span class="sig-paren">(</span><em>values</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.append"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append" title="Permalink to this definition"></a></dt> <code class="descname">append</code><span class="sig-paren">(</span><em>values</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.append"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Increment the frequency count for the values</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>values</strong> A list of values to account the frequency</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append_interval"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append_interval">
<code class="descname">append_interval</code><span class="sig-paren">(</span><em>intervals</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.append_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append_interval" title="Permalink to this definition"></a></dt> <code class="descname">append_interval</code><span class="sig-paren">(</span><em>intervals</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.append_interval"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.append_interval" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Increment the frequency count for all values inside an interval</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>intervals</strong> A list of intervals do increment the frequency</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.averageloglikelihood"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.averageloglikelihood">
<code class="descname">averageloglikelihood</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.averageloglikelihood"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.averageloglikelihood" title="Permalink to this definition"></a></dt> <code class="descname">averageloglikelihood</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.averageloglikelihood"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.averageloglikelihood" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Average log likelihood of the probability distribution with respect to data</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>data</strong> </td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute"> <dl class="attribute">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.bins"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.bins">
@ -144,42 +173,117 @@ If type is KDE the PDF is continuous</p>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.crossentropy"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.crossentropy">
<code class="descname">crossentropy</code><span class="sig-paren">(</span><em>q</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.crossentropy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.crossentropy" title="Permalink to this definition"></a></dt> <code class="descname">crossentropy</code><span class="sig-paren">(</span><em>q</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.crossentropy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.crossentropy" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Cross entropy between the actual probability distribution and the informed one.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>q</strong> a probabilistic.ProbabilityDistribution object</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Cross entropy between this probability distribution and the given distribution</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.cummulative"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.cumulative">
<code class="descname">cummulative</code><span class="sig-paren">(</span><em>values</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.cummulative"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.cummulative" title="Permalink to this definition"></a></dt> <code class="descname">cumulative</code><span class="sig-paren">(</span><em>values</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.cumulative"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.cumulative" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Return the cumulative probability densities for the input values</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>values</strong> A list of input values</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The cumulative probability densities for the input values</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.density"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.density">
<code class="descname">density</code><span class="sig-paren">(</span><em>values</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.density"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.density" title="Permalink to this definition"></a></dt> <code class="descname">density</code><span class="sig-paren">(</span><em>values</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.density"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.density" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Return the probability densities for the input values</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>values</strong> List of values to return the densities</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">List of probability densities for the input values</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.differential_offset"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.differential_offset">
<code class="descname">differential_offset</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.differential_offset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.differential_offset" title="Permalink to this definition"></a></dt> <code class="descname">differential_offset</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.differential_offset"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.differential_offset" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Auxiliary function for probability distributions of differentiated data</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>value</strong> </td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.empiricalloglikelihood"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.empiricalloglikelihood">
<code class="descname">empiricalloglikelihood</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.empiricalloglikelihood"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.empiricalloglikelihood" title="Permalink to this definition"></a></dt> <code class="descname">empiricalloglikelihood</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.empiricalloglikelihood"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.empiricalloglikelihood" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Empirical Log Likelihood of the probability distribution</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.entropy"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.entropy">
<code class="descname">entropy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.entropy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.entropy" title="Permalink to this definition"></a></dt> <code class="descname">entropy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.entropy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.entropy" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Return the entropy of the probability distribution, H[X] =</p>
<p>:return:the entropy of the probability distribution</p>
</dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.expected_value"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.expected_value">
<code class="descname">expected_value</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.expected_value"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.expected_value" title="Permalink to this definition"></a></dt> <code class="descname">expected_value</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.expected_value"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.expected_value" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Return the expected value of the distribution, as E[X] = ∑ x * P(x)</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The expected value of the distribution</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.kullbackleiblerdivergence"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.kullbackleiblerdivergence">
<code class="descname">kullbackleiblerdivergence</code><span class="sig-paren">(</span><em>q</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.kullbackleiblerdivergence"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.kullbackleiblerdivergence" title="Permalink to this definition"></a></dt> <code class="descname">kullbackleiblerdivergence</code><span class="sig-paren">(</span><em>q</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.kullbackleiblerdivergence"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.kullbackleiblerdivergence" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Kullback-Leibler divergence between the actual probability distribution and the informed one.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>q</strong> a probabilistic.ProbabilityDistribution object</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Kullback-Leibler divergence</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute"> <dl class="attribute">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.labels"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.labels">
@ -195,17 +299,52 @@ If type is KDE the PDF is continuous</p>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.pseudologlikelihood"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.pseudologlikelihood">
<code class="descname">pseudologlikelihood</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.pseudologlikelihood"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.pseudologlikelihood" title="Permalink to this definition"></a></dt> <code class="descname">pseudologlikelihood</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.pseudologlikelihood"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.pseudologlikelihood" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Pseudo log likelihood of the probability distribution with respect to data</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>data</strong> </td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.quantile"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.quantile">
<code class="descname">quantile</code><span class="sig-paren">(</span><em>values</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.quantile"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.quantile" title="Permalink to this definition"></a></dt> <code class="descname">quantile</code><span class="sig-paren">(</span><em>values</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.quantile"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.quantile" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Return the quantile values for the input values</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>values</strong> input values</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The list of the quantile values for the input values</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.set"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.set">
<code class="descname">set</code><span class="sig-paren">(</span><em>value</em>, <em>density</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.set"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.set" title="Permalink to this definition"></a></dt> <code class="descname">set</code><span class="sig-paren">(</span><em>value</em>, <em>density</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/ProbabilityDistribution.html#ProbabilityDistribution.set"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.set" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Assert a probability density for a certain value value, such that P(value) = density</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>value</strong> A value in the universe of discourse from the distribution</li>
<li><strong>density</strong> The probability density to assign to the value</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute"> <dl class="attribute">
<dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.type"> <dt id="pyFTS.probabilistic.ProbabilityDistribution.ProbabilityDistribution.type">
@ -246,7 +385,18 @@ If type is KDE the PDF is continuous</p>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.kde.KernelSmoothing.kernel_function"> <dt id="pyFTS.probabilistic.kde.KernelSmoothing.kernel_function">
<code class="descname">kernel_function</code><span class="sig-paren">(</span><em>u</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/kde.html#KernelSmoothing.kernel_function"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.kde.KernelSmoothing.kernel_function" title="Permalink to this definition"></a></dt> <code class="descname">kernel_function</code><span class="sig-paren">(</span><em>u</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pyFTS/probabilistic/kde.html#KernelSmoothing.kernel_function"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyFTS.probabilistic.kde.KernelSmoothing.kernel_function" title="Permalink to this definition"></a></dt>
<dd></dd></dl> <dd><p>Apply the kernel</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>u</strong> </td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method"> <dl class="method">
<dt id="pyFTS.probabilistic.kde.KernelSmoothing.probability"> <dt id="pyFTS.probabilistic.kde.KernelSmoothing.probability">

File diff suppressed because one or more lines are too long

View File

@ -7,7 +7,7 @@ pyFTS module for common benchmark metrics
import time import time
import numpy as np import numpy as np
import pandas as pd import pandas as pd
from pyFTS.common import FuzzySet,SortedCollection from pyFTS.common import FuzzySet, SortedCollection
from pyFTS.probabilistic import ProbabilityDistribution from pyFTS.probabilistic import ProbabilityDistribution
@ -23,10 +23,10 @@ def acf(data, k):
sigma = np.var(data) sigma = np.var(data)
n = len(data) n = len(data)
s = 0 s = 0
for t in np.arange(0,n-k): for t in np.arange(0, n - k):
s += (data[t]-mu) * (data[t+k] - mu) s += (data[t] - mu) * (data[t + k] - mu)
return 1/((n-k)*sigma)*s return 1 / ((n - k) * sigma) * s
def rmse(targets, forecasts): def rmse(targets, forecasts):
@ -85,9 +85,9 @@ def smape(targets, forecasts, type=2):
if isinstance(forecasts, list): if isinstance(forecasts, list):
forecasts = np.array(forecasts) forecasts = np.array(forecasts)
if type == 1: if type == 1:
return np.mean(np.abs(forecasts - targets) / ((forecasts + targets)/2)) return np.mean(np.abs(forecasts - targets) / ((forecasts + targets) / 2))
elif type == 2: elif type == 2:
return np.mean(np.abs(forecasts - targets) / (abs(forecasts) + abs(targets)) )*100 return np.mean(np.abs(forecasts - targets) / (abs(forecasts) + abs(targets))) * 100
else: else:
return sum(np.abs(forecasts - targets)) / sum(forecasts + targets) return sum(np.abs(forecasts - targets)) / sum(forecasts + targets)
@ -113,8 +113,8 @@ def UStatistic(targets, forecasts):
naive = [] naive = []
y = [] y = []
for k in np.arange(0,l-1): for k in np.arange(0, l - 1):
y.append((forecasts[k ] - targets[k]) ** 2) y.append((forecasts[k] - targets[k]) ** 2)
naive.append((targets[k + 1] - targets[k]) ** 2) naive.append((targets[k + 1] - targets[k]) ** 2)
return np.sqrt(sum(y) / sum(naive)) return np.sqrt(sum(y) / sum(naive))
@ -129,11 +129,10 @@ def TheilsInequality(targets, forecasts):
""" """
res = targets - forecasts res = targets - forecasts
t = len(res) t = len(res)
us = np.sqrt(sum([u**2 for u in res])) us = np.sqrt(sum([u ** 2 for u in res]))
ys = np.sqrt(sum([y**2 for y in targets])) ys = np.sqrt(sum([y ** 2 for y in targets]))
fs = np.sqrt(sum([f**2 for f in forecasts])) fs = np.sqrt(sum([f ** 2 for f in forecasts]))
return us / (ys + fs) return us / (ys + fs)
def BoxPierceStatistic(data, h): def BoxPierceStatistic(data, h):
@ -146,10 +145,10 @@ def BoxPierceStatistic(data, h):
""" """
n = len(data) n = len(data)
s = 0 s = 0
for k in np.arange(1,h+1): for k in np.arange(1, h + 1):
r = acf(data, k) r = acf(data, k)
s += r**2 s += r ** 2
return n*s return n * s
def BoxLjungStatistic(data, h): def BoxLjungStatistic(data, h):
@ -162,10 +161,10 @@ def BoxLjungStatistic(data, h):
""" """
n = len(data) n = len(data)
s = 0 s = 0
for k in np.arange(1,h+1): for k in np.arange(1, h + 1):
r = acf(data, k) r = acf(data, k)
s += r**2 / (n -k) s += r ** 2 / (n - k)
return n*(n-2)*s return n * (n - 2) * s
def sharpness(forecasts): def sharpness(forecasts):
@ -174,7 +173,6 @@ def sharpness(forecasts):
return np.mean(tmp) return np.mean(tmp)
def resolution(forecasts): def resolution(forecasts):
"""Resolution - Standard deviation of the intervals""" """Resolution - Standard deviation of the intervals"""
shp = sharpness(forecasts) shp = sharpness(forecasts)
@ -230,9 +228,9 @@ def winkler_score(tau, target, forecast):
if forecast[0] < target and target < forecast[1]: if forecast[0] < target and target < forecast[1]:
return delta return delta
elif forecast[0] > target: elif forecast[0] > target:
return delta + 2*(forecast[0] - target)/tau return delta + 2 * (forecast[0] - target) / tau
elif forecast[1] < target: elif forecast[1] < target:
return delta + 2*(target - forecast[1])/tau return delta + 2 * (target - forecast[1]) / tau
def winkler_mean(tau, targets, forecasts): def winkler_mean(tau, targets, forecasts):
@ -261,7 +259,7 @@ def brier_score(targets, densities):
ret.append(score) ret.append(score)
except ValueError as ex: except ValueError as ex:
ret.append(sum([d.distribution[k] ** 2 for k in d.bins])) ret.append(sum([d.distribution[k] ** 2 for k in d.bins]))
return sum(ret)/len(ret) return sum(ret) / len(ret)
def pmf_to_cdf(density): def pmf_to_cdf(density):
@ -271,7 +269,7 @@ def pmf_to_cdf(density):
prev = 0 prev = 0
for col in density.columns: for col in density.columns:
prev += density[col][row] if not np.isnan(density[col][row]) else 0 prev += density[col][row] if not np.isnan(density[col][row]) else 0
tmp.append( prev ) tmp.append(prev)
ret.append(tmp) ret.append(tmp)
df = pd.DataFrame(ret, columns=density.columns) df = pd.DataFrame(ret, columns=density.columns)
return df return df
@ -280,6 +278,7 @@ def pmf_to_cdf(density):
def heavyside(bin, target): def heavyside(bin, target):
return 1 if bin >= target else 0 return 1 if bin >= target else 0
def heavyside_cdf(bins, targets): def heavyside_cdf(bins, targets):
ret = [] ret = []
for t in targets: for t in targets:
@ -304,7 +303,7 @@ def crps(targets, densities):
l = len(densities[0].bins) l = len(densities[0].bins)
n = len(densities) n = len(densities)
for ct, df in enumerate(densities): for ct, df in enumerate(densities):
_crps += sum([(df.cummulative(bin) - (1 if bin >= targets[ct] else 0)) ** 2 for bin in df.bins]) _crps += sum([(df.cumulative(bin) - (1 if bin >= targets[ct] else 0)) ** 2 for bin in df.bins])
return _crps / float(l * n) return _crps / float(l * n)
@ -319,7 +318,7 @@ def get_point_statistics(data, model, **kwargs):
:return: a list with the RMSE, SMAPE and U Statistic :return: a list with the RMSE, SMAPE and U Statistic
''' '''
steps_ahead = kwargs.get('steps_ahead',1) steps_ahead = kwargs.get('steps_ahead', 1)
kwargs['type'] = 'point' kwargs['type'] = 'point'
indexer = kwargs.get('indexer', None) indexer = kwargs.get('indexer', None)
@ -337,7 +336,7 @@ def get_point_statistics(data, model, **kwargs):
if steps_ahead == 1: if steps_ahead == 1:
forecasts = model.predict(ndata, **kwargs) forecasts = model.predict(ndata, **kwargs)
if model.is_multivariate and model.has_seasonality: if model.is_multivariate and model.has_seasonality:
ndata = model.indexer.get_data(ndata) ndata = model.indexer.get_data(ndata)
elif model.is_multivariate: elif model.is_multivariate:
@ -354,12 +353,12 @@ def get_point_statistics(data, model, **kwargs):
else: else:
steps_ahead_sampler = kwargs.get('steps_ahead_sampler', 1) steps_ahead_sampler = kwargs.get('steps_ahead_sampler', 1)
nforecasts = [] nforecasts = []
for k in np.arange(model.order, len(ndata)-steps_ahead,steps_ahead_sampler): for k in np.arange(model.order, len(ndata) - steps_ahead, steps_ahead_sampler):
sample = ndata[k - model.order: k] sample = ndata[k - model.order: k]
tmp = model.predict(sample, **kwargs) tmp = model.predict(sample, **kwargs)
nforecasts.append(tmp[-1]) nforecasts.append(tmp[-1])
start = model.max_lag + steps_ahead -1 start = model.max_lag + steps_ahead - 1
ret.append(np.round(rmse(ndata[start:-1:steps_ahead_sampler], nforecasts), 2)) ret.append(np.round(rmse(ndata[start:-1:steps_ahead_sampler], nforecasts), 2))
ret.append(np.round(mape(ndata[start:-1:steps_ahead_sampler], nforecasts), 2)) ret.append(np.round(mape(ndata[start:-1:steps_ahead_sampler], nforecasts), 2))
ret.append(np.round(UStatistic(ndata[start:-1:steps_ahead_sampler], nforecasts), 2)) ret.append(np.round(UStatistic(ndata[start:-1:steps_ahead_sampler], nforecasts), 2))
@ -368,7 +367,7 @@ def get_point_statistics(data, model, **kwargs):
def get_interval_statistics(data, model, **kwargs): def get_interval_statistics(data, model, **kwargs):
''' """
Condensate all measures for point interval forecasters Condensate all measures for point interval forecasters
:param data: test data :param data: test data
@ -376,7 +375,7 @@ def get_interval_statistics(data, model, **kwargs):
:param kwargs: :param kwargs:
:return: a list with the sharpness, resolution, coverage, .05 pinball mean, :return: a list with the sharpness, resolution, coverage, .05 pinball mean,
.25 pinball mean, .75 pinball mean and .95 pinball mean. .25 pinball mean, .75 pinball mean and .95 pinball mean.
''' """
steps_ahead = kwargs.get('steps_ahead', 1) steps_ahead = kwargs.get('steps_ahead', 1)
kwargs['type'] = 'interval' kwargs['type'] = 'interval'
@ -401,7 +400,7 @@ def get_interval_statistics(data, model, **kwargs):
tmp = model.predict(sample, **kwargs) tmp = model.predict(sample, **kwargs)
forecasts.append(tmp[-1]) forecasts.append(tmp[-1])
start = model.max_lag + steps_ahead -1 start = model.max_lag + steps_ahead - 1
ret.append(round(sharpness(forecasts), 2)) ret.append(round(sharpness(forecasts), 2))
ret.append(round(resolution(forecasts), 2)) ret.append(round(resolution(forecasts), 2))
ret.append(round(coverage(data[model.max_lag:], forecasts), 2)) ret.append(round(coverage(data[model.max_lag:], forecasts), 2))
@ -415,14 +414,14 @@ def get_interval_statistics(data, model, **kwargs):
def get_distribution_statistics(data, model, **kwargs): def get_distribution_statistics(data, model, **kwargs):
''' """
Get CRPS statistic and time for a forecasting model Get CRPS statistic and time for a forecasting model
:param data: test data :param data: test data
:param model: FTS model with probabilistic forecasting capability :param model: FTS model with probabilistic forecasting capability
:param kwargs: :param kwargs:
:return: a list with the CRPS and execution time :return: a list with the CRPS and execution time
''' """
steps_ahead = kwargs.get('steps_ahead', 1) steps_ahead = kwargs.get('steps_ahead', 1)
kwargs['type'] = 'distribution' kwargs['type'] = 'distribution'
@ -450,5 +449,3 @@ def get_distribution_statistics(data, model, **kwargs):
ret.append(round(_e1 - _s1, 3)) ret.append(round(_e1 - _s1, 3))
ret.append(round(brier_score(data[start:-1:skip], forecasts), 3)) ret.append(round(brier_score(data[start:-1:skip], forecasts), 3))
return ret return ret

View File

@ -87,4 +87,4 @@ def singleton(x, parameters):
:param parameters: a list with one real value :param parameters: a list with one real value
:returns :returns
""" """
return x == parameters[0] return x == parameters[0]

View File

@ -166,7 +166,7 @@ class FTS(object):
:param data: time series data with the minimal length equal to the max_lag of the model :param data: time series data with the minimal length equal to the max_lag of the model
:param kwargs: model specific parameters :param kwargs: model specific parameters
:return: a list with the forecasted intervals :return: a list with the prediction intervals
""" """
raise NotImplementedError('This model do not perform one step ahead interval forecasts!') raise NotImplementedError('This model do not perform one step ahead interval forecasts!')
@ -176,7 +176,7 @@ class FTS(object):
:param data: time series data with the minimal length equal to the max_lag of the model :param data: time series data with the minimal length equal to the max_lag of the model
:param kwargs: model specific parameters :param kwargs: model specific parameters
:return: a list with the forecasted Probability Distributions :return: a list with probabilistic.ProbabilityDistribution objects representing the forecasted Probability Distributions
""" """
raise NotImplementedError('This model do not perform one step ahead distribution forecasts!') raise NotImplementedError('This model do not perform one step ahead distribution forecasts!')

View File

@ -61,10 +61,21 @@ class ProbabilityDistribution(object):
self.name = kwargs.get("name", "") self.name = kwargs.get("name", "")
def set(self, value, density): def set(self, value, density):
"""
Assert a probability 'density' for a certain value 'value', such that P(value) = density
:param value: A value in the universe of discourse from the distribution
:param density: The probability density to assign to the value
"""
k = self.bin_index.find_ge(value) k = self.bin_index.find_ge(value)
self.distribution[k] = density self.distribution[k] = density
def append(self, values): def append(self, values):
"""
Increment the frequency count for the values
:param values: A list of values to account the frequency
"""
if self.type == "histogram": if self.type == "histogram":
for k in values: for k in values:
v = self.bin_index.find_ge(k) v = self.bin_index.find_ge(k)
@ -78,6 +89,11 @@ class ProbabilityDistribution(object):
self.distribution[self.bins[v]] = d self.distribution[self.bins[v]] = d
def append_interval(self, intervals): def append_interval(self, intervals):
"""
Increment the frequency count for all values inside an interval
:param intervals: A list of intervals do increment the frequency
"""
if self.type == "histogram": if self.type == "histogram":
for interval in intervals: for interval in intervals:
for k in self.bin_index.inside(interval[0], interval[1]): for k in self.bin_index.inside(interval[0], interval[1]):
@ -85,6 +101,12 @@ class ProbabilityDistribution(object):
self.count += 1 self.count += 1
def density(self, values): def density(self, values):
"""
Return the probability densities for the input values
:param values: List of values to return the densities
:return: List of probability densities for the input values
"""
ret = [] ret = []
scalar = False scalar = False
@ -109,6 +131,12 @@ class ProbabilityDistribution(object):
return ret return ret
def differential_offset(self, value): def differential_offset(self, value):
"""
Auxiliary function for probability distributions of differentiated data
:param value:
:return:
"""
nbins = [] nbins = []
dist = {} dist = {}
@ -127,6 +155,11 @@ class ProbabilityDistribution(object):
self.qtl = None self.qtl = None
def expected_value(self): def expected_value(self):
"""
Return the expected value of the distribution, as E[X] = x * P(x)
:return: The expected value of the distribution
"""
return np.nansum([v * self.distribution[v] for v in self.bins]) return np.nansum([v * self.distribution[v] for v in self.bins])
def build_cdf_qtl(self): def build_cdf_qtl(self):
@ -147,7 +180,13 @@ class ProbabilityDistribution(object):
self.quantile_index = SortedCollection.SortedCollection(iterable=_keys) self.quantile_index = SortedCollection.SortedCollection(iterable=_keys)
def cummulative(self, values): def cumulative(self, values):
"""
Return the cumulative probability densities for the input values
:param values: A list of input values
:return: The cumulative probability densities for the input values
"""
if self.cdf is None: if self.cdf is None:
self.build_cdf_qtl() self.build_cdf_qtl()
@ -161,6 +200,12 @@ class ProbabilityDistribution(object):
return self.cdf[values] return self.cdf[values]
def quantile(self, values): def quantile(self, values):
"""
Return the quantile values for the input values
:param values: input values
:return: The list of the quantile values for the input values
"""
if self.qtl is None: if self.qtl is None:
self.build_cdf_qtl() self.build_cdf_qtl()
@ -176,21 +221,43 @@ class ProbabilityDistribution(object):
return ret return ret
def entropy(self): def entropy(self):
"""
Return the entropy of the probability distribution, H[X] =
:return:the entropy of the probability distribution
"""
h = -sum([self.distribution[k] * np.log(self.distribution[k]) if self.distribution[k] > 0 else 0 h = -sum([self.distribution[k] * np.log(self.distribution[k]) if self.distribution[k] > 0 else 0
for k in self.bins]) for k in self.bins])
return h return h
def crossentropy(self,q): def crossentropy(self,q):
"""
Cross entropy between the actual probability distribution and the informed one.
:param q: a probabilistic.ProbabilityDistribution object
:return: Cross entropy between this probability distribution and the given distribution
"""
h = -sum([self.distribution[k] * np.log(q.distribution[k]) if self.distribution[k] > 0 else 0 h = -sum([self.distribution[k] * np.log(q.distribution[k]) if self.distribution[k] > 0 else 0
for k in self.bins]) for k in self.bins])
return h return h
def kullbackleiblerdivergence(self,q): def kullbackleiblerdivergence(self,q):
"""
Kullback-Leibler divergence between the actual probability distribution and the informed one.
:param q: a probabilistic.ProbabilityDistribution object
:return: Kullback-Leibler divergence
"""
h = sum([self.distribution[k] * np.log(self.distribution[k]/q.distribution[k]) if self.distribution[k] > 0 else 0 h = sum([self.distribution[k] * np.log(self.distribution[k]/q.distribution[k]) if self.distribution[k] > 0 else 0
for k in self.bins]) for k in self.bins])
return h return h
def empiricalloglikelihood(self): def empiricalloglikelihood(self):
"""
Empirical Log Likelihood of the probability distribution
:return:
"""
_s = 0 _s = 0
for k in self.bins: for k in self.bins:
if self.distribution[k] > 0: if self.distribution[k] > 0:
@ -198,6 +265,12 @@ class ProbabilityDistribution(object):
return _s return _s
def pseudologlikelihood(self, data): def pseudologlikelihood(self, data):
"""
Pseudo log likelihood of the probability distribution with respect to data
:param data:
:return:
"""
densities = self.density(data) densities = self.density(data)
@ -208,6 +281,12 @@ class ProbabilityDistribution(object):
return _s return _s
def averageloglikelihood(self, data): def averageloglikelihood(self, data):
"""
Average log likelihood of the probability distribution with respect to data
:param data:
:return:
"""
densities = self.density(data) densities = self.density(data)

View File

@ -18,6 +18,12 @@ class KernelSmoothing(object):
self.transf = Transformations.Scale(min=0,max=1) self.transf = Transformations.Scale(min=0,max=1)
def kernel_function(self, u): def kernel_function(self, u):
"""
Apply the kernel
:param u:
:return:
"""
if self.kernel == "epanechnikov": if self.kernel == "epanechnikov":
tmp = (3/4)*(1.0 - u**2) tmp = (3/4)*(1.0 - u**2)
return tmp if tmp > 0 else 0 return tmp if tmp > 0 else 0