示例#1
0
def show5HexagramsForFileList(annotationFileList):
    cep = ll.ChromaEvaluationParameters(stepSize=2048, smoothingTime=1.2)
    chromaEvaluator = ll.AnnotatedChromaEvaluator(cep)
    chromas = chromaEvaluator.loadChromasForAnnotationFileList(annotationFileList)
    fig, ax = plt.subplots(nrows=1,ncols=5,figsize=(12,2.6), dpi= 90, facecolor='w', edgecolor='k')
    for axx in ax:
        axx.axes.get_xaxis().set_visible(False)
        axx.axes.get_yaxis().set_visible(False)
    ax[0].set_title("Maj")
    if (any(chromas.kinds == 'maj') > 0):
        maj = preprocessing.normalize(chromas.chromas[chromas.kinds == 'maj'], norm='l1')
        #sns.violinplot(data=pd.DataFrame(maj,  columns=degrees), inner="point", ax=ax[0][0])
        plots.plotMajHexagram(ax[0], maj)
    ax[1].set_title("Min")
    if (any(chromas.kinds == 'min') > 0):
        min = preprocessing.normalize(chromas.chromas[chromas.kinds == 'min'], norm='l1')
        #sns.violinplot(data=pd.DataFrame(min,  columns=degrees), inner="point", ax=ax[0][1])
        plots.plotMinHexagram(ax[1], min)
    ax[2].set_title("Dom")
    if (any(chromas.kinds == 'dom') > 0):
        dom = preprocessing.normalize(chromas.chromas[chromas.kinds == 'dom'], norm='l1')
        #sns.violinplot(data=pd.DataFrame(dom,  columns=degrees), inner="point", ax=ax[0][2])
        plots.plotDomHexagram(ax[2], dom)
    ax[3].set_title("Hdim7")
    if (any(chromas.kinds == 'hdim7') > 0):
        hdim7 = preprocessing.normalize(chromas.chromas[chromas.kinds == 'hdim7'], norm='l1')
        #sns.violinplot(data=pd.DataFrame(hdim7,  columns=degrees), inner="point", ax=ax[0][3])
        plots.plotHdim7Hexagram(ax[3], hdim7)
    ax[4].set_title("Dim")
    if (any(chromas.kinds == 'dim') > 0):
        dim = preprocessing.normalize(chromas.chromas[chromas.kinds == 'dim'], norm='l1')
        #sns.violinplot(data=pd.DataFrame(dim,  columns=degrees), inner="point", ax=ax[0][4])
        plots.plotDimHexagram(ax[4], dim)
    plt.tight_layout()
    plt.show()
def trainBasicChordGMM(chromaEvaluationParameters, basicGMMParameters,
                       jsonListFile):
    chromaEvaluator = ll.AnnotatedChromaEvaluator(chromaEvaluationParameters)
    gmms = list(
        map(
            lambda x: GaussianMixture(
                n_components=basicGMMParameters.nComponents[x],
                covariance_type=basicGMMParameters.covarianceTypes[x],
                max_iter=200,
                random_state=8), range(N_CHORD_KINDS)))
    gmm = BasicChordGMM(basicGMMParameters, gmms)
    gmm.fit(chromaEvaluator.loadChromasForAnnotationFileListFile(jsonListFile))
    return gmm
def findOptimalNComponentsByBIC(trainingChromaParams, f = 1, min_components=1, max_components=30):
    # gmm = chordModel.trainBasicChordGMM(trainingChromaParams, gmmParams, TRAIN_FILES_LIST_PATTERN.format(f))
    #gmm.saveModel(modelPattern.format(f))
    fig, ax = plt.subplots(nrows=3,ncols=2)
    ax = np.reshape(np.array(ax), (1, np.size(ax)))[0]
    res = np.zeros(chordModel.N_CHORD_KINDS)
    segments = ll.AnnotatedChromaEvaluator(trainingChromaParams). \
        loadChromasForAnnotationFileListFile(TRAIN_FILES_LIST_PATTERN.format(f))
    for i in range(chordModel.N_CHORD_KINDS):
        chordname = chordModel.CHORD_KINDS[i]
        samples = segments.chromas[segments.kinds ==chordname]
        bics = estimateBICs(samples,\
                           min_components=min_components,\
                           max_components=min(max_components, len(samples)))
        ax[i].set_title(chordname)
        ax[i].plot(bics)
        minIndex = np.argmin(bics)
        print(chordname, "BIC: ", bics[minIndex], " N: ", minIndex + 1)
        res[i] = minIndex + 1
    plt.show()
    return res
示例#4
0
def trainCV(trainingChromaParams):
    chromaEvaluator = ll.AnnotatedChromaEvaluator(trainingChromaParams)
    for f in FOLD_NUMBERS:
        chromas = chromaEvaluator.loadChromasForAnnotationFileListFile(TRAIN_FILES_LIST_PATTERN.format(f))
        betas = np.empty(N_CHORD_KINDS, dtype='object')
        partitions = np.empty(N_CHORD_KINDS, dtype='object')
        for k in xrange(N_CHORD_KINDS):
            chord = preprocessing.normalize(
                chordModel.substituteZeros(chromas.chromas[chromas.kinds == CHORD_KINDS[k]]), norm='l1')
            sortedDegrees = plots.sortedDegrees(chord, method='mean')
            #partition = [degrees.index(x) for x in sortedDegrees[0:len(sortedDegrees) / 2]]
            partition = [degrees.index(x) for x in sortedDegrees[0:7]]
            partitions[k] = partition
            a = plots.estimatePartition(partition, chord)
            params = beta.fit(a, floc=0, fscale=1)
            plt.hist(a, 60, normed=True)
            rv = beta(*params)
            betas[k] = rv
            #x = np.linspace(0, 1)
            #plt.plot(x, rv.pdf(x), lw=2)
            #plt.plot(x, rv.cdf(x), lw=2)
            #plt.show()
        model = Model2(partitions, betas)
        model.saveModel(MODEL_PATTERN.format(f))
示例#5
0
import plots
import lowLevelFeatures as ll
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import random
from sklearn import preprocessing
import matplotlib.pyplot as plt
from plots import degrees
import math
import chordModel
import numpy as np

cep = ll.ChromaEvaluationParameters(stepSize=2048, smoothingTime=1.2)
chromaEvaluator = ll.AnnotatedChromaEvaluator(cep)
chromas = chromaEvaluator.loadChromasForAnnotationFileListFile('ready.txt')
dMaj = pd.DataFrame(data=preprocessing.normalize(chromas.chromas[chromas.kinds == 'maj'], norm='l1'),  columns=degrees)
#g = sns.jointplot('VI', 'VII', dMaj, kind="kde")
maj = preprocessing.normalize(chromas.chromas[chromas.kinds == 'maj'], norm='l1')
fig, ax = plt.subplots()
plots.plotMajHexagram(ax, maj, 60)

# partition
partition = [degrees.index('I'), degrees.index('III'), degrees.index('V')]
a = plots.estimatePartition(partition, maj)
sns.distplot(a)
plt.show()

partition = [degrees.index('I'), degrees.index('II'), degrees.index('III'),  degrees.index('IV'), degrees.index('V'), degrees.index('VI'), degrees.index('VII')]
a = plots.estimatePartition(partition, maj)
sns.distplot(a)