Exemple #1
0
    def do_estep(self, Wf, Wt, Z, H):
        WZH = self.reconstruct(Wf, Wt, Z, H, circular=self.circular)
        logprob = self.compute_logprob(Wf, Wt, Z, H, WZH)

        WfZ = Wf * Z[newaxis,:]
        WtZ = Wt * Z[:,newaxis]

        VdivWZH = (self.V / (WZH + EPS))[:,:,newaxis]
        self.VRWf[:] = 0
        self.VRWt[:] = 0
        self.VRH[:] = 0
        for r in xrange(self.winF):
            WfZshifted = shift(WfZ, r, 0, self.circularF)
            for tau in xrange(self.winT):
                Hshifted = shift(H[:,r,:], tau, 1, self.circularT)
                ## Hshifted : (rank, T)
                ## tmp : (F, T, rank)
                ## Previously:
                # tmp = ((WZshifted[:,:,tau][:,:,newaxis]
                #         * Hshifted[newaxis,:,:]).transpose((0,2,1))
                #        * VdivWZH)
                WZtau = WfZshifted * WtZ[:,tau][newaxis,:] # (F, rank)
                tmp = Basilica.w_product(WZtau, Hshifted).transpose((0,2,1)) * VdivWZH
                self.VRWf += shift(tmp.sum(1), -r, 0, self.circularF)
                self.VRWt[:,tau] += tmp.sum(1).sum(0)
                self.VRH[:,:,r] += shift(tmp.sum(0), -tau, 0, self.circularT)

        return logprob, WZH
Exemple #2
0
def shift_key_to_zero(W, Z, H):
	newW = np.zeros(W.shape)
	newH = np.zeros(H.shape)
	for k in xrange(len(Z)):
		key_profile = H[k].sum(1)
		main_key = np.argmax(key_profile)
		newW[:,k] = plca.shift(W[:,k], main_key, axis=0, circular=True)
		newH[k] = plca.shift(H[k], -main_key, axis=0, circular=True)
	return newW, Z, newH
Exemple #3
0
def shift_key_to_zero(W, Z, H):
    newW = np.zeros(W.shape)
    newH = np.zeros(H.shape)
    for k in xrange(len(Z)):
        key_profile = H[k].sum(1)
        main_key = np.argmax(key_profile)
        newW[:, k] = plca.shift(W[:, k], main_key, axis=0, circular=True)
        newH[k] = plca.shift(H[k], -main_key, axis=0, circular=True)
    return newW, Z, newH
def find_downbeat(V, W):
    newW = W.copy()
    for k in xrange(W.shape[1]):
        Wlen = compute_effective_pattern_length(W[:,k,:])
        Wk = W[:,k,:Wlen]
        corr = np.array([_compute_summary_correlation(plca.shift(Wk, r, 1), V)
                         for r in xrange(Wlen)])
        bestshift = corr[:,Wlen:-Wlen].sum(1).argmin()
        print k, Wlen, bestshift
        newW[:,k,:Wlen] = plca.shift(Wk, bestshift, 1)
    return newW
def find_downbeat(V, W):
    newW = W.copy()
    for k in xrange(W.shape[1]):
        Wlen = compute_effective_pattern_length(W[:, k, :])
        Wk = W[:, k, :Wlen]
        corr = np.array([
            _compute_summary_correlation(plca.shift(Wk, r, 1), V)
            for r in xrange(Wlen)
        ])
        bestshift = corr[:, Wlen:-Wlen].sum(1).argmin()
        print k, Wlen, bestshift
        newW[:, k, :Wlen] = plca.shift(Wk, bestshift, 1)
    return newW
def find_downbeat_slow(V, W, Z, H, **kwargs):
    bopt = np.zeros(len(Z), dtype=int)
    nW = np.zeros(W.shape)
    nH = np.zeros(H.shape)
    for k in np.argsort(Z)[::-1]:
        Wlen = compute_effective_pattern_length(W[:, k, :])
        params = []
        logprobs = []
        for b in xrange(Wlen):
            initW = W
            initW[:, k, :Wlen] = plca.shift(W[:, k, :Wlen], b, axis=1)
            W, Z, H, norm, recon, logprob = plca.FactoredSIPLCA2.analyze(
                V,
                rank=len(Z),
                win=[H.shape[1], W.shape[-1]],
                niter=50,
                circular=[True, False],
                initW=initW,
                initH=np.ones(H.shape),
                initZ=Z,
                **kwargs)
            params.append((W, Z, H))
            logprobs.append(logprob)
            print b, logprobs[-1]
        bopt[k] = np.argmax(logprobs)
        W[:, k] = params[bopt[k]][0][:, k]
        nH[k] = params[bopt[k]][2][k]
    return bopt, W, Z, nH
def find_downbeat_slow(V, W, Z, H, **kwargs):
    bopt = np.zeros(len(Z), dtype=int)
    nW = np.zeros(W.shape)
    nH = np.zeros(H.shape)
    for k in np.argsort(Z)[::-1]:
        Wlen = compute_effective_pattern_length(W[:,k,:])
        params = []
        logprobs = []
        for b in xrange(Wlen):
            initW = W
            initW[:,k,:Wlen] = plca.shift(W[:,k,:Wlen], b, axis=1)
            W,Z,H,norm,recon,logprob = plca.FactoredSIPLCA2.analyze(
                V, rank=len(Z), win=[H.shape[1], W.shape[-1]],
                niter=50, circular=[True,False],
                initW=initW, initH=np.ones(H.shape), initZ=Z,
                **kwargs)
            params.append((W,Z,H))
            logprobs.append(logprob)
            print b, logprobs[-1]
        bopt[k] = np.argmax(logprobs)
        W[:,k] = params[bopt[k]][0][:,k]
        nH[k] = params[bopt[k]][2][k]
    return bopt, W, Z, nH