Changeset 6ae3a77 for python


Ignore:
Timestamp:
Feb 23, 2006, 3:23:30 AM (18 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:
ee7b9da
Parents:
a12563ea
Message:

update onset bench
update onset bench

Location:
python/test/bench/onset
Files:
4 edited

Legend:

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

    ra12563ea r6ae3a77  
    11#! /usr/bin/python
    22
    3 from aubio.bench.node import *
    43from aubio.tasks import *
    54
     
    109        def run_bench(self,modes=['dual'],thresholds=[0.5]):
    1110                from os.path import dirname,basename
    12                 self.modes = modes
    1311                self.thresholds = thresholds
    1412                self.pretty_titles()
    15                 for mode in self.modes:
     13
     14                for mode in modes:
    1615                        d = []
    17                         outplot = "_-_".join(("delay",mode,
    18                                 basename(self.datadir) ))
    19 
    2016                        self.params.onsetmode = mode
     17                        self.params.localmin = True
     18                        self.params.delay = 1.
    2119                        self.params.threshold = thresholds[0]
    22 
     20                        #
    2321                        self.params.localmin = False
    2422                        self.params.delay = 0.
    25 
    26                         self.dir_exec()
    27                         self.dir_eval()
    28                         self.pretty_print()
     23                        self.dir_eval_print()
    2924                        self.plotdiffs(d,plottitle="Causal")
    30 
     25                        #
    3126                        self.params.localmin = True
    3227                        self.params.delay = 0.
    33                         self.dir_exec()
    34                         self.dir_eval()
    35                         self.pretty_print()
     28                        self.dir_eval_print()
    3629                        self.plotdiffs(d,plottitle="Local min")
    3730
    3831                        self.params.localmin = False
    3932                        self.params.delay = 6.
    40                         self.dir_exec()
    41                         self.dir_eval()
    42                         self.pretty_print()
     33                        self.dir_eval_print()
    4334                        self.plotdiffs(d,plottitle="Fixed delay")
    4435
    45                         self.plotplotdiffs(d)
    46                         self.plotplotdiffs(d,outplot=outplot,extension="png")
    47                         self.plotplotdiffs(d,outplot=outplot,extension="ps")
    48                         self.plotplotdiffs(d,outplot=outplot,extension="svg")
    49 
     36                        #self.plotplotdiffs(d)
     37                        outplot = "_-_".join(("delay",mode,basename(self.datadir) ))
     38                        for ext in ("png","svg","ps"):
     39                                self.plotplotdiffs(d,outplot=outplot,extension=ext)
    5040
    5141if __name__ == "__main__":
     
    5343        if len(sys.argv) > 1: datapath = sys.argv[1]
    5444        else: print "ERR: a path is required"; sys.exit(1)
    55         modes = ['complex', 'energy', 'phase', 'specdiff', 'kl', 'mkl', 'dual']
    56         #modes = [ 'complex' ]
    57         thresholds = [ 0.5]
    58         #thresholds = [1.5]
     45        modes = ['complex', 'energy', 'phase', 'hfc', 'specdiff', 'kl', 'mkl', 'dual']
     46        #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]
     47        #modes = [ 'hfc' ]
     48        thresholds = [0.5]
    5949
    6050        #datapath = "%s%s" % (DATADIR,'/onset/DB/*/')
  • python/test/bench/onset/bench-onset

    ra12563ea r6ae3a77  
    1111                self.thresholds = thresholds
    1212                self.pretty_titles()
    13                 d,e,f = [],[],[]
     13                d,e,f,g = [],[],[],[]
    1414                for mode in modes:
    1515                        self.vlist = []
    1616                        self.params.onsetmode = mode
     17                        #self.params.localmin = True
     18                        self.params.delay = 2.
     19                        self.params.bufsize = 1024
     20                        self.params.hopsize = 256
     21                        self.params.step = float(self.params.hopsize)/float(self.params.samplerate)
     22                        #self.params.mintol = 8.
     23
    1724                        for threshold in self.thresholds:
    1825                                self.params.threshold = threshold
    19                                 self.dir_exec()
    20                                 self.dir_eval()
    21                                 self.pretty_print()
    22                                 #print self.v
     26                                self.dir_eval_print()
    2327                                self.vlist.append(self.v)
    2428                        self.plotroc(d)
    2529                        self.plotfmeas(e)
    2630                        self.plotpr(f)
    27                         #print vlist
     31                        #self.plothistcat(g)
     32
     33
     34
    2835                #self.plotplotroc(d)
    2936                #self.plotplotfmeas(e)
     
    3441                        self.plotplotfmeas(e,outplot=outplot,extension=ext)
    3542                        self.plotplotpr(f,outplot=outplot,extension=ext)
    36 
    37 
    38         def auto_learn(self,modes=['dual'],thresholds=[0.1,1.5]):
    39                 """ simple dichotomia like algorithm to optimise threshold """
    40                 self.modes = modes
    41                 self.pretty_titles()
    42                 for mode in self.modes:
    43                         steps = 11
    44                         lesst = thresholds[0]
    45                         topt = thresholds[1]
    46                         self.params.onsetmode = mode
    47 
    48                         self.params.threshold = topt
    49                         self.dir_exec()
    50                         self.dir_eval()
    51                         self.pretty_print()
    52                         topF = self.F
    53 
    54                         self.params.threshold = lesst
    55                         self.dir_exec()
    56                         self.dir_eval()
    57                         self.pretty_print()
    58                         lessF = self.F
    59 
    60                         for i in range(steps):
    61                                 self.params.localmin = True
    62                                 self.params.delay = 1.
    63                                 self.dir_exec()
    64                                 self.dir_eval()
    65                                 self.params.threshold = ( lesst + topt ) * .5
    66                                 self.dir_exec()
    67                                 self.dir_eval()
    68                                 self.pretty_print()
    69                                 if self.F == 100.0 or self.F == topF:
    70                                         print "assuming we converged, stopping"
    71                                         break
    72                                 #elif abs(self.F - topF) < 0.01 :
    73                                 #       print "done converging"
    74                                 #       break
    75                                 if topF < self.F:
    76                                         #lessF = topF
    77                                         #lesst = topt
    78                                         topF = self.F
    79                                         topt = self.params.threshold
    80                                 elif lessF < self.F:
    81                                         lessF = self.F
    82                                         lesst = self.params.threshold
    83                                 if topt == lesst:
    84                                         lesst /= 2.
    85 
    86         def auto_learn2(self,modes=['dual'],thresholds=[0.00001,1.0]):
    87                 """ simple dichotomia like algorithm to optimise threshold """
    88                 self.modes = modes
    89                 self.pretty_titles([])
    90                 for mode in self.modes:
    91                         steps = 10
    92                         step = 0.4
    93                         self.params.onsetmode = mode
    94                         self.params.threshold = thresholds[0]
    95                         cur = 0
    96 
    97                         for i in range(steps):
    98                                 self.dir_exec()
    99                                 self.dir_eval()
    100                                 self.pretty_print()
    101                                 new = self.P
    102                                 if self.R == 0.0:
    103                                         #print "Found maximum, highering"
    104                                         step /= 2.
    105                                         self.params.threshold -= step
    106                                 elif new == 100.0:
    107                                         #print "Found maximum, highering"
    108                                         step *= .99
    109                                         self.params.threshold += step
    110                                 elif cur > new:
    111                                         #print "lower"
    112                                         step /= 2.
    113                                         self.params.threshold -= step
    114                                 elif cur < new:
    115                                         #print "higher"
    116                                         step *= .99
    117                                         self.params.threshold += step
    118                                 else:
    119                                         print "Assuming we converged"
    120                                         break
    121                                 cur = new
    122 
     43                        #self.plotplothistcat(g,outplot=outplot,extension=ext)
    12344
    12445if __name__ == "__main__":
     
    12950        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]
    13051        #modes = [ 'hfc' ]
    131         #thresholds = [0.1, 1.5]
     52        #thresholds = [0.5]
    13253
    13354        #datapath = "%s%s" % (DATADIR,'/onset/DB/*/')
  • python/test/bench/onset/bench-window

    ra12563ea r6ae3a77  
    33from aubio.tasks import *
    44
    5 from benchonset import mmean, stdev, plotdiffs, plotplotdiffs, benchonset
     5from benchonset import mmean, stdev, benchonset
    66
    77class mybenchonset(benchonset):
     
    1111                self.thresholds = thresholds
    1212                self.pretty_titles()
     13
    1314                for mode in modes:
    1415
    1516                        self.params.onsetmode = mode
     17                        self.params.localmin = True
     18                        self.params.delay = 1.
    1619                        self.params.threshold = thresholds[0]
    1720                        self.params.localmin = False
    18 
     21                        #
    1922                        for delay in (0., 4.):
    2023                                d = []
    21                                 outplot = "_-_".join(("window",mode,"delay-%s" % delay,
    22                                         basename(self.datadir) ))
    2324                                self.params.delay = delay
    24 
    2525                                for buf in (2048, 1024, 512):
    2626                                        for hop in (buf/2, buf/4):
     
    2828                                                self.params.hopsize = hop
    2929                                                self.params.step = float(self.params.hopsize)/float(self.params.samplerate)
    30 
    31                                                 self.dir_exec()
    32                                                 self.dir_eval()
    33                                                 self.pretty_print()
    34                                                 plotdiffs(self.v,d,plottitle="%s %s" % (buf,hop))
    35 
    36                                 plotplotdiffs(d)
    37                                 plotplotdiffs(d,outplot=outplot,extension="png")
    38                                 plotplotdiffs(d,outplot=outplot,extension="ps")
    39                                 plotplotdiffs(d,outplot=outplot,extension="svg")
    40 
     30                                                self.dir_eval_print()
     31                                                self.plotdiffs(d,plottitle="%s %s" % (buf,hop))
     32                                #plotplotdiffs(d)
     33                                outplot = "_-_".join(("window",mode,"delay-%s" % int(delay),
     34                                        basename(self.datadir) ))
     35                                for ext in ("png","svg","ps"):
     36                                        self.plotplotdiffs(d,outplot=outplot,extension=ext)
    4137
    4238if __name__ == "__main__":
     
    4440        if len(sys.argv) > 1: datapath = sys.argv[1]
    4541        else: print "ERR: a path is required"; sys.exit(1)
    46         modes = ['complex', 'energy', 'phase', 'specdiff', 'kl', 'mkl', 'dual']
    47         #modes = [ 'complex' ]
    48         thresholds = [ 0.5]
    49         #thresholds = [1.5]
     42        modes = ['complex', 'energy', 'phase', 'hfc', 'specdiff', 'kl', 'mkl', 'dual']
     43        #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]
     44        #modes = [ 'hfc' ]
     45        thresholds = [0.5]
    5046
    5147        #datapath = "%s%s" % (DATADIR,'/onset/DB/*/')
  • python/test/bench/onset/benchonset.py

    ra12563ea r6ae3a77  
    4747                v['mode']      = self.params.onsetmode
    4848                v['thres']     = self.params.threshold
     49                v['bufsize']   = self.params.bufsize
     50                v['hopsize']   = self.params.hopsize
     51                v['silence']   = self.params.silence
     52                v['mintol']   = self.params.mintol
    4953
    5054                v['Torig']     = sum(v['orig'])
     
    9599                self.v['recl']      = self.R
    96100
     101
     102        """
     103        Plot functions
     104        """
     105
    97106        def plotroc(self,d,plottitle=""):
    98107                import Gnuplot, Gnuplot.funcutils
     
    188197                #g('set key 27,65')
    189198                #g('set format \"%g\"')
     199                g.plot(*d)
     200
     201        def plotfmeasvar(self,d,var,plottitle=""):
     202                import Gnuplot, Gnuplot.funcutils
     203                x,y = [],[]
     204                for i in self.vlist:
     205                        x.append(i[var])
     206                        y.append(i['dist'])
     207                d.append(Gnuplot.Data(x, y, with='linespoints',
     208                        title="%s %s" % (plottitle,i['mode']) ))
     209       
     210        def plotplotfmeasvar(self,d,var,outplot="",extension='ps', title="F-measure"):
     211                import Gnuplot, Gnuplot.funcutils
     212                from sys import exit
     213                g = Gnuplot.Gnuplot(debug=0, persist=1)
     214                if outplot:
     215                        if   extension == 'ps':  terminal = 'postscript'
     216                        elif extension == 'png': terminal = 'png'
     217                        elif extension == 'svg': terminal = 'svg'
     218                        else: exit("ERR: unknown plot extension")
     219                        g('set terminal %s' % terminal)
     220                        g('set output \'fmeas-%s.%s\'' % (outplot,extension))
     221                g.xlabel(var)
     222                g.ylabel('F-measure (%)')
     223                #g('set xrange [0:1.2]')
     224                g('set yrange [0:100]')
     225                g.title(basename(self.datadir))
    190226                g.plot(*d)
    191227
     
    230266                g.ylabel('% number of correct detections / ms ')
    231267                g('set xrange [-0.05:0.05]')
    232                 g('set yrange [0:50]')
    233                 g.plot(*d)
    234 
    235 
     268                g('set yrange [0:20]')
     269                g.plot(*d)
     270
     271
     272        def plothistcat(self,d,plottitle=""):
     273                import Gnuplot, Gnuplot.funcutils
     274                total = v['Torig']
     275                for i in range(len(per)): per[i] /= total/100.
     276
     277                d.append(Gnuplot.Data(val, per, with='fsteps',
     278                        title="%s %s" % (plottitle,v['mode']) ))
     279                #d.append('mean=%f,sigma=%f,eps(x) title \"\"'% (mean,smean))
     280                #d.append('mean=%f,sigma=%f,eps(x) title \"\"'% (amean,samean))
     281
     282
     283        def plotplothistcat(self,d,outplot=0,extension='ps'):
     284                import Gnuplot, Gnuplot.funcutils
     285                from sys import exit
     286                g = Gnuplot.Gnuplot(debug=0, persist=1)
     287                if outplot:
     288                        if   extension == 'ps':  ext, extension = '.ps' , 'postscript'
     289                        elif extension == 'png': ext, extension = '.png', 'png'
     290                        elif extension == 'svg': ext, extension = '.svg', 'svg'
     291                        else: exit("ERR: unknown plot extension")
     292                        g('set terminal %s' % extension)
     293                        g('set output \'diffhist-%s%s\'' % (outplot,ext))
     294                g('eps(x) = 1./(sigma*(2.*3.14159)**.5) * exp ( - ( x - mean ) ** 2. / ( 2. * sigma ** 2. ))')
     295                g.title(basename(self.datadir))
     296                g.xlabel('delay to hand-labelled onset (s)')
     297                g.ylabel('% number of correct detections / ms ')
     298                g('set xrange [-0.05:0.05]')
     299                g('set yrange [0:20]')
     300                g.plot(*d)
     301
     302
Note: See TracChangeset for help on using the changeset viewer.