コード例 #1
0
ファイル: x-force.py プロジェクト: gperciva/vivi
    def main():
        x_range = numpy.linspace(fbmin, fbmax, STEPS_X)
        y_range = range(STEPS_Y)

        costs = numpy.zeros((STEPS_Y, STEPS_X))
        for ix, x in enumerate(x_range):
            for iy, y in enumerate(y_range):
                filename = os.path.join(TMPDIR,
                                        "%i-%i-x%.3f-y%.3f" % (ix, iy, x, y))
                K_attack = 0.0
                K_main = 0.0
                K_velocity = 0.0

                controller.set_stable_K(st, dyn, 0, K_attack)
                controller.set_stable_K_main(st, dyn, 0, K_main)
                controller.set_K_velocity(K_velocity)

                single_file(filename, x)
                nac = note_actions_cats.NoteActionsCats()
                nac.load_file(filename, None)
                to_find = "finger_midi"
                nac.load_note(to_find, full=True)
                cats = [b for a, b in nac.get_note_cats()]
                cost = get_costs(cats)
                costs[iy][ix] = cost

            #print "Done %i / %i" % (ix+1, STEPS_X)
            # clean up
            remove_these = glob.glob(os.path.join(TMPDIR, "*"))
            for r in remove_these:
                os.remove(r)
        #print costs

        stable_file = open('%s.txt' % (name), 'w')
        for ix, x in enumerate(x_range):
            for iy, y in enumerate(y_range):
                stable_file.write("%g\t%g\t%g\n" % (x, y, costs[iy][ix]))
            stable_file.write("\n")
        stable_file.close()

        means = numpy.mean(costs, axis=0)
        stable_file = open('%s-means.txt' % (name), 'w')
        for ix, x in enumerate(x_range):
            #for iy, y in enumerate(y_range):
            stable_file.write("%g\t%g\n" % (x, means[ix]))
        #stable_file.write("\n")
        stable_file.close()

        lows = numpy.percentile(costs, 25, axis=0)
        highs = numpy.percentile(costs, 75, axis=0)
        stable_file = open('%s-lows.txt' % (name), 'w')
        for ix, x in enumerate(x_range):
            stable_file.write("%g\t%g\n" % (x, lows[ix]))
        stable_file.close()
        stable_file = open('%s-highs.txt' % (name), 'w')
        for ix, x in enumerate(x_range):
            stable_file.write("%g\t%g\n" % (x, highs[ix]))
        stable_file.close()
コード例 #2
0
    def get_stable_files_info(self):
        files = self._get_files()

        self._setup_lists_from_files(files)

        # ASSUME: no screw-ups in the file creation
        self.num_rows = len(self.counts[0]) * len(self.extras[0])
        #self.num_cols = len(self.forces_initial[0])*len(self.finger_midis)
        self.num_cols = len(self.forces_initial[0])
        self.num_counts = len(self.counts[0])
        #self.num_rows = STEPS_X
        #self.num_cols = STEPS_Y

        # initialize 3d array
        self.notes = []
        for fmi in range(len(self.finger_midis)):
            self.notes.append([])
            for i in range(self.num_rows):
                self.notes[fmi].append([])
                for j in range(self.num_cols):
                    self.notes[fmi][i].append(None)
        
        for filename in files:
            params, extra, count = self.files.get_audio_params_extra(filename)
            finger_midi = params.finger_midi
            force = params.bow_force
            fmi = self.finger_midis.index(finger_midi)
            K_i = self.extras[finger_midi].index(extra)
            force_i = self.forces_initial[finger_midi].index(force)

            # and setup self.examines
            row = (
                    self.num_counts*self.extras[finger_midi].index(extra)
                    + self.counts[finger_midi].index(count)
                    )
            col = (
                    #len(self.finger_midis) * 
                    self.forces_initial[finger_midi].index(force)
                    #+ self.finger_midis.index(finger_midi)
                    )
            nac = note_actions_cats.NoteActionsCats()
            nac.load_file(filename[0:-4], self.files)
            #to_find = "finger_midi %i" % fm
            to_find = "finger_midi"
            nac.load_note(to_find, full=True)
            #print nac.note_cats_means
            #print nac.note_forces


            #stability = self.get_stability(nac.note_cats_means,
            #    nac.note_forces)
            cats = [ b for a,b in nac.get_note_cats() ]
            stability = self.get_cost(cats)

            #self.notes[fmi][K_i][force_i] = (nac, stability)
            #print fmi, row, col
            self.notes[fmi][row][col] = (nac, stability)
