]> git.parisson.com Git - timeside.git/commitdiff
Fix PEP8 on timeside.analyzer with autopep8
authorThomas Fillon <thomas@parisson.com>
Tue, 22 Apr 2014 13:23:41 +0000 (15:23 +0200)
committerThomas Fillon <thomas@parisson.com>
Tue, 22 Apr 2014 13:23:41 +0000 (15:23 +0200)
18 files changed:
timeside/analyzer/aubio_melenergy.py
timeside/analyzer/aubio_mfcc.py
timeside/analyzer/aubio_pitch.py
timeside/analyzer/aubio_specdesc.py
timeside/analyzer/aubio_temporal.py
timeside/analyzer/core.py
timeside/analyzer/dc.py
timeside/analyzer/irit_speech_4hz.py
timeside/analyzer/irit_speech_entropy.py
timeside/analyzer/level.py
timeside/analyzer/limsi_sad.py
timeside/analyzer/odf.py
timeside/analyzer/preprocessors.py
timeside/analyzer/spectrogram.py
timeside/analyzer/utils.py
timeside/analyzer/vamp_plugin.py
timeside/analyzer/waveform.py
timeside/analyzer/yaafe.py

index 9941fca76e2eefffce5835d0082d426d94dea43e..8bb8616cf4bdae1944706c5775f63de79ef1dc50 100644 (file)
@@ -29,6 +29,7 @@ from aubio import filterbank, pvoc
 
 
 class AubioMelEnergy(Analyzer):
+
     """Aubio Mel Energy analyzer"""
     implements(IAnalyzer)
 
index 6579c3a9ff2d0d9bb90aeb660e13d0bcfd25e87d..36bc2083350274aae4b18669df84d9ed1350b223 100644 (file)
@@ -29,6 +29,7 @@ from aubio import mfcc, pvoc
 
 
 class AubioMfcc(Analyzer):
+
     """Aubio MFCC analyzer"""
     implements(IAnalyzer)
 
index 6769445a47bf534b28763c00b9896352708fcf0c..4e1c7645ce2ba1c659863f4907adbac77cb1ae31 100644 (file)
@@ -26,7 +26,9 @@ from preprocessors import downmix_to_mono, frames_adapter
 from aubio import pitch
 import numpy as np
 
+
 class AubioPitch(Analyzer):
+
     """Aubio Pitch estimation analyzer"""
     implements(IAnalyzer)  # TODO check if needed with inheritance
 
@@ -42,8 +44,9 @@ class AubioPitch(Analyzer):
                                       samplerate,
                                       blocksize,
                                       totalframes)
-        self.aubio_pitch = pitch("default", self.input_blocksize, self.input_stepsize,
-                       samplerate)
+        self.aubio_pitch = pitch(
+            "default", self.input_blocksize, self.input_stepsize,
+            samplerate)
         self.aubio_pitch.set_unit("freq")
         self.block_read = 0
         self.pitches = []
@@ -72,7 +75,8 @@ class AubioPitch(Analyzer):
     def process(self, frames, eod=False):
         #time = self.block_read * self.input_stepsize * 1. / self.samplerate()
         self.pitches += [self.aubio_pitch(frames)[0]]
-        self.pitch_confidences += [np.nan_to_num(self.aubio_pitch.get_confidence())]
+        self.pitch_confidences += [
+            np.nan_to_num(self.aubio_pitch.get_confidence())]
         self.block_read += 1
         return frames, eod
 
@@ -88,7 +92,8 @@ class AubioPitch(Analyzer):
         pitch.data_object.value = self.pitches
         self.process_pipe.results.add(pitch)
 
-        pitch_confidence = self.new_result(data_mode='value', time_mode='framewise')
+        pitch_confidence = self.new_result(
+            data_mode='value', time_mode='framewise')
         pitch_confidence.id_metadata.id += '.' + "pitch_confidence"
         pitch_confidence.id_metadata.name += ' ' + "pitch confidence"
         pitch_confidence.id_metadata.unit = None
