def random_grid(sidelen, decoder_params, imshape, seed=None):
    rng = npr if seed is None else npr.RandomState(seed=seed)
    zdim = get_zdim(decoder_params)

    points = rng.randn(sidelen**2, zdim)
    imagevecs = points_to_imagevecs(points, decoder_params)
    return make_grid(sidelen, imagevecs, imshape)
def run_interactive(decoder_params, dims, limits):
    zdim = get_zdim(decoder_params)
    decode = numpy_gaussian_decoder(decoder_params)
    vec = np.zeros(zdim)

    def draw(x, y):
        vec[dims] = (x,y)
        return reshape_square(decode(vec))

    return Interactive(draw, draw(0,0), limits)
def run_interactive(decoder_params, dims, limits):
    zdim = get_zdim(decoder_params)
    decode = numpy_gaussian_decoder(decoder_params)
    vec = np.zeros(zdim)

    def draw(x, y):
        vec[dims] = (x,y)
        return reshape_square(decode(vec))

    return Interactive(draw, draw(0,0), limits)
def regular_grid(sidelen, decoder_params, imshape, limits=[-2,2,-2,2], axes=None,
                 corners=None, rand_scale=1., seed=None, decoder=None):
    if decoder is None:
        from vae import gaussian_decoder as decoder
    rng = npr if seed is None else npr.RandomState(seed=seed)
    zdim = get_zdim(decoder_params)

    if vecs is not None:
        v0, v1 = vecs
    elif axes is not None:
        v0, v1 = np.eye(zdim)[axes[0]], np.eye(zdim)[axes[1]]
    else:
        v0, v1 = np.linalg.qr(rng.randn(zdim, 2))[0].T

    x0, x1, y0, y1 = limits[0]*v0, limits[1]*v0, limits[2]*v1, limits[3]*v1
    interval = np.linspace(0, 1, sidelen, endpoint=True)
    regular_grid = lambda zdim: np.vstack(
            [(1-t)*x0 + t*x1 + (1-s)*y0 + s*y1 for t in interval for s in interval])
    imagevecs = points_to_imagevecs(regular_grid, decoder_params, decoder)
    return make_grid(sidelen, imagevecs, imshape)
def generate_samples(n, decoder_params):
    zdim = get_zdim(decoder_params)
    decode = gaussian_decoder(decoder_params)
    return decode(np.random.randn(n, zdim))[0].eval()