コード例 #3
0
ファイル: mix_hill.py プロジェクト: gperciva/vivi
def get_notes_costs(audio_basename, pncs):
    nac = note_actions_cats.NoteActionsCats()
    nac.load_file(audio_basename)
    note_costs = []
    for pnc in pncs:
        nac.load_note(pnc)
        cats = map(lambda x: x[1], nac.note_cats)
        filt = filter(lambda x: x != vivi_defines.CATEGORY_NULL, cats)
        filt = filter(lambda x: x != vivi_defines.CATEGORY_WAIT, filt)
        cost = sum(map(lambda x: x * x, filt))
        note_costs.append(cost)
    return note_costs
コード例 #4
0
 def get_cats(basename):
     nac = note_actions_cats.NoteActionsCats()
     nac.load_file(basename, self.files)
     #to_find = "finger_midi %i" % basic_training.FINGER_MIDIS[self.fm]
     to_find = "finger_midi"
     nac.load_note(to_find, full=True)
     cats = [b for a, b in nac.get_note_cats()]
     #att = self.portion_attack(cats_means)
     #att = cats_means # consider entire note
     #cost = self.get_cost(att)
     notes = split_cats(cats)
     return notes
コード例 #5
0
    def main():
        x_range = numpy.linspace(0, 0.2, STEPS_X)
        x_range = numpy.linspace(0, 0.05, STEPS_X)
        #y_range = numpy.linspace(-0.1, 0.1, STEPS_Y)
        #y_range = numpy.linspace(-0.5, 0.0, STEPS_Y)
        y_range = numpy.linspace(0.0, 0.1, STEPS_Y)

        costs = numpy.zeros((STEPS_Y, STEPS_X))
        for ix, x in enumerate(x_range):
            for iy, y in enumerate(y_range):
                filename = os.path.join(TMPDIR,
                                        "%i-%i-x%.3f-y%.3f" % (ix, iy, x, y))
                K_attack = y
                K_main = x
                K_velocity = 0

                controller.set_stable_K(st, dyn, 0, K_attack)
                controller.set_stable_K_main(st, dyn, 0, K_main)
                controller.set_K_velocity(K_velocity)

                single_file(filename, x, y)
                nac = note_actions_cats.NoteActionsCats()
                nac.load_file(filename, None)
                to_find = "finger_midi"
                nac.load_note(to_find, full=True)
                cats = [b for a, b in nac.get_note_cats()]
                cost = get_costs(cats)
                costs[iy][ix] = cost

            print "Done %i / %i" % (ix + 1, STEPS_X)
            # clean up
            remove_these = glob.glob(os.path.join(TMPDIR, "*"))
            for r in remove_these:
                os.remove(r)
        #print costs

        stable_file = open('%s.txt' % (name), 'w')
        for ix, x in enumerate(x_range):
            for iy, y in enumerate(y_range):
                stable_file.write("%g\t%g\t%g\n" % (x, y, costs[iy][ix]))
            stable_file.write("\n")
        stable_file.close()
コード例 #6
0
    def try_file(descr, filename, good_flag=False):
        #pylab.figure()
        nac = note_actions_cats.NoteActionsCats()
        nac.load_file(filename[0:-5], None)
        nac.load_note("finger_midi", full=True)

        cats = nac.note_cats_means
        #print cats
        #cats = [c for t,c in nac.note_cats]
        # remove weird final (0,0)
        if nac.note_cats[-1][0] == 0:
            cats = cats[:-1]
        title = filename[-12:-7]
        stability = TaskStable.get_stability(cats,
            nac.note_forces,
            plot=True,
            name=descr, good_flag=good_flag)

        #plot_cats = [c for c in cats if c > -10]
        #cats = numpy.array(plot_cats)
        #pylab.title(descr + " " + title)
        #pylab.legend()
        print "%s final:\t%s\t%.2f" % (descr, title, stability)
