def test_good_rules(): parncutt = Parncutt() parncutt.segment_combiner(method="cost") for id in subcosts: d_corpus = DCorpus(corpus_str=TestConstant.PARNCUTT_HUMAN_FRAGMENT[id]) parncutt.load_corpus(d_corpus=d_corpus) if id == 'B': suggestions, costs, details = parncutt.generate_advice(staff="upper", cycle=4, k=20) else: suggestions, costs, details = parncutt.generate_advice(staff="upper", last_digit=last_digit[id], k=30) details_for_sugg = dict() for i in range(len(details)): details_for_sugg[suggestions[i]] = details[i][0] # 0 index because we only have one segment # parncutt.report_on_advice(suggestions, costs, details) for gold_sugg in subcosts[id]: assert gold_sugg in details_for_sugg, \ "Missing suggestion {0} in {1}".format(gold_sugg, id) for rule in subcosts[id][gold_sugg]: # if rule == 'bl1': # continue gold_cost = subcosts[id][gold_sugg][rule] cost = details_for_sugg[gold_sugg][rule] assert cost == gold_cost, \ "Bad {0} cost for {1} in {2}: {3} should be {4}".format(rule, gold_sugg, id, cost, gold_cost)
def test_cycles(): parncutt = Parncutt() parncutt.segment_combiner(method="cost") d_corpus = DCorpus(corpus_str=TestConstant.FOUR_NOTES) parncutt.load_corpus(d_corpus=d_corpus) suggestions, costs, details = parncutt.generate_advice(staff="upper", cycle=4, k=2) assert len(suggestions) == 2, "No loops in that dog in top ten" # parncutt.report_on_advice(suggestions, costs, details) d_corpus = DCorpus(corpus_str=TestConstant.PARNCUTT_HUMAN_FRAGMENT['B']) parncutt.load_corpus(d_corpus=d_corpus) suggestions, costs, details = parncutt.generate_advice(staff="upper", cycle=4, k=16) assert len(suggestions) == 16, "There should be 16 cyclic fingerings!"
def test_fingering_counts(): parncutt = Parncutt(pruning_method="none") parncutt.segment_combiner(method="cost") d_corpus = DCorpus(corpus_str=TestConstant.FOUR_NOTES) parncutt.load_corpus(d_corpus=d_corpus) suggestions, costs, details = parncutt.generate_advice(staff="upper", k=2) assert parncutt.last_segment_pruned_count() == 320, "Bad none pruning on open-ended problem"
def test_four_note_example(self): parncutt = Parncutt(segmenter=ManualDSegmenter(), segment_combiner="cost") # parncutt.segment_combiner(method="cost") d_corpus = DCorpus(corpus_str=TestConstant.FOUR_NOTES) parncutt.load_corpus(d_corpus=d_corpus) suggestions, costs, details = parncutt.generate_advice(staff="upper", k=2) self.assertEqual(len(suggestions), 2, "No loops in that dog in top ten")
def test_sma_lar(): parncutt = Parncutt() parncutt.segment_combiner(method="cost") for id in sma_lar_sums: d_corpus = DCorpus(corpus_str=TestConstant.PARNCUTT_HUMAN_FRAGMENT[id]) parncutt.load_corpus(d_corpus=d_corpus) if id == 'B': suggestions, costs, details = parncutt.generate_advice(staff="upper", cycle=4, k=20) else: suggestions, costs, details = parncutt.generate_advice(staff="upper", last_digit=last_digit[id], k=20) details_for_sugg = dict() for i in range(len(details)): details_for_sugg[suggestions[i]] = details[i][0] # 0 index because we only have one segment # parncutt.report_on_advice(suggestions, costs, details) for gold_sugg in sma_lar_sums[id]: assert gold_sugg in details_for_sugg,\ "Missing suggestion {0} in {1}".format(gold_sugg, id) sma = details_for_sugg[gold_sugg]['sma'] lar = details_for_sugg[gold_sugg]['lar'] assert sma + lar == sma_lar_sums[id][gold_sugg],\ "Bad sma + lar total for {0} in {1}".format(gold_sugg, id)
def get_fingered_system_scores(self, loaded_model: Parncutt, model_name, version=None, score_count=5, weights=None): advice = loaded_model.generate_advice(staff=STAFF, score_index=0, k=score_count) # print(advice) authority = model_name if version: authority = model_name + '_' + version base_score = loaded_model.score_by_index(0) sys_scores = [] for i in range(score_count): sys_score = copy.deepcopy(base_score) sys_score.remove_annotations() abcdf = advice[0][i] ann = DAnnotation(abcdf=abcdf, authority=authority) sys_score.annotate(d_annotation=ann) PianoFingering.finger_score(d_score=sys_score, staff=STAFF) sys_scores.append(sys_score) return sys_scores
#!/usr/bin/env python3 import pprint from pydactyl.dactyler.Parncutt import Parncutt from pydactyl.dcorpus.DCorpus import DCorpus from pydactyl.dcorpus.ManualDSegmenter import ManualDSegmenter model = Parncutt(segmenter=ManualDSegmenter(), segment_combiner="cost") # d_corpus = DCorpus(paths=["/Users/dave/malody.abcd"]) d_corpus = DCorpus(paths=["/tmp/malody.abcd"]) model.load_corpus(d_corpus=d_corpus) advice = model.advise() print("Best advice: {0}".format(advice)) # Gold-standard embedded in input file. hamming_dists = model.evaluate_strike_distance() print("Hamming distance from gold standard: {0}".format(hamming_dists[0])) suggestions, costs, details = model.generate_advice(staff="upper", k=9) print("Ranked advice:\n\t{0}".format("\n\t".join(suggestions))) print("Ranked costs :\n\t{0}".format("\n\t".join(str(x) for x in costs))) # pp = pprint.PrettyPrinter(width=120) # pp.pprint(details)
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. import copy import re import sys from pydactyl.dcorpus.DCorpus import DCorpus, DAnnotation from pydactyl.dactyler.Parncutt import Parncutt from pydactyl.dcorpus.PigIn import PigIn # import scamp # s = scamp.Session() # print(s.get_available_midi_output_devices()) # exit(0) ## pig_eater = PigIn() ## pig_eater.transform() staff = 'upper' k = 5 corpus_dir = "/Users/dave/tb2/didactyl/dd/corpora/pig/PianoFingeringDataset_v1.00/abcd/" d_corpus = DCorpus() d_corpus.append_dir(corpus_dir=corpus_dir, split_header_extension='abcd') model = Parncutt() model.load_corpus(d_corpus=d_corpus) advice = model.generate_advice(staff=staff, score_index=0, k=k) print(advice)