index 94fbbe722559b2f4faf339addb67aca1e8a7ea4d..cc19fb69b4cdac0b50d929004c92c09fa8a9f46d 100644 (file)
@@ -28,6 +28,7 @@ from aubio import specdesc, pvoc
 
 
 class AubioSpecdesc(Analyzer):
+
     """Aubio Spectral Descriptors collection analyzer"""
     implements(IAnalyzer)
 
index 4ada85929008ac04348e62a2d48b862c307dbec0..f4be03f107c9b7acc40c61216016e0703a5f18dc 100644 (file)
@@ -29,6 +29,7 @@ import numpy
 
 
 class AubioTemporal(Analyzer):
+
     """Aubio Temporal analyzer"""
     implements(IAnalyzer)
 
@@ -72,7 +73,6 @@ class AubioTemporal(Analyzer):
     def __str__(self):
         return "%s %s" % (str(self.value), self.unit())
 
-
     @downmix_to_mono
     @frames_adapter
     def process(self, frames, eod=False):
@@ -134,7 +134,8 @@ class AubioTemporal(Analyzer):
         #---------------------------------
         #  Beat confidences: Event (time, value)
         #---------------------------------
-        beat_confidences = self.new_result(data_mode='value', time_mode='event')
+        beat_confidences = self.new_result(
+            data_mode='value', time_mode='event')
         beat_confidences.id_metadata.id += '.' + "beat_confidence"
         beat_confidences.id_metadata.name += " " + "Beat confidences"
         beat_confidences.id_metadata.unit = None
index 32e33dcc7701a94867909f9127ea22bda64c3990..384be373f3ecb5c91bae7dd3440986cd0dccd86d 100644 (file)
@@ -25,7 +25,7 @@
 from __future__ import division
 
 from timeside.core import Processor
-import timeside #import __version__
+import timeside  # import __version__
 import numpy
 from collections import OrderedDict
 import h5py
@@ -440,7 +440,8 @@ class DataObject(MetadataObject):
                     maxshape = None
                 else:
                     maxshape = (None,)
-                h5group.create_dataset(key, data=self.__getattribute__(key), maxshape = maxshape)
+                h5group.create_dataset(
+                    key, data=self.__getattribute__(key), maxshape=maxshape)
 
     def from_hdf5(self, h5group):
         for key, dataset in h5group.items():
@@ -823,11 +824,13 @@ class GlobalLabelResult(LabelObject, GlobalObject, AnalyzerResult):
 
 
 class FrameValueResult(ValueObject, FramewiseObject, AnalyzerResult):
+
     def _render_plot(self, ax):
         ax.plot(self.time, self.data)
 
 
 class FrameLabelResult(LabelObject, FramewiseObject, AnalyzerResult):
+
     def _render_plot(self, ax):
         pass
 
@@ -841,6 +844,7 @@ class EventLabelResult(LabelObject, EventObject, AnalyzerResult):
 
 
 class SegmentValueResult(ValueObject, SegmentObject, AnalyzerResult):
+
     def _render_plot(self, ax):
         for time, value in (self.time, self.data):
             ax.axvline(time, ymin=0, ymax=value, color='r')
@@ -848,6 +852,7 @@ class SegmentValueResult(ValueObject, SegmentObject, AnalyzerResult):
 
 
 class SegmentLabelResult(LabelObject, SegmentObject, AnalyzerResult):
+
     def _render_plot(self, ax):
         import itertools
         colors = itertools.cycle(['b', 'g', 'r', 'c', 'm', 'y', 'k'])
@@ -855,7 +860,7 @@ class SegmentLabelResult(LabelObject, SegmentObject, AnalyzerResult):
         for key in self.label_metadata.label.keys():
             ax_color[key] = colors.next()
         for time, duration, label in zip(self.time, self.duration, self.data):
-            ax.axvspan(time, time+duration, color=ax_color[label], alpha=0.3)
+            ax.axvspan(time, time + duration, color=ax_color[label], alpha=0.3)
 
 
 class AnalyzerResultContainer(dict):