コード例 #7
0
    def get_file_info(self):
        files = self._get_files()

        self._setup_lists_from_files(files)

        self.num_rows = len(self.counts[0])
        self.num_cols = len(self.extras[0])

        self.notes = []
        for i in range(self.num_rows):
            self.notes.append([])
            for j in range(self.num_cols):
                self.notes[i].append(None)

        for filename in files:
            params, extra, count = self.files.get_audio_params_extra(filename)
            row = self.counts[0].index(count)
            col = self.extras[0].index(extra)

            nac = note_actions_cats.NoteActionsCats()
            nac.load_file(filename[0:-4], self.files)
            nac.load_note("note", full=True)
            self.notes[row][col] = (nac, 0, filename)
コード例 #8
0
 def new_examine_note(self):
     self.examine_note = note_actions_cats.NoteActionsCats()
コード例 #9
0
    def _examine_files(self):
        #files = self._get_files()

        #self._setup_lists_from_files(files)

        #self.num_rows = len(self.counts[self.fm])
        #self.num_cols = len(self.forces_initial[self.fm])
        self.num_rows = STEPS_Y
        self.num_cols = STEPS_X

        # hack
        #self.forces = self.forces_initial[self.fm]
        self.forces = self.test_range

        # initialize 2d array
        notes = []

        for i in range(self.num_rows):
            notes.append([])
            for j in range(self.num_cols):
                notes[i].append(None)

        shape = (self.num_rows, self.num_cols)
        costs = numpy.zeros(shape, dtype=numpy.float64)

        forces = [ float(str("%.03f" % f)) for f in self.test_range]
        for filename in self.kept_files:
            params, extra, count = self.files.get_audio_params_extra(filename)
            #print filename, params, extra, count
            finger_midi = params.finger_midi
            if finger_midi != self.fm:
                continue

            #row = self.counts[finger_midi].index(count)
            #col = self.forces_initial[finger_midi].index(params.bow_force)
            row = count
            col = forces.index(params.bow_force)

            nac = note_actions_cats.NoteActionsCats()
            nac.load_file(filename, self.files)
            #to_find = "finger_midi %i" % basic_training.FINGER_MIDIS[self.fm]
            to_find = "finger_midi"
            nac.load_note(to_find, full=True)
            cats = [ b for a,b in nac.get_note_cats() ]
            #att = self.portion_attack(cats_means)
            #att = cats_means # consider entire note
            #cost = self.get_cost(att)
            K = self.K_range[row]
            #cost = (1.0 + K)*get_cost(cats)
            cost = get_cost(cats)
            #print row, col
            notes[row][col] = (nac, cost, filename)
            costs[row][col] = cost

        stable_file = open('orig-%i.txt' % self.fmi, 'w')
        for K_i, K in enumerate(self.K_range):
            for Fbi, Fb in enumerate(self.test_range):
                stable_file.write("%g\t%g\t%g\n" % (
                        K,
                        Fb,
                        costs[K_i][Fbi]))
            stable_file.write("\n")
        stable_file.close()
        #numpy.savetxt("orig.txt", costs)
        newcosts = numpy.zeros( shape )
        for i in range(shape[0]):
            for j in range(shape[1]):
                squares = 0
                if j > 0:
                    squares += 1
                if j < shape[1]-1:
                    squares += 1
                if i > 0:
                    squares += 1
                if i < shape[0] - 1:
                    squares += 1
                left = costs[i][j-1] if j>0 else 0
                right = costs[i][j+1] if j<shape[1]-1 else 0
                top = costs[i-1][j] if i>0 else 0
                bot = costs[i+1][j] if i>shape[0]-1 else 0
                newcosts[i][j] = (costs[i][j]/2.0 +
                    (left+right+top+bot) / squares) / 2.0

        stable_file = open('stable-%i.txt' % self.fmi, 'w')
        for K_i, K in enumerate(self.K_range):
            for Fbi, Fb in enumerate(self.test_range):
                stable_file.write("%g\t%g\t%g\n" % (
                        K,
                        Fb,
                        newcosts[K_i][Fbi]))
            stable_file.write("\n")
        stable_file.close()

        #newcosts = costs
        # avoid picking edges
        r = 0
        c = 0
        while True:
        #while r == 0 or c == 0 or r == newcosts.shape[0] or c == newcosts.shape[1]:
            #r, c = numpy.unravel_index(costs.argmin(), shape)
            r, c = numpy.unravel_index(newcosts.argmin(), shape)
            #print r, c, newcosts[r][c]
            if r == 0 or c == 0 or r == newcosts.shape[0]-1 or c == newcosts.shape[1]-1:
                newcosts[r][c] = 99999
            else:
                break

        #print r, c, costs[r][c]
        self.best_attack = self.test_range[c]
        self.best_stability = self.K_range[r]
       # #print best_attack, best_stability

        if self.second:
            self.notes2 = list(notes)
            self.best_attack2 = self.best_attack
            self.best_stability2 = self.best_stability
        else:
            self.notes1 = list(notes)
            self.best_attack1 = self.best_attack
            self.best_stability1 = self.best_stability


        return 0,0
        cands = []
        for col, bow_force in enumerate(self.test_range):
        #for col, bow_force in enumerate(self.forces_initial[self.fm]):
            vals = []
            #for row, count in enumerate(self.counts[self.fm]):
            for row in range(STEPS_Y):
                val = notes[row][col]
                #print val
                #if val[1] > 0:
                #    vals.append(val[1])
            if len(vals) > 0:
                val = scipy.mean(vals)
                std = scipy.std(vals)
                worst = max(vals)
            else:
                val = 0
            cands.append( (val, col, bow_force) )
            #cands.append( (worst, col, bow_force) )
            #cands.append( (val+5*std, col, bow_force) )
            #cands.append( (val**2+std**2, col, bow_force) )
        cands.sort()
        lowest_index = cands[0][1]
        self.best_attack = cands[0][2]
        #if self.fmi != 0:
        #    return lowest_index, self.best_attack
        #print '------'
        #for c in cands:
        #    print c
        #print '------'
        #print self.fmi, lowest_index, self.best_attack
        return lowest_index, self.best_attack
