Example #1
0
def main():
    # create mrf problem:
    # two nodes, binary problem
    # potts potential
    pairwise = [[0, 1, 1], [1, 0, 1], [1, 1, 0]]
    import toy_datasets as toy
    X, Y = toy.generate_blocks_multinomial(n_samples=1, noise=.5)
    x, y = X[0], Y[0]
    inds = np.arange(x.shape[0] * x.shape[1]).reshape(x.shape[:2])
    inds = inds.astype(np.int64)
    horz = np.c_[inds[:, :-1].ravel(), inds[:, 1:].ravel()]
    vert = np.c_[inds[:-1, :].ravel(), inds[1:, :].ravel()]
    edges = np.vstack([horz, vert])
    x = x.reshape(-1, x.shape[-1])
    unary_assignment = solve_lp(-x, pairwise, edges)
    plt.matshow(np.argmax(unary_assignment, axis=1).reshape(y.shape))
    plt.show()
    tracer()
Example #2
0
import toy_datasets			as toy
import matplotlib.pyplot	as pyplot

from itertools import product

# Define constants
N = 1
size = 12
noise = 1.25

# Data generation
X, Y = toy.generate_blocks_multinomial(n_samples=N, noise=noise, n_rows=size, n_cols=size)

# Save files
pyplot.matshow(Y[0])
pyplot.xticks([])
pyplot.yticks([])
pyplot.savefig('figures/toy_label.svg', format='svg', bbox_inches=0)

pyplot.matshow(X[0,:,:,0])
pyplot.xticks([])
pyplot.yticks([])
pyplot.savefig('fugres/toy_feature_0.svg', format='svg', bbox_inches=0)

pyplot.matshow(X[0,:,:,1])
pyplot.xticks([])
pyplot.yticks([])
pyplot.savefig('figures/toy_feature_1.svg', format='svg', bbox_inches=0)
Example #3
0
import toy_datasets as toy
import matplotlib.pyplot as pyplot

from itertools import product

# Define constants
N = 1
size = 12
noise = 1.25

# Data generation
X, Y = toy.generate_blocks_multinomial(n_samples=N,
                                       noise=noise,
                                       n_rows=size,
                                       n_cols=size)

# Save files
pyplot.matshow(Y[0])
pyplot.xticks([])
pyplot.yticks([])
pyplot.savefig('figures/toy_label.svg', format='svg', bbox_inches=0)

pyplot.matshow(X[0, :, :, 0])
pyplot.xticks([])
pyplot.yticks([])
pyplot.savefig('fugres/toy_feature_0.svg', format='svg', bbox_inches=0)

pyplot.matshow(X[0, :, :, 1])
pyplot.xticks([])
pyplot.yticks([])
pyplot.savefig('figures/toy_feature_1.svg', format='svg', bbox_inches=0)