示例#1
0
def plot_narmour_feature(prob_model, min_pitch, max_pitch, feature_name, folder, reference_note=None):
    if feature_name is not None: return
    max_interval= max_pitch - min_pitch
    max_interval= 12
    prob= [[None]*2*(max_interval+1) for i in xrange(2*max_interval+2)]
    if feature_name is not None: code= [[None]*2*(max_interval+1) for i in xrange(2*max_interval+2)]
    for i1_length in xrange(2*max_interval+2):
        for i2_length in xrange(2*max_interval+2):
            prob[i1_length][i2_length]= prob_model.get_interval_prob(i1_length-max_interval-1, i2_length-max_interval-1, feature_name=feature_name)
            if reference_note is not None:
                prob[i1_length][i2_length]= prob[i1_length][i2_length]*prob_model.notes_distr[Note(reference_note.pitch+i1_length+i2_length).get_canonical_note()]

            if feature_name is not None: 
                #code[i1_length][i2_length]= i1_length -max_interval-1 + i2_length -max_interval-1 
                code[i1_length][i2_length]= get_interval_features(i1_length-max_interval-1, i2_length-max_interval-1)[feature_name]
    

    x= range(2*max_interval+2)
    y= range(2*max_interval+2)

    #if feature_name is None:
    #    for reference_note in xrange(0, 12):
    #        print reference_note
    #        for i1_length in xrange(2*max_interval+2):
    #            for i2_length in xrange(2*max_interval+2):
    #                prob[i1_length][i2_length]= prob_model.get_interval_prob(i1_length-max_interval-1, i2_length-max_interval-1, feature_name=feature_name)
    #                prob[i1_length][i2_length]= prob[i1_length][i2_length]*prob_model.notes_distr[Note(reference_note+i1_length+i2_length).get_canonical_note()]

    #        prob_fname= os.path.join(folder, 'narmour_%s_%s.png' % (reference_note, feature_name))
    #        _do_plot(x, y, prob, prob_fname, max_interval)


    if feature_name == 'all': import ipdb;ipdb.set_trace()
    if feature_name is None: feature_name= 'all'
    if reference_note is not None:
        prob_fname= os.path.join(folder, 'narmour_%s_%s.png' % (reference_note, feature_name))
    else:
        prob_fname= os.path.join(folder, 'narmour_%s.png' % feature_name) 
    _do_plot(x, y, prob, prob_fname, max_interval, reference_note=reference_note)
示例#2
0
    def get_interval_prob(self, i1_length, i2_length, feature_name=None):
        features= get_interval_features(i1_length, i2_length)

        return self.get_features_prob(features, feature_name)