Пример #1
0
    def run_time(self, Vt, Wt=None, Zt=None, Ht=None, niter=5):
        self.time_analyzer.V = Vt
        if Wt is None or Zt is None or Ht is None:
            initW, initZ, initH = self.time_analyzer.initialize()
            if Wt is None: Wt = initW
            if Zt is None: Zt = initZ
            if Ht is None: Ht = initH

        for iter in xrange(niter):
            logprob, WZH = self.time_analyzer.do_estep(Wt, Zt, Ht)
            logger.info('Iteration t%d: logprob = %f', iter, logprob)
            Wt, Zt, Ht = self.time_analyzer.do_mstep(iter)
            assert Wt.ndim == 3
            assert Zt.ndim == 1
            assert Ht.ndim == 2

        # Ht : (rank, rank*F*T)
        # Ht_sum : (rank, F*T)
        meta_Ht = self.sum_pieces(Ht)

        Htt = meta_Ht.reshape(self.rank, self.f_steps, self.t_steps)
        Hmax = np.max(Htt)
        plt.clf()
        plt.imshow(np.rollaxis(Htt[0:3]/Hmax*2, 0, 3), origin='lower', aspect='auto', interpolation='nearest')
        plt.draw()
        
        meta_logprob, meta_WZH = self.meta_time_analyzer.do_estep(Wt, Zt, meta_Ht)
        logger.info('Meta t%d: logprob = %f', iter, logprob)
        meta_Wt, meta_Zt, meta_Ht = self.meta_time_analyzer.do_mstep(0)
        return Wt, Zt, Ht, meta_Ht
Пример #2
0
    def run_freq(self, Vf, Wf=None, Zf=None, Hf=None, niter=5):
        self.freq_analyzer.V = Vf
        if Wf is None or Zf is None or Hf is None:
            initW, initZ, initH = self.freq_analyzer.initialize()
            if Wf is None: Wf = initW
            if Zf is None: Zf = initZ
            if Hf is None: Hf = initH
        
        for iter in xrange(niter):
            logprob, WZH = self.freq_analyzer.do_estep(Wf, Zf, Hf)
            logger.info('Iteration f%d: logprob = %f', iter, logprob)
            Wf, Zf, Hf = self.freq_analyzer.do_mstep(iter)
            plt.clf()
            plt.plot(Wf[...,0])
            plt.draw()

        # Hf : (rank, F, rank*T)
        # Hf_sum : (rank, F, T)
        meta_Hf = self.sum_pieces(Hf)
        
        meta_logprob, meta_WZH = self.meta_freq_analyzer.do_estep(
          Wf, Zf, meta_Hf)
        logger.info('Meta f%d: logprob = %f', iter, logprob)
        meta_Wf, meta_Zf, meta_Hf = self.meta_freq_analyzer.do_mstep(0)
        return Wf, Zf, Hf, meta_Hf