Exemple #1
0
def test_multi_convolutional_feature_map_fprop():
    cplane1 = ConvolutionalPlane((5, 5), (20, 20), bias=False)
    cplane2 = ConvolutionalPlane((5, 5), (20, 20), bias=False)
    sigmoid = TanhSigmoid((16, 16), bias=True)
    mfmap = MultiConvolutionalFeatureMap((5, 5), (20, 20), 2)
    mfmap.initialize()
    cplane1.params[:] = mfmap.planes[0].params
    cplane2.params[:] = mfmap.planes[1].params
    sigmoid.params[:] = mfmap.params[0:1]
    inputs1 = random.normal(size=(20, 20))
    inputs2 = random.normal(size=(20, 20))
    control = sigmoid.fprop(cplane1.fprop(inputs1) + cplane2.fprop(inputs2))
    mfmap_out = mfmap.fprop([inputs1, inputs2])
    assert_array_almost_equal(control, mfmap_out)
Exemple #2
0
 def __init__(self,
              fsize,
              imsize,
              num,
              inner=TANH_INNER,
              outer=TANH_OUTER,
              **kwargs):
     """
     Construct a MultiConvolutionalFeatureMap.
     
     All parameters are as in ConvolutionalFeatureMap; num is the
     number of planes this MCFM has (and the length of the list
     that fprop, bprop and grad expect for the "inputs" argument).
     """
     # Filter size times the number of filters, plus a bias
     filter_elems = np.prod(fsize)
     nparams = filter_elems * num + 1
     outsize = ConvolutionalPlane.outsize_from_imsize_and_fsize(
         imsize, fsize)
     super(MultiConvolutionalFeatureMap, self).__init__(outsize,
                                                        True,
                                                        nparams=nparams,
                                                        **kwargs)
     self.planes = []
     assert num > 0
     for index in xrange(num):
         param_range = slice(1 + (filter_elems * index),
                             1 + (filter_elems * (index + 1)))
         thisparam = self.params[param_range]
         thisgrad = self._grad[param_range]
         thisplane = ConvolutionalPlane(fsize,
                                        imsize,
                                        params=thisparam,
                                        grad=thisgrad,
                                        bias=False)
         self.planes.append(thisplane)
     self._out_array = np.empty(outsize)
Exemple #3
0
 def __init__(self, fsize, imsize):
     """Construct a feature map with given filter size and image size."""
     super(NaiveConvolutionalFeatureMap, self).__init__()
     self.convolution = ConvolutionalPlane(fsize, imsize)
     self.nonlinearity = TanhSigmoid(self.convolution.outsize)
Exemple #4
0
def test_convolutional_plane_params_gradient_no_bias():
    module = ConvolutionalPlane((5, 5), (20, 20), bias=False)
    module.initialize()
    inputs = random.normal(size=(20, 20))
    params = random.normal(size=len(module.params))
    check_parameter_gradient(module, inputs, params)