Commit f81cab1b authored by Anthony Larcher's avatar Anthony Larcher
Browse files

doc

parent 846b53ec
......@@ -47,6 +47,7 @@ from sidekit.bosaris import Key
from sidekit.bosaris import Scores
from sidekit.bosaris import DetPlot
from sidekit.bosaris import effective_prior
from sidekit.bosaris import logit_effective_prior
from sidekit.bosaris import fast_minDCF
# Import classes
......
......@@ -26,6 +26,7 @@ from sidekit.bosaris.key import Key
from sidekit.bosaris.scores import Scores
from sidekit.bosaris.detplot import DetPlot
from sidekit.bosaris.detplot import effective_prior
from sidekit.bosaris.detplot import logit_effective_prior
from sidekit.bosaris.detplot import fast_minDCF
......
......@@ -109,6 +109,28 @@ def effective_prior(Ptar, cmiss, cfa):
p = Ptar * cmiss / (Ptar * cmiss + (1 - Ptar) * cfa)
return p
def logit_effective_prior(Ptar, cmiss, cfa):
"""This function adjusts a given prior probability of target p_targ,
to incorporate the effects of a cost of miss,
cmiss, and a cost of false-alarm, cfa.
In particular note:
EFFECTIVE_PRIOR(EFFECTIVE_PRIOR(p,cmiss,cfa),1,1)
= EFFECTIVE_PRIOR(p,cfa,cmiss)
The effective prior for the NIST SRE detection cost fuction,
with p_targ = 0.01, cmiss = 10, cfa = 1 is therefore:
EFFECTIVE_PRIOR(0.01,10,1) = 0.0917
:param Ptar: is the probability of a target trial
:param cmiss: is the cost of a miss
:param cfa: is the cost of a false alarm
:return: a prior
"""
p = Ptar * cmiss / (Ptar * cmiss + (1 - Ptar) * cfa)
return __logit__(p)
def __probit__(p):
"""Map from [0,1] to [-inf,inf] as used to make DET out of a ROC
......
......@@ -216,10 +216,8 @@ class Ndx:
with open(input_filename, 'r') as fid:
lines = [l.rstrip().split() for l in fid]
models = numpy.array([], '|O')
models.resize(len(lines))
testsegs = numpy.array([], '|O')
testsegs.resize(len(lines))
models = numpy.empty(len(lines), '|O')
testsegs = numpy.empty(len(lines), '|O')
for ii in range(len(lines)):
models[ii] = lines[ii][0]
testsegs[ii] = lines[ii][1]
......
......@@ -45,11 +45,14 @@
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
......@@ -301,8 +304,8 @@
<span class="n">feat</span> <span class="o">=</span> <span class="n">feat</span><span class="p">[</span><span class="n">label</span><span class="p">]</span>
<span class="n">label</span> <span class="o">=</span> <span class="n">label</span><span class="p">[</span><span class="n">label</span><span class="p">]</span>
<span class="k">return</span> <span class="n">feat</span><span class="p">,</span> <span class="n">label</span></div>
<span class="k">return</span> <span class="n">feat</span><span class="p">,</span> <span class="n">label</span>
</div>
<span class="k">def</span> <span class="nf">_mask</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cep</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Keep only the MFCC index present in the filter list</span>
......@@ -411,8 +414,8 @@
<span class="k">else</span><span class="p">:</span>
<span class="n">context_label</span> <span class="o">=</span> <span class="bp">None</span>
<span class="k">return</span> <span class="n">context_feat</span><span class="p">,</span> <span class="n">context_label</span></div>
<span class="k">return</span> <span class="n">context_feat</span><span class="p">,</span> <span class="n">context_label</span>
</div>
<div class="viewcode-block" id="FeaturesServer.get_traps"><a class="viewcode-back" href="../featuresserver.html#features_server.FeaturesServer.get_traps">[docs]</a> <span class="k">def</span> <span class="nf">get_traps</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feat</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Compute TRAP parameters. The input frames are concatenated to add their left and right context,</span>
......@@ -451,8 +454,8 @@
<span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span>
<span class="n">context_feat</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">hamming_dct</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
<span class="n">hamming_dct</span>
<span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">context_feat</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="o">-</span><span class="mi">1</span><span class="p">),</span> <span class="n">context_label</span></div>
<span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">context_feat</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="o">-</span><span class="mi">1</span><span class="p">),</span> <span class="n">context_label</span>
</div>
<div class="viewcode-block" id="FeaturesServer.load"><a class="viewcode-back" href="../featuresserver.html#features_server.FeaturesServer.load">[docs]</a> <span class="k">def</span> <span class="nf">load</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">input_feature_filename</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Depending of the setting of the FeaturesServer, can either:</span>
......@@ -505,8 +508,8 @@
<span class="n">channel</span><span class="o">=</span><span class="n">channel</span><span class="p">,</span>
<span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
<span class="n">start</span><span class="o">=</span><span class="n">start</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="n">stop</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">previous_load</span></div>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">previous_load</span>
</div>
<div class="viewcode-block" id="FeaturesServer.get_features"><a class="viewcode-back" href="../featuresserver.html#features_server.FeaturesServer.get_features">[docs]</a> <span class="k">def</span> <span class="nf">get_features</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">input_feature_filename</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Get the datasets from a single HDF5 file</span>
......@@ -585,7 +588,6 @@
<span class="n">label</span> <span class="o">=</span> <span class="n">h5f</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s">&quot;vad&quot;</span><span class="p">)))</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s">&#39;bool&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()[</span><span class="n">start</span><span class="p">:</span><span class="n">stop</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">label</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">feat</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s">&#39;bool&#39;</span><span class="p">)</span>
<span class="c"># Pad the segment if needed</span>
<span class="n">feat</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">pad</span><span class="p">(</span><span class="n">feat</span><span class="p">,</span> <span class="p">((</span><span class="n">pad_begining</span><span class="p">,</span> <span class="n">pad_end</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span> <span class="n">mode</span><span class="o">=</span><span class="s">&#39;edge&#39;</span><span class="p">)</span>
<span class="n">label</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">pad</span><span class="p">(</span><span class="n">label</span><span class="p">,</span> <span class="p">((</span><span class="n">pad_begining</span><span class="p">,</span> <span class="n">pad_end</span><span class="p">)),</span> <span class="n">mode</span><span class="o">=</span><span class="s">&#39;edge&#39;</span><span class="p">)</span>
......@@ -598,8 +600,8 @@
<span class="k">else</span><span class="p">:</span>
<span class="n">feat</span><span class="p">,</span> <span class="n">label</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">post_processing</span><span class="p">(</span><span class="n">feat</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span>
<span class="k">return</span> <span class="n">feat</span><span class="p">,</span> <span class="n">label</span></div>
<span class="k">return</span> <span class="n">feat</span><span class="p">,</span> <span class="n">label</span>
</div>
<div class="viewcode-block" id="FeaturesServer.get_tandem_features"><a class="viewcode-back" href="../featuresserver.html#features_server.FeaturesServer.get_tandem_features">[docs]</a> <span class="k">def</span> <span class="nf">get_tandem_features</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Read acoustic parameters from multiple HDF5 files (from disk or extracted by FeaturesExtractor objects).</span>
......@@ -628,8 +630,8 @@
<span class="n">label</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">feat</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s">&#39;bool&#39;</span><span class="p">)</span>
<span class="c"># Apply the final post-processing on the concatenated features</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">post_processing</span><span class="p">(</span><span class="n">features</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span></div>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">post_processing</span><span class="p">(</span><span class="n">features</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="FeaturesServer.mean_std"><a class="viewcode-back" href="../featuresserver.html#features_server.FeaturesServer.mean_std">[docs]</a> <span class="k">def</span> <span class="nf">mean_std</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Compute the mean and standard deviation vectors for a segment of acoustic features</span>
......@@ -665,7 +667,7 @@
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2014-16, Anthony LARCHER &amp; Sylvain MEIGNIER &amp; Kong Aik LEE.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.4.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.1.
</div>
</body>
</html>
\ No newline at end of file
......@@ -45,11 +45,14 @@
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../../search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
......@@ -117,9 +120,9 @@
<span class="sd"> </span>
<span class="sd"> :return: the equivalence on the mel scale.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="mf">1127.01048</span> <span class="o">*</span> <span class="n">numpy</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">f</span> <span class="o">/</span> <span class="mf">700.0</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span></div>
<span class="k">return</span> <span class="mf">1127.01048</span> <span class="o">*</span> <span class="n">numpy</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">f</span> <span class="o">/</span> <span class="mf">700.0</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="mel2hz"><a class="viewcode-back" href="../../frontend/features.html#frontend.features.mel2hz">[docs]</a><span class="k">def</span> <span class="nf">mel2hz</span><span class="p">(</span><span class="n">m</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Convert an array of mel values in Hz.</span>
<span class="sd"> </span>
......@@ -127,9 +130,9 @@
<span class="sd"> </span>
<span class="sd"> :return: the equivalent values in Hertz.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">m</span> <span class="o">/</span> <span class="mf">1127.01048</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mf">700.0</span></div>
<span class="k">return</span> <span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="n">m</span> <span class="o">/</span> <span class="mf">1127.01048</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mf">700.0</span>
</div>
<div class="viewcode-block" id="compute_delta"><a class="viewcode-back" href="../../frontend/features.html#frontend.features.compute_delta">[docs]</a><span class="k">def</span> <span class="nf">compute_delta</span><span class="p">(</span><span class="n">features</span><span class="p">,</span>
<span class="n">win</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
<span class="n">method</span><span class="o">=</span><span class="s">&#39;filter&#39;</span><span class="p">,</span>
......@@ -163,9 +166,9 @@
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">features</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">]):</span>
<span class="n">delta</span><span class="p">[:,</span> <span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">convolve</span><span class="p">(</span><span class="n">features</span><span class="p">[:,</span> <span class="n">i</span><span class="p">],</span> <span class="n">filt</span><span class="p">)</span>
<span class="k">return</span> <span class="n">delta</span><span class="p">[</span><span class="n">win</span><span class="p">:</span><span class="o">-</span><span class="n">win</span><span class="p">,</span> <span class="p">:]</span></div>
<span class="k">return</span> <span class="n">delta</span><span class="p">[</span><span class="n">win</span><span class="p">:</span><span class="o">-</span><span class="n">win</span><span class="p">,</span> <span class="p">:]</span>
</div>
<div class="viewcode-block" id="pca_dct"><a class="viewcode-back" href="../../frontend/features.html#frontend.features.pca_dct">[docs]</a><span class="k">def</span> <span class="nf">pca_dct</span><span class="p">(</span><span class="n">cep</span><span class="p">,</span> <span class="n">left_ctx</span><span class="o">=</span><span class="mi">12</span><span class="p">,</span> <span class="n">right_ctx</span><span class="o">=</span><span class="mi">12</span><span class="p">,</span> <span class="n">p</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Apply DCT PCA as in [McLaren 2015] paper:</span>
<span class="sd"> Mitchell McLaren and Yun Lei, &#39;Improved Speaker Recognition </span>
......@@ -191,9 +194,9 @@
<span class="k">if</span> <span class="n">p</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
<span class="n">p</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="n">dct_temp</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">*</span> <span class="n">cep</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="n">PARAM_TYPE</span><span class="p">)</span>
<span class="k">return</span> <span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">ceps</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">dct_temp</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
<span class="n">dct_temp</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">ceps</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="o">-</span><span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">p</span><span class="p">)</span></div>
<span class="n">dct_temp</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">ceps</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="o">-</span><span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="shifted_delta_cepstral"><a class="viewcode-back" href="../../frontend/features.html#frontend.features.shifted_delta_cepstral">[docs]</a><span class="k">def</span> <span class="nf">shifted_delta_cepstral</span><span class="p">(</span><span class="n">cep</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">p</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="mi">7</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Compute the Shifted-Delta-Cepstral features for language identification</span>
......@@ -221,9 +224,9 @@
<span class="k">for</span> <span class="n">ff</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">cep</span><span class="p">)):</span>
<span class="n">sdc</span><span class="p">[</span><span class="n">ff</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="n">delta</span><span class="p">[</span><span class="n">idx</span><span class="p">,</span> <span class="p">:]</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
<span class="n">idx</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">roll</span><span class="p">(</span><span class="n">idx</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">hstack</span><span class="p">((</span><span class="n">cep</span><span class="p">,</span> <span class="n">sdc</span><span class="p">))</span></div>
<span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">hstack</span><span class="p">((</span><span class="n">cep</span><span class="p">,</span> <span class="n">sdc</span><span class="p">))</span>
</div>
<div class="viewcode-block" id="trfbank"><a class="viewcode-back" href="../../frontend/features.html#frontend.features.trfbank">[docs]</a><span class="k">def</span> <span class="nf">trfbank</span><span class="p">(</span><span class="n">fs</span><span class="p">,</span> <span class="n">nfft</span><span class="p">,</span> <span class="n">lowfreq</span><span class="p">,</span> <span class="n">maxfreq</span><span class="p">,</span> <span class="n">nlinfilt</span><span class="p">,</span> <span class="n">nlogfilt</span><span class="p">,</span> <span class="n">midfreq</span><span class="o">=</span><span class="mi">1000</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Compute triangular filterbank for cepstral coefficient computation.</span>
......@@ -304,8 +307,8 @@
<span class="n">fbank</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">lid</span><span class="p">]</span> <span class="o">=</span> <span class="n">left_slope</span> <span class="o">*</span> <span class="p">(</span><span class="n">n_frequences</span><span class="p">[</span><span class="n">lid</span><span class="p">]</span> <span class="o">-</span> <span class="n">low</span><span class="p">)</span>
<span class="n">fbank</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">rid</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span> <span class="o">=</span> <span class="n">right_slope</span> <span class="o">*</span> <span class="p">(</span><span class="n">hi</span> <span class="o">-</span> <span class="n">n_frequences</span><span class="p">[</span><span class="n">rid</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
<span class="k">return</span> <span class="n">fbank</span><span class="p">,</span> <span class="n">frequences</span></div>
<span class="k">return</span> <span class="n">fbank</span><span class="p">,</span> <span class="n">frequences</span>
</div>
<div class="viewcode-block" id="mel_filter_bank"><a class="viewcode-back" href="../../frontend/features.html#frontend.features.mel_filter_bank">[docs]</a><span class="k">def</span> <span class="nf">mel_filter_bank</span><span class="p">(</span><span class="n">fs</span><span class="p">,</span> <span class="n">nfft</span><span class="p">,</span> <span class="n">lowfreq</span><span class="p">,</span> <span class="n">maxfreq</span><span class="p">,</span> <span class="n">widest_nlogfilt</span><span class="p">,</span> <span class="n">widest_lowfreq</span><span class="p">,</span> <span class="n">widest_maxfreq</span><span class="p">,):</span>
<span class="sd">&quot;&quot;&quot;Compute triangular filterbank for cepstral coefficient computation.</span>
......@@ -357,9 +360,9 @@
<span class="n">fbank</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">lid</span><span class="p">]</span> <span class="o">=</span> <span class="n">left_slope</span> <span class="o">*</span> <span class="p">(</span><span class="n">nfreqs</span><span class="p">[</span><span class="n">lid</span><span class="p">]</span> <span class="o">-</span> <span class="n">low</span><span class="p">)</span>
<span class="n">fbank</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">rid</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]]</span> <span class="o">=</span> <span class="n">right_slope</span> <span class="o">*</span> <span class="p">(</span><span class="n">hi</span> <span class="o">-</span> <span class="n">nfreqs</span><span class="p">[</span><span class="n">rid</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]])</span>
<span class="k">return</span> <span class="n">fbank</span><span class="p">,</span> <span class="n">sub_band_freqs</span></div>
<span class="k">return</span> <span class="n">fbank</span><span class="p">,</span> <span class="n">sub_band_freqs</span>
</div>
<div class="viewcode-block" id="mfcc"><a class="viewcode-back" href="../../frontend/features.html#frontend.features.mfcc">[docs]</a><span class="k">def</span> <span class="nf">mfcc</span><span class="p">(</span><span class="n">input_sig</span><span class="p">,</span>
<span class="n">lowfreq</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">maxfreq</span><span class="o">=</span><span class="mi">8000</span><span class="p">,</span>
<span class="n">nlinfilt</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">nlogfilt</span><span class="o">=</span><span class="mi">24</span><span class="p">,</span>
......@@ -455,9 +458,9 @@
<span class="n">lst</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span>
<span class="k">del</span> <span class="n">mspec</span>
<span class="k">return</span> <span class="n">lst</span></div>
<span class="k">return</span> <span class="n">lst</span>
</div>
<div class="viewcode-block" id="framing"><a class="viewcode-back" href="../../frontend/features.html#frontend.features.framing">[docs]</a><span class="k">def</span> <span class="nf">framing</span><span class="p">(</span><span class="n">sig</span><span class="p">,</span> <span class="n">win_size</span><span class="p">,</span> <span class="n">win_shift</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">context</span><span class="o">=</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">pad</span><span class="o">=</span><span class="s">&#39;zeros&#39;</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> :param sig: input signal, can be mono or multi dimensional</span>
......@@ -481,9 +484,9 @@
<span class="k">elif</span> <span class="n">pad</span> <span class="o">==</span> <span class="s">&#39;edge&#39;</span><span class="p">:</span>
<span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">lib</span><span class="o">.</span><span class="n">stride_tricks</span><span class="o">.</span><span class="n">as_strided</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">lib</span><span class="o">.</span><span class="n">pad</span><span class="p">(</span><span class="n">sig</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="s">&#39;edge&#39;</span><span class="p">),</span>
<span class="n">shape</span><span class="o">=</span><span class="n">shape</span><span class="p">,</span>
<span class="n">strides</span><span class="o">=</span><span class="n">strides</span><span class="p">)</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span></div>
<span class="n">strides</span><span class="o">=</span><span class="n">strides</span><span class="p">)</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()</span>
</div>
<div class="viewcode-block" id="dct_basis"><a class="viewcode-back" href="../../frontend/features.html#frontend.features.dct_basis">[docs]</a><span class="k">def</span> <span class="nf">dct_basis</span><span class="p">(</span><span class="n">nbasis</span><span class="p">,</span> <span class="n">length</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> :param nbasis: number of CT coefficients to keep</span>
......@@ -513,7 +516,7 @@
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2014-16, Anthony LARCHER &amp; Sylvain MEIGNIER &amp; Kong Aik LEE.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.4.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.1.
</div>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
......@@ -45,11 +45,14 @@
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../../search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
......@@ -91,7 +94,7 @@
<span class="sd">useful parameters for speaker verification.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">numpy</span>
<span class="kn">import</span> <span class="nn">pandas</span>
<span class="c">#import pandas</span>
<span class="kn">import</span> <span class="nn">scipy.stats</span> <span class="kn">as</span> <span class="nn">stats</span>
<span class="kn">from</span> <span class="nn">scipy.signal</span> <span class="kn">import</span> <span class="n">lfilter</span>
......@@ -134,9 +137,9 @@
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">y</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
<span class="n">y</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="mi">4</span><span class="p">:]</span> <span class="o">=</span> <span class="n">lfilter</span><span class="p">(</span><span class="n">numerator</span><span class="p">,</span> <span class="n">denominator</span><span class="p">,</span> <span class="n">x</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="mi">4</span><span class="p">:],</span> <span class="n">axis</span><span class="o">=-</span><span class="mi">1</span><span class="p">,</span> <span class="n">zi</span><span class="o">=</span><span class="n">zf</span><span class="p">[</span><span class="n">i</span><span class="p">,</span> <span class="p">:])[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">return</span> <span class="n">y</span><span class="o">.</span><span class="n">T</span></div>
<span class="k">return</span> <span class="n">y</span><span class="o">.</span><span class="n">T</span>
</div>
<div class="viewcode-block" id="cms"><a class="viewcode-back" href="../../frontend/normfeat.html#frontend.normfeat.cms">[docs]</a><span class="k">def</span> <span class="nf">cms</span><span class="p">(</span><span class="n">features</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">global_mean</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Performs cepstral mean subtraction</span>
<span class="sd"> </span>
......@@ -156,9 +159,9 @@
<span class="n">mu</span> <span class="o">=</span> <span class="n">global_mean</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">mu</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">features</span><span class="p">[</span><span class="n">label</span><span class="p">,</span> <span class="p">:],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">features</span> <span class="o">-=</span> <span class="n">mu</span></div>
<span class="n">features</span> <span class="o">-=</span> <span class="n">mu</span>
</div>
<div class="viewcode-block" id="cmvn"><a class="viewcode-back" href="../../frontend/normfeat.html#frontend.normfeat.cmvn">[docs]</a><span class="k">def</span> <span class="nf">cmvn</span><span class="p">(</span><span class="n">features</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">global_mean</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">global_std</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Performs mean and variance normalization</span>
<span class="sd"> </span>
......@@ -183,10 +186,10 @@
<span class="n">mu</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="n">features</span><span class="p">[</span><span class="n">label</span><span class="p">,</span> <span class="p">:],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">stdev</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">std</span><span class="p">(</span><span class="n">features</span><span class="p">[</span><span class="n">label</span><span class="p">,</span> <span class="p">:],</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="n">features</span> <span class="o">-=</span> <span class="n">mu</span>
<span class="n">features</span> <span class="o">/=</span> <span class="n">stdev</span></div>
<span class="n">features</span> <span class="o">/=</span> <span class="n">stdev</span>
</div>
<div class="viewcode-block" id="stg"><a class="viewcode-back" href="../../frontend/normfeat.html#frontend.normfeat.stg">[docs]</a><span class="k">def</span> <span class="nf">stg</span><span class="p">(</span><span class="n">features</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">win</span><span class="o">=</span><span class="mi">301</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Performs feature warping on a sliding window</span>
<span class="sd"> </span>
......@@ -248,9 +251,9 @@
<span class="c"># wrapFeatures = np.copy(features)</span>
<span class="k">if</span> <span class="n">add_a_feature</span><span class="p">:</span>
<span class="n">stg_features</span> <span class="o">=</span> <span class="n">stg_features</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="n">features</span><span class="p">[</span><span class="n">label</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="n">stg_features</span></div>
<span class="n">features</span><span class="p">[</span><span class="n">label</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="n">stg_features</span>
</div>
<div class="viewcode-block" id="cep_sliding_norm"><a class="viewcode-back" href="../../frontend/normfeat.html#frontend.normfeat.cep_sliding_norm">[docs]</a><span class="k">def</span> <span class="nf">cep_sliding_norm</span><span class="p">(</span><span class="n">features</span><span class="p">,</span> <span class="n">win</span><span class="o">=</span><span class="mi">301</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span> <span class="nb">reduce</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Performs a cepstal mean substitution and standard deviation normalization</span>
......@@ -274,7 +277,7 @@
<span class="k">else</span><span class="p">:</span>
<span class="n">d_win</span> <span class="o">=</span> <span class="n">win</span> <span class="o">//</span> <span class="mi">2</span>
<span class="n">df</span> <span class="o">=</span> <span class="n">pandas</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">features</span><span class="p">[</span><span class="n">label</span><span class="p">,</span> <span class="p">:])</span>
<span class="c">#df = pandas.DataFrame(features[label, :])</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">df</span><span class="o">.</span><span class="n">rolling</span><span class="p">(</span><span class="n">window</span><span class="o">=</span><span class="n">win</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
<span class="n">mean</span> <span class="o">=</span> <span class="n">r</span><span class="o">.</span><span class="n">mean</span><span class="p">()</span><span class="o">.</span><span class="n">values</span>
<span class="n">std</span> <span class="o">=</span> <span class="n">r</span><span class="o">.</span><span class="n">std</span><span class="p">()</span><span class="o">.</span><span class="n">values</span>
......@@ -311,7 +314,7 @@
</div>
<div class="footer" role="contentinfo">
&copy; Copyright 2014-16, Anthony LARCHER &amp; Sylvain MEIGNIER &amp; Kong Aik LEE.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.4.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.1.
</div>
</body>
</html>
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment