Пример #1
0
from sam.math_util import avk, deriv_avk
from sam.optimize import check_grad

from sam.corpus.corpus import CorpusReader
from sam.vem.model import VEMModel

import sam.log as log

CORPUS_FILENAME = 'nips-425D.h5'

reader = CorpusReader(CORPUS_FILENAME, data_series='sam')
model = VEMModel(reader)

while True:
    model.run_one_iteration()
    model.print_topics()



def check_grads(model):
    assert np.isfinite(model.l_alpha())
    assert np.isfinite(model.l_valpha())

    x = model.grad_l_vmu()
    assert np.isfinite(x).all()

    import pdb
    try:
        # Main update rules
        log.info('xi update:', check_grad(model, 'xi', model.l_xi, model.grad_l_xi))
        log.info('valpha update:', check_grad(model, 'valpha', model.l_valpha, model.grad_l_valpha))