def benchmark(net, benchmark_dir): r""" Run a benchmark to gauge the quality of the ANN approach. This function takes a fully trained ANN as well as a directory containing only benchmark files as parameters. """ tracks = read_standard_tracks hits = 0 misses = 0 # **note that there is one *chord context* per chord** contexts = [context for piece in os.listdir(benchmark_dir) for track in tracks(os.path.join(benchmark_dir, piece)) for context in chord_contexts(track)] for context in contexts: preceding = context[0] theoretical_chord = physical2theoretical_chord(context[1]) following = context[2] recent_notes = context[3] chord_index = context[4] limiting = context[5] best_config = _best_sane_chord(preceding, theoretical_chord, following, recent_notes, chord_index, limiting, net) LOG.info('Best config: {best_config}.'.format(**locals())) LOG.info('Truth: {0}'.format(context[1])) if best_config == context[1]: hits += 1 else: misses += 1 print('Hits: {hits}.\nMisses: {misses}'.format(**locals())) print('Accuracy: {ratio}'.format(ratio = float(hits) / (hits + misses)))
def _lowest_note_chord(chord): r""" Return the highest note in a chord, in its theoretical notation. Chords are given in their physical form. >>> _lowest_note_chord({5: 5, 4: 5}) ('A', 2) """ notes = physical2theoretical_chord(chord) if notes: return sorted(notes.keys(), key=cmp_to_key(compare_notes))[0]
def test_two_note_chord(self): physical = {3: 7, 4: 7} result = notemappings.physical2theoretical_chord(physical) expected = Counter([('E', 3), ('A', 3)]) self.assertEqual(result, expected)