コード例 #10
0
    def get_stable_files_info(self):
        #files = self._get_files()

        #self._setup_lists_from_files(files)

        # ASSUME: no screw-ups in the file creation
        #fm = basic_training.FINGER_MIDIS[self.finger_midi_index]
        #fm = self.finger_midi
        #self.num_rows = len(self.counts[0]) * len(self.extras[0])
        #self.num_rows = len(self.counts[0])
        #self.num_cols = len(self.forces_initial[0])*len(self.finger_midis)
        #self.num_counts = len(self.counts[0])

        self.num_rows = REPS * 3
        self.num_counts = REPS
        self.num_cols = STEPS

        #print self.num_rows, self.num_cols
        # initialize 2d array
        self.notes = []
        for i in range(self.num_rows):
            self.notes.append([])
            for j in range(self.num_cols):
                self.notes[i].append(None)

        row = 0
        col = 0
        for i in range(3):
            row = i * self.num_counts
            col = 0
            #print len(self.kept_files[i])
            for vals in self.kept_files[i]:
                force, filename, direction = vals
                nac = note_actions_cats.NoteActionsCats()
                nac.load_file(filename, self.files)
                #to_find = "finger_midi %i" % fm
                to_find = "finger_midi"
                nac.load_note(to_find, full=True)
                #print row, col
                self.notes[row][col] = (nac, direction, filename)
                row += 1
                if (row % REPS) == 0:
                    row = i * self.num_counts
                    col += 1
        return

        for filename in files:
            params, extra, count = self.files.get_audio_params_extra(filename)
            finger_midi = params.finger_midi
            fmi = FINGERS.index(finger_midi)
            force = params.bow_force
            #if finger_midi != self.finger_midi:
            #if finger_midi != basic_training.FINGER_MIDIS[self.finger_midi_index]:
            #    continue
            #print filename, self.finger_midis, finger_midi, fmi, self.finger_midi_index
            count_i = self.counts[finger_midi].index(count)
            #K_i = self.extras[finger_midi].index(extra)
            force_i = self.forces_initial[finger_midi].index(force)
            #force_i = self.test_range.index(force)

            # and setup self.examines
            row = count_i
            col = force_i + len(self.finger_midis) * fmi
            #print row, col

            nac = note_actions_cats.NoteActionsCats()
            nac.load_file(filename[0:-4], self.files)
            #to_find = "finger_midi %i" % fm
            to_find = "finger_midi"
            nac.load_note(to_find)
            examine_cats = nac.note_cats_means
            rms = self.get_rms(examine_cats)
            self.notes[row][col] = (nac, rms, filename)