index 6cf662fd57aaece6988c1a5bb6c49d75bc88b028..c7c11ff9815c92f069f77fae08d199459ed5db7b 100644 (file)
@@ -26,6 +26,7 @@ import numpy
 
 
 class MeanDCShift(Analyzer):
+
     """Mean DC shift analyzer"""
     implements(IValueAnalyzer)
 
index c04e43885a161836d444d4fe64da83a7e415d53a..916e55dc5b361e2074d98ff85385d11d7e480ea4 100644 (file)
@@ -30,6 +30,7 @@ from scipy.signal import firwin, lfilter
 
 
 class IRITSpeech4Hz(Analyzer):
+
     '''Speech Segmentor based on the 4Hz energy modulation analysis.
 
     Properties:
@@ -157,7 +158,7 @@ class IRITSpeech4Hz(Analyzer):
         segs.data_object.time = [(float(s[0]) * self.blocksize() /
                                  self.samplerate())
                                  for s in segList]
-        segs.data_object.duration = [(float(s[1]-s[0]+1) * self.blocksize() /
+        segs.data_object.duration = [(float(s[1] - s[0] + 1) * self.blocksize() /
                                      self.samplerate())
                                      for s in segList]
 
index d8eb0453092552b27a55f8e1c8262b3658662f5f..febf1a4ddab24eb4a73ac741cefcc80a1488fa83 100644 (file)
@@ -29,6 +29,7 @@ from scipy.ndimage.morphology import binary_opening
 
 
 class IRITSpeechEntropy(Analyzer):
+
     """Speech Segmentor based on Entropy analysis."""
 
     implements(IAnalyzer)
@@ -100,7 +101,7 @@ class IRITSpeechEntropy(Analyzer):
         segs.data_object.time = [(float(s[0]) * self.blocksize() /
                                  self.samplerate())
                                  for s in segList]
-        segs.data_object.duration = [(float(s[1]-s[0]+1) * self.blocksize() /
+        segs.data_object.duration = [(float(s[1] - s[0] + 1) * self.blocksize() /
                                      self.samplerate())
                                      for s in segList]
 
index 540cd2fb5d0b27eec672bfc55dd1f4be9f43a647..574f26d726cf80c0dea1f0da0e80b6e82f845802 100644 (file)
@@ -26,7 +26,9 @@ from timeside.api import IValueAnalyzer
 import numpy as np
 from .utils import MACHINE_EPSILON
 
+
 class Level(Analyzer):
+
     """RMS level analyzer"""
     implements(IValueAnalyzer)
 
@@ -75,7 +77,8 @@ class Level(Analyzer):
         if self.max_value == 0:  # Prevent np.log10(0) = Inf
             self.max_value = MACHINE_EPSILON
 
-        max_level.data_object.value = np.round(20*np.log10(self.max_value), 3)
+        max_level.data_object.value = np.round(
+            20 * np.log10(self.max_value), 3)
         self.process_pipe.results.add(max_level)
 
         # RMS level
@@ -88,5 +91,5 @@ class Level(Analyzer):
         if rms_val == 0:
             rms_val = MACHINE_EPSILON
 
-        rms_level.data_object.value = np.round(20*np.log10(rms_val), 3)
+        rms_level.data_object.value = np.round(20 * np.log10(rms_val), 3)
         self.process_pipe.results.add(rms_level)
index 5a5afa03a12c11f54a33ab06a658496c83795375..294d9533b3aa349725135bd03386d504413212c5 100644 (file)
@@ -46,12 +46,13 @@ class GMM:
                       - 2 * N.dot(x, (self.means / self.vars).T)
                       + N.dot(x ** 2, (1.0 / self.vars).T))
         + N.log(self.weights)
-        m = N.amax(llh,1)
+        m = N.amax(llh, 1)
         dif = llh - N.atleast_2d(m).T
-        return m + N.log(N.sum(N.exp(dif),1))
+        return m + N.log(N.sum(N.exp(dif), 1))
 
 
 class LimsiSad(Analyzer):
+
     """
     Limsi Speech Activity Detection Systems
     LimsiSad performs frame level speech activity detection based on GMM models
@@ -63,7 +64,6 @@ class LimsiSad(Analyzer):
     """
     implements(IAnalyzer)
 
-
     def __init__(self, sad_model='etape'):
         """
         Parameters:
@@ -77,9 +77,12 @@ class LimsiSad(Analyzer):
 
         # feature extraction defition
         spec = yaafelib.FeaturePlan(sample_rate=16000)
-        spec.addFeature('mfcc: MFCC CepsIgnoreFirstCoeff=0 blockSize=1024 stepSize=256')
-        spec.addFeature('mfccd1: MFCC CepsIgnoreFirstCoeff=0 blockSize=1024 stepSize=256 > Derivate DOrder=1')
-        spec.addFeature('mfccd2: MFCC CepsIgnoreFirstCoeff=0 blockSize=1024 stepSize=256 > Derivate DOrder=2')
+        spec.addFeature(
+            'mfcc: MFCC CepsIgnoreFirstCoeff=0 blockSize=1024 stepSize=256')
+        spec.addFeature(
+            'mfccd1: MFCC CepsIgnoreFirstCoeff=0 blockSize=1024 stepSize=256 > Derivate DOrder=1')
+        spec.addFeature(
+            'mfccd2: MFCC CepsIgnoreFirstCoeff=0 blockSize=1024 stepSize=256 > Derivate DOrder=2')
         spec.addFeature('zcr: ZCR blockSize=1024 stepSize=256')
         parent_analyzer = Yaafe(spec)
         self.parents.append(parent_analyzer)
@@ -92,11 +95,12 @@ class LimsiSad(Analyzer):
 
         # load gmm model
         if sad_model not in ['etape', 'maya']:
-            raise ValueError("argument sad_model %s not supported. Supported values are 'etape' or 'maya'" % sad_model)
-        picfname = os.path.join(timeside.__path__[0], 'trained_models', 'limsi_sad_%s.pkl' % sad_model)
+            raise ValueError(
+                "argument sad_model %s not supported. Supported values are 'etape' or 'maya'" % sad_model)
+        picfname = os.path.join(
+            timeside.__path__[0], 'trained_models', 'limsi_sad_%s.pkl' % sad_model)
         self.gmms = pickle.load(open(picfname, 'rb'))
 
-
     @staticmethod
     @interfacedoc
     def id():
@@ -115,22 +119,27 @@ class LimsiSad(Analyzer):
 
     def process(self, frames, eod=False):
         if self.input_samplerate != 16000:
-            raise Exception('%s requires 16000 input sample rate: %d provided' % (self.__class__.__name__, self.input_samplerate))
+            raise Exception(
+                '%s requires 16000 input sample rate: %d provided' %
+                (self.__class__.__name__, self.input_samplerate))
         return frames, eod
 
     def post_process(self):
         mfcc = self.process_pipe.results['yaafe.mfcc']['data_object']['value']
-        mfccd1 = self.process_pipe.results['yaafe.mfccd1']['data_object']['value']
-        mfccd2 = self.process_pipe.results['yaafe.mfccd2']['data_object']['value']
+        mfccd1 = self.process_pipe.results[
+            'yaafe.mfccd1']['data_object']['value']
+        mfccd2 = self.process_pipe.results[
+            'yaafe.mfccd2']['data_object']['value']
         zcr = self.process_pipe.results['yaafe.zcr']['data_object']['value']
 
         features = N.concatenate((mfcc, mfccd1, mfccd2, zcr), axis=1)
 
-        res = 0.5 + 0.5 * (self.gmms[0].llh(features) - self.gmms[1].llh(features))
+        res = 0.5 + 0.5 * \
+            (self.gmms[0].llh(features) - self.gmms[1].llh(features))
 
         sad_result = self.new_result(data_mode='value', time_mode='framewise')
         sad_result.id_metadata.id += '.' + 'sad_lhh_diff'
-        sad_result.id_metadata.name += ' ' + 'Speech Activity Detection Log Likelihood Difference'
+        sad_result.id_metadata.name += ' ' + \
+            'Speech Activity Detection Log Likelihood Difference'
         sad_result.data_object.value = res
         self.process_pipe.results.add(sad_result)
-
index c30244541dffd8c9d334920e8675d810a79596f5..75520eda58031fa1e25b2ec9536aca6e162a8ae9 100644 (file)
@@ -29,6 +29,7 @@ from scipy import signal
 
 
 class OnsetDetectionFunction(Analyzer):
+
     """Onset Detection Function analyzer"""
     implements(IAnalyzer)
 
@@ -77,12 +78,10 @@ class OnsetDetectionFunction(Analyzer):
         # Low-pass filtering of the spectrogram amplitude along the time axis
         S = signal.lfilter(signal.hann(15)[8:], 1, abs(spectrogram), axis=0)
 
-
         import matplotlib.pyplot as plt
 #        plt.figure()
 #        plt.imshow(np.log10(abs(spectrogram)), origin='lower', aspect='auto', interpolation='nearest')
 
-
         # Clip small value to a minimal threshold
         np.maximum(S, 1e-9, out=S)
 
index 324f7732f1c374afc6aa48b2221ade79e8bdb759..51f89c150b283dfa0ff838cddbd543ed13907594 100644 (file)
@@ -28,6 +28,7 @@
             of the analyzer
 '''
 
