def test_save_and_load_model(self):
        pre_model = self.create_test_model()
        pre_model.train(iter=10000)
        p1 = pre_model.perplexity()
        pre_model.save()

        r = self.get_resource()
        post_model = GTopicModel.load(r.path)
        p2 = post_model.perplexity()
        self.assertTrue((p1 - p2) < 1e-5)
    # document (corpus)
    p = PickleResource(path)
    doc = p.load()
    training, test = doc.split(right_rate_or_size=0.3, compact=False)

    model = None
    perplexity = 1e5
    topics = [args.topics]
    if args.till:
        topics = range(args.topics, args.till + 1)

    for t in topics:
        print("topic count = {0}".format(t))
        for e in range(args.epoch):
            # make model
            m = GTopicModel(t, training, resource=r)
            m.train(iter=args.iter, burn=args.burn)
            p = m.perplexity(test)

            if p < perplexity:
                model = m
                perplexity = p

            print("\t epoch{0}: perplexity = {1}".format(e, p))

    print(
        "model is created. topics={0}, perplexity is {1}/{2} (training/test)".format(
            model.topic_count, model.perplexity(), model.perplexity(test))
    )

    model.save()