# first time, we only care about the structure to put nans
            mpe_query_blocks = np.zeros_like(tr_block[0:num_mpes, :].reshape(num_mpes, -1))
            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)
Esempio n. 2
0
            mpe_query_blocks = np.zeros_like(
                np.array(tr_block[0:10, :].reshape(10, -1)))
            mpe_query_blocks[:, -(mpe_result.shape[1]):] = mpe_result

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

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

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

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

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

        for c in range(10):
Esempio n. 3
0
    images = standardize(images)

    blocks = 45
    n_instances_per_class = blocks * blocks  # 2025

    print(np.unique(labels_tr, return_counts=True))
    num3 = images[labels_tr == 3][:n_instances_per_class].reshape(
        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={
Esempio n. 4
0
        else:
            # i+1 time: we set the previous mpe values as evidence
            mpe_query_blocks = np.zeros_like(np.array(tr_block[0:10, :].reshape(10, -1)))
            mpe_query_blocks[:, -(mpe_result.shape[1] - 10):] = mpe_result[:, 0:-10]

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




        cspn_mpe_query = np.concatenate((set_sub_block_nans(mpe_query_blocks, inp=block_idx, nans=[block_idx[0]]),
                                         np.eye(10, 10)), axis=1)
        mpe_result = mpe(cspn, cspn_mpe_query)

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

        cspn_sample_query = np.concatenate((set_sub_block_nans(sample_query_blocks, inp=block_idx, nans=[block_idx[0]]),
                                            np.eye(10, 10)),
                                           axis=1)
        sample_result = sample_instances(cspn, cspn_sample_query, RandomState(123))

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

        for c in range(10):
            mpe_fname = "imgs_pixelcspn_annotations/mpe_cspn_%s_class_%s.png" % ("".join(map(str, block_idx)), c)
            save_img(mpe_img_blocks[c], mpe_fname)

            sample_fname = "imgs_pixelcspn_annotations/sample_cspn_%s_class_%s.png" % ("".join(map(str, block_idx)), c)
            save_img(sample_img_blocks[c], sample_fname)