+
 def downmix_to_mono(process_func):
     '''
     Pre-processing decorator that downmixes frames from multi-channel to mono
@@ -160,8 +161,8 @@ def frames_adapter(process_func):
             if eod and len(eod_list):
                 eod_list[-1] = eod
 
-            for index, eod in zip(xrange(0, nb_frames*self.stepsize, self.stepsize), eod_list):
-                yield (stack[index:index + self.blocksize],eod)
+            for index, eod in zip(xrange(0, nb_frames * self.stepsize, self.stepsize), eod_list):
+                yield (stack[index:index + self.blocksize], eod)
 
     @functools.wraps(process_func)
     def wrapper(analyzer, frames, eod):
index 237b2ac4c71d4b69d86f84058c3d8823aa3ca05a..ee708624c90fe83d6d215219b6b0b83dd8a7f858 100644 (file)
@@ -27,6 +27,7 @@ import numpy as np
 
 
 class Spectrogram(Analyzer):
+
     """Spectrogram analyzer"""
     implements(IAnalyzer)
 
@@ -50,7 +51,7 @@ class Spectrogram(Analyzer):
     def setup(self, channels=None, samplerate=None,
               blocksize=None, totalframes=None):
         super(Spectrogram, self).setup(channels, samplerate,
-              blocksize, totalframes)
+                                       blocksize, totalframes)
 
     @staticmethod
     @interfacedoc
index 6b033068ce7fa2d5a5f885dd3a70bdb1310e0e85..497126d8084e855e80e1a1258ea0d51e4ce37d50 100644 (file)
@@ -23,16 +23,19 @@ import numpy as np
 
 MACHINE_EPSILON = np.finfo(np.float32).eps
 
+
 def downsample_blocking(frames, hop_s, dtype='float32'):
     # downmixing to one channel
     if len(frames.shape) != 1:
-        downsampled = frames.sum(axis = -1) / frames.shape[-1]
+        downsampled = frames.sum(axis=-1) / frames.shape[-1]
     else:
         downsampled = frames
     # zero padding to have a multiple of hop_s
     if downsampled.shape[0] % hop_s != 0:
-        pad_length = hop_s + downsampled.shape[0] / hop_s * hop_s - downsampled.shape[0]
-        downsampled = np.hstack([downsampled, np.zeros(pad_length, dtype = dtype)])
+        pad_length = hop_s + \
+            downsampled.shape[0] / hop_s * hop_s - downsampled.shape[0]
+        downsampled = np.hstack(
+            [downsampled, np.zeros(pad_length, dtype=dtype)])
     # blocking
     return downsampled.reshape(downsampled.shape[0] / hop_s, hop_s)
 
@@ -53,11 +56,11 @@ def computeModulation(serie, wLen, withLog=True):
         '''
         sLen = len(serie)
         modul = np.zeros((sLen,))
