Esempio n. 1
0
def make_sparse_random_conv2D(num_nonzero, input_space, output_space,
        kernel_shape, batch_size, \
        kernel_stride = (1,1), border_mode = 'valid', message = "", rng=None):
    raise NotImplementedError("Not yet modified after copy-paste from "
                              "pylearn2.linear.conv2d")
    """ Creates a Conv2D with random kernels, where the randomly initialized
    values are sparse"""

    if rng is None:
        rng = default_sparse_rng()

    W = np.zeros(( output_space.num_channels, input_space.num_channels, \
            kernel_shape[0], kernel_shape[1]))

    def random_coord():
        return [rng.randint(dim) for dim in W.shape]

    for i in xrange(num_nonzero):
        o, ch, r, c = random_coord()
        while W[o, ch, r, c] != 0:
            o, ch, r, c = random_coord()
        W[o, ch, r, c] = rng.randn()

    W = sharedX(W)

    return Conv2D(filters=W,
                  batch_size=batch_size,
                  input_space=input_space,
                  output_axes=output_space.axes,
                  kernel_stride=kernel_stride,
                  border_mode=border_mode,
                  filters_shape=W.get_value(borrow=True).shape,
                  message=message)
Esempio n. 2
0
def make_sparse_random_local(num_nonzero, input_space, output_space,
        kernel_shape, batch_size, \
        kernel_stride = (1,1), border_mode = 'valid', message = "", rng=None):
    """
    .. todo::

        WRITEME
    """
    raise NotImplementedError("Not yet modified after copy-paste from "
            "pylearn2.linear.conv2d_c01b")
    """ Creates a Conv2D with random kernels, where the randomly initialized
    values are sparse"""

    if rng is None:
        rng = default_sparse_rng()

    W = np.zeros(( output_space.num_channels, input_space.num_channels, \
            kernel_shape[0], kernel_shape[1]))

    def random_coord():
        return [ rng.randint(dim) for dim in W.shape ]

    for i in xrange(num_nonzero):
        o, ch, r, c = random_coord()
        while W[o, ch, r, c] != 0:
            o, ch, r, c = random_coord()
        W[o, ch, r, c] = rng.randn()


    W = sharedX( W)
Esempio n. 3
0
def make_sparse_random_local(num_nonzero, input_space, output_space,
        kernel_shape, batch_size, \
        kernel_stride = (1,1), border_mode = 'valid', message = "", rng=None):
    """
    .. todo::

        WRITEME
    """
    raise NotImplementedError("Not yet modified after copy-paste from "
            "pylearn2.linear.conv2d_c01b")
    """ Creates a Conv2D with random kernels, where the randomly initialized
    values are sparse"""

    if rng is None:
        rng = default_sparse_rng()

    W = np.zeros(( output_space.num_channels, input_space.num_channels, \
            kernel_shape[0], kernel_shape[1]))

    def random_coord():
        return [ rng.randint(dim) for dim in W.shape ]

    for i in xrange(num_nonzero):
        o, ch, r, c = random_coord()
        while W[o, ch, r, c] != 0:
            o, ch, r, c = random_coord()
        W[o, ch, r, c] = rng.randn()


    W = sharedX( W)
Esempio n. 4
0
def make_sparse_random_conv2D(num_nonzero, input_space, output_space,
        kernel_shape, batch_size, \
        kernel_stride = (1,1), border_mode = 'valid', message = "", rng=None):
    raise NotImplementedError("Not yet modified after copy-paste from "
            "pylearn2.linear.conv2d")
    """ Creates a Conv2D with random kernels, where the randomly initialized
    values are sparse"""

    if rng is None:
        rng = default_sparse_rng()

    W = np.zeros(( output_space.num_channels, input_space.num_channels, \
            kernel_shape[0], kernel_shape[1]))

    def random_coord():
        return [ rng.randint(dim) for dim in W.shape ]

    for i in xrange(num_nonzero):
        o, ch, r, c = random_coord()
        while W[o, ch, r, c] != 0:
            o, ch, r, c = random_coord()
        W[o, ch, r, c] = rng.randn()


    W = sharedX( W)

    return Conv2D(filters = W,
        batch_size = batch_size,
        input_space = input_space,
        output_axes = output_space.axes,
        kernel_stride = kernel_stride, border_mode = border_mode,
        filters_shape = W.get_value(borrow=True).shape, message = message)
Esempio n. 5
0
def make_sparse_random_conv2D(num_nonzero, input_space, output_space,
        kernel_shape,
                pad = 0,
        kernel_stride = (1,1), border_mode = 'valid', message = "", rng=None,
        partial_sum = None):
    """ Creates a Conv2D with random kernels, where the randomly initialized
    values are sparse"""

    if rng is None:
        rng = default_sparse_rng()

    W = np.zeros((input_space.num_channels, \
            kernel_shape[0], kernel_shape[1],
            output_space.num_channels))

    def random_coord():
        return [rng.randint(dim) for dim in W.shape[0:3] ]

    for o in xrange(output_space.num_channels):
        for i in xrange(num_nonzero):
            ch, r, c = random_coord()
            while W[ch, r, c, o] != 0:
                ch, r, c = random_coord()
            W[ch, r, c, o] = rng.randn()

    W = sharedX(W)

    return Conv2D(filters = W,
        input_axes = input_space.axes,
        output_axes = output_space.axes,
        kernel_stride = kernel_stride, pad=pad,
        message = message, partial_sum=partial_sum)
Esempio n. 6
0
def make_sparse_random_conv2D(num_nonzero,
                              input_space,
                              output_space,
                              kernel_shape,
                              pad=0,
                              kernel_stride=(1, 1),
                              border_mode='valid',
                              message="",
                              rng=None,
                              partial_sum=None):
    """
    .. todo::

        WRITEME properly

    Creates a Conv2D with random kernels, where the randomly initialized
    values are sparse
    """

    if rng is None:
        rng = default_sparse_rng()

    W = np.zeros((input_space.num_channels, \
            kernel_shape[0], kernel_shape[1],
            output_space.num_channels))

    def random_coord():
        return [rng.randint(dim) for dim in W.shape[0:3]]

    for o in xrange(output_space.num_channels):
        for i in xrange(num_nonzero):
            ch, r, c = random_coord()
            while W[ch, r, c, o] != 0:
                ch, r, c = random_coord()
            W[ch, r, c, o] = rng.randn()

    W = sharedX(W)

    return Conv2D(filters=W,
                  input_axes=input_space.axes,
                  output_axes=output_space.axes,
                  kernel_stride=kernel_stride,
                  pad=pad,
                  message=message,
                  partial_sum=partial_sum)