sample_query_blocks = np.zeros_like(tr_block[0:num_samples, :].reshape(num_samples, -1))
        else:
            # i+1 time: we set the previous mpe values as evidence
            mpe_query_blocks = np.zeros_like(np.array(tr_block[0:num_mpes, :].reshape(num_mpes, -1)))
            mpe_query_blocks[:, -(mpe_result.shape[1]) :] = mpe_result

            sample_query_blocks = np.zeros_like(np.array(tr_block[0:num_samples, :].reshape(num_samples, -1)))
            sample_query_blocks[:, -(sample_result.shape[1]) :] = sample_result

        cspn_mpe_query = set_sub_block_nans(mpe_query_blocks, inp=block_idx, nans=block_idx[0:conditional_blocks])
        mpe_result = mpe(cspn, cspn_mpe_query)

        mpe_img_blocks = stitch_imgs(
            mpe_result.shape[0], img_size=img_size, num_blocks=num_blocks, blocks={tuple(block_idx): mpe_result}
        )

        cspn_sample_query = set_sub_block_nans(sample_query_blocks, inp=block_idx, nans=block_idx[0:conditional_blocks])
        sample_result = sample_instances(cspn, cspn_sample_query, RandomState(123))

        sample_img_blocks = stitch_imgs(
            sample_result.shape[0], img_size=img_size, num_blocks=num_blocks, blocks={tuple(block_idx): sample_result}
        )

        for j in range(num_mpes):
            mpe_fname = output_path + "mpe_%s_%s.png" % ("-".join(map(str, block_idx)), j)
            save_img(mpe_img_blocks[j], mpe_fname)

        for j in range(num_samples):
            sample_fname = output_path + "sample_%s_%s.png" % ("-".join(map(str, block_idx)), j)
            save_img(sample_img_blocks[j], sample_fname)
Exemple #2
0
        n_instances_per_class, -1)
    num5 = images[labels_tr == 5][:n_instances_per_class].reshape(
        n_instances_per_class, -1)

    num3_img = stitch_imgs(
        imgs=1,
        img_size=(28 * blocks, 28 * blocks),
        num_blocks=(blocks, blocks),
        blocks={
            i: num3[i, :].reshape(28, 28)
            for i in range(n_instances_per_class)
        },
    )

    save_img(
        num3_img[0],
        "/Users/alejomc/PycharmProjects/SimpleSPN/src/spn/experiments/conditional/num3.png"
    )

    num5_img = stitch_imgs(
        imgs=1,
        img_size=(28 * blocks, 28 * blocks),
        num_blocks=(blocks, blocks),
        blocks={
            i: num5[i, :].reshape(28, 28)
            for i in range(n_instances_per_class)
        },
    )

    save_img(
        num5_img[0],
        "/Users/alejomc/PycharmProjects/SimpleSPN/src/spn/experiments/conditional/num5.png"