-        w = int(wLen/2)
+        w = int(wLen / 2)
 
-        for i in range(w, sLen-w):
+        for i in range(w, sLen - w):
 
-            d = serie[i-w:i+w]
+            d = serie[i - w:i + w]
             if withLog:
                 if not (d > 0).all():
                     d[d <= 0] = MACHINE_EPSILON  # prevent log(0)=inf
@@ -66,7 +69,7 @@ def computeModulation(serie, wLen, withLog=True):
             modul[i] = np.var(d)
 
         modul[:w] = modul[w]
-        modul[-w:] = modul[-w-1]
+        modul[-w:] = modul[-w - 1]
 
         return modul
 
@@ -76,16 +79,16 @@ def segmentFromValues(values, offset=0):
 
     '''
 
-    seg = [offset,-1,values[0]]
+    seg = [offset, -1, values[0]]
     segList = []
-    for i,v in enumerate(values) :
+    for i, v in enumerate(values):
 
-        if not (v == seg[2]) :
-            seg[1] = i+offset-1
+        if not (v == seg[2]):
+            seg[1] = i + offset - 1
             segList.append(tuple(seg))
-            seg = [i+offset,-1,v]
+            seg = [i + offset, -1, v]
 
-    seg[1] = i+offset
+    seg[1] = i + offset
     segList.append(tuple(seg))
 
     return segList
@@ -97,7 +100,7 @@ def segmentFromValues(values, offset=0):
 # Double emploi avec le calcul mfcc d'aubio. Voir pour la fusion...
 #                         Maxime
 
-def melFilterBank(nbFilters,fftLen,sr) :
+def melFilterBank(nbFilters, fftLen, sr):
     '''
     Grenerate a Mel Filter-Bank
 
