Ignore:
Timestamp:
Feb 20, 2006, 12:37:53 PM (19 years ago)
Author:
Paul Brossier <piem@altern.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
a7880d9
Parents:
79c04d8
Message:

added bench-window, bench-delay, benchonset
added bench-window, bench-delay, benchonset

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/test/bench/onset/bench-onset

    r79c04d8 r83c6734  
    11#! /usr/bin/python
    22
    3 from aubio.bench.node import *
    43from aubio.tasks import *
    54
     5from benchonset import mmean, stdev, benchonset
    66
    7 
    8 
    9 def mmean(l):
    10         return sum(l)/float(len(l))
    11 
    12 def stdev(l):
    13         smean = 0
    14         lmean = mmean(l)
    15         for i in l:
    16                 smean += (i-lmean)**2
    17         smean *= 1. / len(l)
    18         return smean**.5
    19 
    20 class benchonset(bench):
    21 
    22         """ list of values to store per file """
    23         valuenames = ['orig','missed','Tm','expc','bad','Td']
    24         """ list of lists to store per file """
    25         valuelists = ['l','labs']
    26         """ list of values to print per dir """
    27         printnames = [ 'mode', 'thres', 'dist', 'prec', 'recl',
    28                 'Ttrue', 'Tfp',  'Tfn',  'Tm',   'Td',
    29                 'aTtrue', 'aTfp', 'aTfn', 'aTm',  'aTd', 
    30                 'mean', 'smean',  'amean', 'samean']
    31 
    32         """ per dir """
    33         formats = {'mode': "%12s" , 'thres': "%5.4s",
    34                 'dist':  "%5.4s", 'prec': "%5.4s", 'recl':  "%5.4s",
    35                 'Ttrue': "%5.4s", 'Tfp':   "%5.4s", 'Tfn':   "%5.4s",
    36                 'Tm':    "%5.4s", 'Td':    "%5.4s",
    37                 'aTtrue':"%5.4s", 'aTfp':  "%5.4s", 'aTfn':  "%5.4s",
    38                 'aTm':   "%5.4s", 'aTd':   "%5.4s",
    39                 'mean':  "%5.40s", 'smean': "%5.40s",
    40                 'amean':  "%5.40s", 'samean': "%5.40s"}
    41 
    42         def dir_eval(self):
    43                 """ evaluate statistical data over the directory """
    44                 totaltrue = sum(self.v['expc'])-sum(self.v['bad'])-sum(self.v['Td'])
    45                 totalfp = sum(self.v['bad'])+sum(self.v['Td'])
    46                 totalfn = sum(self.v['missed'])+sum(self.v['Tm'])
    47                 self.P = 100*float(totaltrue)/max(totaltrue + totalfp,1)
    48                 self.R = 100*float(totaltrue)/max(totaltrue + totalfn,1)
    49                 if self.R < 0: self.R = 0
    50                 self.F = 2.* self.P*self.R / max(float(self.P+self.R),1)
    51                 N = float(len(self.reslist))
    52                 self.v['mode']      = self.params.onsetmode
    53                 self.v['thres']     = self.params.threshold
    54                 self.v['thres']     = "%2.3f" % self.params.threshold
    55                 self.v['dist']      = "%2.3f" % self.F
    56                 self.v['prec']      = "%2.3f" % self.P
    57                 self.v['recl']      = "%2.3f" % self.R
    58                 self.v['Ttrue']     = totaltrue
    59                 self.v['Tfp']       = totalfp
    60                 self.v['Tfn']       = totalfn
    61                 self.v['aTtrue']    = totaltrue/N
    62                 self.v['aTfp']      = totalfp/N
    63                 self.v['aTfn']      = totalfn/N
    64                 self.v['aTm']       = sum(self.v['Tm'])/N
    65                 self.v['aTd']       = sum(self.v['Td'])/N
    66                 self.v['Tm']       = sum(self.v['Tm'])
    67                 self.v['Td']       = sum(self.v['Td'])
    68                 self.v['mean']      = mmean(self.v['l'])
    69                 self.v['smean']     = stdev(self.v['l'])
    70                 self.v['amean']     = mmean(self.v['labs'])
    71                 self.v['samean']    = stdev(self.v['labs'])
     7class mybenchonset(benchonset):
    728
    739        def run_bench(self,modes=['dual'],thresholds=[0.5]):
    74                 self.modes = modes
     10                from os.path import dirname,basename
    7511                self.thresholds = thresholds
    7612                self.pretty_titles()
    77                 for mode in self.modes:
     13                d,e,f = [],[],[]
     14                for mode in modes:
     15                        self.vlist = []
    7816                        self.params.onsetmode = mode
    7917                        for threshold in self.thresholds:
     
    8321                                self.pretty_print()
    8422                                #print self.v
     23                                self.vlist.append(self.v)
     24                        self.plotroc(d)
     25                        self.plotfmeas(e)
     26                        self.plotpr(f)
     27                        #print vlist
     28                #self.plotplotroc(d)
     29                #self.plotplotfmeas(e)
     30                #self.plotplotpr(f)
     31                outplot = basename(self.datadir)
     32                for ext in ("png","svg","ps"):
     33                        self.plotplotroc(d,outplot=outplot,extension=ext)
     34                        self.plotplotfmeas(e,outplot=outplot,extension=ext)
     35                        self.plotplotpr(f,outplot=outplot,extension=ext)
     36
    8537
    8638        def auto_learn(self,modes=['dual'],thresholds=[0.1,1.5]):
     
    10759
    10860                        for i in range(steps):
     61                                self.params.localmin = True
     62                                self.params.delay = 1.
     63                                self.dir_exec()
     64                                self.dir_eval()
    10965                                self.params.threshold = ( lesst + topt ) * .5
    11066                                self.dir_exec()
     
    170126        if len(sys.argv) > 1: datapath = sys.argv[1]
    171127        else: print "ERR: a path is required"; sys.exit(1)
    172         modes = ['complex', 'energy', 'phase', 'specdiff', 'kl', 'mkl', 'dual']
    173         #modes = [ 'mkl' ]
     128        modes = ['complex', 'energy', 'phase', 'hfc', 'specdiff', 'kl', 'mkl', 'dual']
    174129        thresholds = [ 0.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2]
    175         #thresholds = [1.5]
     130        #modes = [ 'hfc' ]
     131        #thresholds = [0.1, 1.5]
    176132
    177133        #datapath = "%s%s" % (DATADIR,'/onset/DB/*/')
    178134        respath = '/var/tmp/DB-testings'
    179135
    180         benchonset = benchonset(datapath,respath,checkres=True,checkanno=True)
     136        benchonset = mybenchonset(datapath,respath,checkres=True,checkanno=True)
    181137        benchonset.params = taskparams()
    182138        benchonset.task = taskonset
Note: See TracChangeset for help on using the changeset viewer.