@@ -111,33 +114,33 @@ def melFilterBank(nbFilters,fftLen,sr) :
                         (Use numpy *dot* function).
     '''
 
-    fh = float(sr)/2.0
-    mh = 2595*np.log10(1+fh/700)
+    fh = float(sr) / 2.0
+    mh = 2595 * np.log10(1 + fh / 700)
 
-    step = mh/nbFilters;
+    step = mh / nbFilters
 
-    mcenter = np.arange(step,mh,step)
+    mcenter = np.arange(step, mh, step)
 
-    fcenter = 700*(10**(mcenter/2595)-1)
+    fcenter = 700 * (10 ** (mcenter / 2595) - 1)
 
-    filterbank = np.zeros((fftLen,nbFilters));
+    filterbank = np.zeros((fftLen, nbFilters))
 
-    for i,_ in enumerate(fcenter) :
+    for i, _ in enumerate(fcenter):
 
-        if i == 0 :
+        if i == 0:
             fmin = 0.0
-        else :
-            fmin = fcenter[i-1]
+        else:
+            fmin = fcenter[i - 1]
 
-        if i == len(fcenter)-1 :
+        if i == len(fcenter) - 1:
             fmax = fh
-        else :
-            fmax = fcenter[i+1]
+        else:
+            fmax = fcenter[i + 1]
 
-        imin = np.ceil(fmin/fh*fftLen)
-        imax = np.ceil(fmax/fh*fftLen)
+        imin = np.ceil(fmin / fh * fftLen)
+        imax = np.ceil(fmax / fh * fftLen)
 
-        filterbank[imin:imax,i] = triangle(imax-imin)
+        filterbank[imin:imax, i] = triangle(imax - imin)
 
     return filterbank
 
@@ -152,15 +155,15 @@ def triangle(length):
         - triangle : triangle filter.
 
     '''
-    triangle = np.zeros((1,length))[0]
-    climax= np.ceil(length/2)
+    triangle = np.zeros((1, length))[0]
+    climax = np.ceil(length / 2)
 
-    triangle[0:climax] = np.linspace(0,1,climax)
-    triangle[climax:length] = np.linspace(1,0,length-climax)
+    triangle[0:climax] = np.linspace(0, 1, climax)
+    triangle[climax:length] = np.linspace(1, 0, length - climax)
     return triangle
 
 
-def entropy(serie,nbins=10,base=np.exp(1),approach='unbiased'):
+def entropy(serie, nbins=10, base=np.exp(1), approach='unbiased'):
         '''
         Compute entropy of a serie using the histogram method.
 
@@ -184,41 +187,39 @@ def entropy(serie,nbins=10,base=np.exp(1),approach='unbiased'):
 
         estimate = 0
         sigma = 0
-        bins,edges = np.histogram(serie,nbins);
+        bins, edges = np.histogram(serie, nbins)
         ncell = len(bins)
-        norm = (np.max(edges)-np.min(edges))/len(bins)
-
+        norm = (np.max(edges) - np.min(edges)) / len(bins)
 
-        for b in bins :
-            if b == 0 :
+        for b in bins:
+            if b == 0:
                 logf = 0
-            else :
+            else:
                 logf = np.log(b)
-            estimate = estimate - b*logf
-            sigma = sigma + b * logf**2
+            estimate = estimate - b * logf
+            sigma = sigma + b * logf ** 2
 
         count = np.sum(bins)
-        estimate=estimate/count;
-        sigma=np.sqrt( (sigma/count-estimate**2)/float(count-1) );
-        estimate=estimate+np.log(count)+np.log(norm);
-        nbias=-(ncell-1)/(2*count);
-
-        if approach =='unbiased' :
-            estimate=estimate-nbias;
-            nbias=0;
-
-        elif approach =='mmse' :
-            estimate=estimate-nbias;
-            nbias=0;
-            lambda_value=estimate^2/(estimate^2+sigma^2);
-            nbias   =(1-lambda_value)*estimate;
-            estimate=lambda_value*estimate;
-            sigma   =lambda_value*sigma;
-        else :
+        estimate = estimate / count
+        sigma = np.sqrt((sigma / count - estimate ** 2) / float(count - 1))
+        estimate = estimate + np.log(count) + np.log(norm)
+        nbias = -(ncell - 1) / (2 * count)
+
+        if approach == 'unbiased':
+            estimate = estimate - nbias
+            nbias = 0
+
+        elif approach == 'mmse':
+            estimate = estimate - nbias
+            nbias = 0
+            lambda_value = estimate ^ 2 / (estimate ^ 2 + sigma ^ 2)
+            nbias = (1 - lambda_value) * estimate
+            estimate = lambda_value * estimate
+            sigma = lambda_value * sigma
+        else:
             return 0
 
-        estimate=estimate/np.log(base);
-        nbias   =nbias   /np.log(base);
-        sigma   =sigma   /np.log(base);
+        estimate = estimate / np.log(base)
+        nbias = nbias / np.log(base)
+        sigma = sigma / np.log(base)
         return estimate
-
index 88f3ef0793dc25e2a373c0e072ccdae15e80fd7a..0ce4ed1dd54929679a23dc6a22e5f79bfc4335aa 100644 (file)
@@ -28,6 +28,7 @@ import numpy as np
 
 
 class VampSimpleHost(Analyzer):
+
     """Vamp plugins library interface analyzer"""
 
     implements(IAnalyzer)
@@ -78,16 +79,17 @@ class VampSimpleHost(Analyzer):
                 return
 
             if duration is not None:
-                plugin_res = self.new_result(data_mode='value', time_mode='segment')
+                plugin_res = self.new_result(
+                    data_mode='value', time_mode='segment')
                 plugin_res.data_object.duration = duration
             else:
-                plugin_res = self.new_result(data_mode='value', time_mode='event')
+                plugin_res = self.new_result(
+                    data_mode='value', time_mode='event')
 
             plugin_res.data_object.time = time
             plugin_res.data_object.value = value
 
-
-#            # Fix strat, duration issues if audio is a segment
+# Fix strat, duration issues if audio is a segment
 #            if self.mediainfo()['is_segment']:
 #                start_index = np.floor(self.mediainfo()['start'] *
 #                                       self.result_samplerate /
@@ -107,7 +109,6 @@ class VampSimpleHost(Analyzer):
 #                plugin_res.audio_metadata.duration = fixed_duration
 #
 #                value = value[start_index:stop_index + 1]
-
             plugin_res.id_metadata.id += '.' + '.'.join(plugin_line[1:])
             plugin_res.id_metadata.name += ' ' + \
                 ' '.join(plugin_line[1:])
@@ -139,7 +140,8 @@ class VampSimpleHost(Analyzer):
         stepsize = int(m.groups()[1])
         # Get the results
 
-        value = np.asfarray([line.split(': ')[1].split(' ') for line in res if (len(line.split(': ')) > 1)])
+        value = np.asfarray([line.split(': ')[1].split(' ')
+                            for line in res if (len(line.split(': ')) > 1)])
         time = np.asfarray([r.split(':')[0].split(',')[0] for r in res])
 
         time_len = len(res[0].split(':')[0].split(','))
@@ -148,7 +150,8 @@ class VampSimpleHost(Analyzer):
             duration = None
         elif time_len == 2:
             # segment
-            duration = np.asfarray([r.split(':')[0].split(',')[1] for r in res])
+            duration = np.asfarray(
+                [r.split(':')[0].split(',')[1] for r in res])
 
         return (time, duration, value)
 
index e5eb47822420a02a182682f58ffb0583fa01984c..b5fdbd14e8458ec71f06538f59750356a31e9b6b 100644 (file)
@@ -26,7 +26,9 @@ import numpy as np
 
 from preprocessors import downmix_to_mono, frames_adapter
 
+
 class Waveform(Analyzer):
+
     """Waveform analyzer"""
     implements(IAnalyzer)  # TODO check if needed with inheritance
 
@@ -39,7 +41,7 @@ class Waveform(Analyzer):
     def setup(self, channels=None, samplerate=None,
               blocksize=None, totalframes=None):
         super(Waveform, self).setup(channels, samplerate,
-              blocksize, totalframes)
+                                    blocksize, totalframes)
         self.values = []
         self.result_blocksize = 1
         self.result_stepsize = 1
index 1a3fa2c71b8ff5d14cb5af18419da9ed33ffd56f..7024c464f497cb2e7c7ddb592f0039071e98e2ff 100644 (file)
@@ -35,17 +35,19 @@ from timeside.analyzer.preprocessors import downmix_to_mono
 
 
 class Yaafe(Analyzer):
+
     """Yaafe feature extraction library interface analyzer"""
     implements(IAnalyzer)
 
     def __init__(self, yaafeSpecification=None):
-        super(Yaafe,self).__init__()
+        super(Yaafe, self).__init__()
 
         # Check arguments
         if yaafeSpecification is None:
             yaafeSpecification = FeaturePlan(sample_rate=32000)
             # add feature definitions manually
-            yaafeSpecification.addFeature('mfcc: MFCC blockSize=512 stepSize=256')
+            yaafeSpecification.addFeature(
+                'mfcc: MFCC blockSize=512 stepSize=256')
 
         if isinstance(yaafeSpecification, DataFlow):
             self.dataFlow = yaafeSpecification
@@ -59,7 +61,6 @@ class Yaafe(Analyzer):
                              str(FeaturePlan)))
         self.yaafe_engine = None
 
-
     @interfacedoc
     def setup(self, channels=None, samplerate=None,
               blocksize=None, totalframes=None):
@@ -91,7 +92,7 @@ class Yaafe(Analyzer):
         # do process things...
         # Convert to float64and reshape
         # for compatibility with Yaafe engine
-        yaafe_frames = frames.astype(numpy.float64).reshape(1,-1)
+        yaafe_frames = frames.astype(numpy.float64).reshape(1, -1)
 
         # write audio array on 'audio' input
         self.yaafe_engine.writeInput('audio', yaafe_frames)