Exemple #1
0
 def __init__(self, size):
     Layer.__init__(self, size)
     self.W = None
     self.b = np.random.rand(size, 1)
     self.z = None
     self.a = None
     self.x = None
Exemple #2
0
def test_layer_neighbors():
    """
      0 1 2
    0 . . .
    1 . n n
    2 . n x
  """
    n = set(Layer.each_neighbor(height=3, width=3, y=2, x=2))
    assert (1, 1) in n
    assert (1, 2) in n
    assert (2, 1) in n
    assert (2, 2) not in n
    assert (2, 3) not in n
    assert (3, 3) not in n
    assert (3, 2) not in n
    """
      0 1 2
    0 n n n
    1 n x n
    2 n n n
  """
    n2 = set(Layer.each_neighbor(height=3, width=3, y=1, x=1))
    assert (0, 0) in n2
    assert (0, 1) in n2
    assert (0, 2) in n2
    assert (1, 0) in n2
    assert (1, 1) not in n2
    assert (1, 2) in n2
    assert (2, 0) in n2
    assert (2, 1) in n2
    assert (2, 2) in n2
Exemple #3
0
 def __init__(self, layer):
     """
     Initializes the DNS layer.
     """
     Layer.__init__(self, layer)
     self.getters = {"qname": self.get_qname}
     self.generators = {"qname": self.gen_qname}
Exemple #4
0
 def __init__(self, name, input_dim, output_dim, collection_size, non_linearity='relu'):
     Layer.__init__(self, name=name,init_type='uniform', regularizable=True)
     self.non_linearity = NonLinearity(type=non_linearity)
     self.embeddings = Embeddings(name="emb_encoder", collection_size=collection_size, output_dim=input_dim)
     self.C = self.add_param(name="C", shape=(2*input_dim, output_dim), init_type=self.init_type,
                             regularizable=self.regularizable)
     # store additional params
     self.params = merge_ordered_dicts(self.embeddings.params, self.params)
 def __call__(self, previous_layer_shape, optimizer, calc_error=True):
     nH, nW = Layer.calc_output_shape(previous_layer_shape, self._size,
                                      self._stride)
     print(previous_layer_shape)
     num_of_channels = previous_layer_shape[2]
     self._error_shape = (-1, nH, nW, 1, 1, num_of_channels)
     self._output_shape = (nH, nW, num_of_channels)
     return self._output_shape
Exemple #6
0
 def __init__(self, layer):
     """
     Initializes the TCP layer.
     """
     Layer.__init__(self, layer)
     # Special methods to help access fields that cannot be accessed normally
     self.getters = {'load': self.get_load, 'options': self.get_options}
     self.setters = {'load': self.set_load, 'options': self.set_options}
     # Special methods to help generate fields that cannot be generated normally
     self.generators = {
         'load': self.gen_load,
         'dataofs': self.gen_dataofs,
         'flags': self.gen_flags,
         'chksum': self.gen_chksum,
         'options': self.gen_options,
         'window': self.gen_window
     }
Exemple #7
0
    def __init__(self, layer):
        """
        Initializes the DNS layer.
        """
        Layer.__init__(self, layer)

        self.getters = {
            "qr": self.get_bitfield,
            "aa": self.get_bitfield,
            "tc": self.get_bitfield,
            "rd": self.get_bitfield,
            "ra": self.get_bitfield,
            "z": self.get_bitfield,
            "ad": self.get_bitfield,
            "cd": self.get_bitfield
        }

        self.setters = {
            "qr": self.set_bitfield,
            "aa": self.set_bitfield,
            "tc": self.set_bitfield,
            "rd": self.set_bitfield,
            "ra": self.set_bitfield,
            "z": self.set_bitfield,
            "ad": self.set_bitfield,
            "cd": self.set_bitfield
        }

        self.generators = {
            "id": self.gen_id,
            "qr": self.gen_bitfield,
            "opcode": self.gen_opcode,
            "aa": self.gen_bitfield,
            "tc": self.gen_bitfield,
            "rd": self.gen_bitfield,
            "ra": self.gen_bitfield,
            "z": self.gen_bitfield,
            "ad": self.gen_bitfield,
            "cd": self.gen_bitfield,
            "rcode": self.gen_rcode,
            "qdcount": self.gen_count,
            "ancount": self.gen_count,
            "nscount": self.gen_count,
            "arcount": self.gen_count
        }
Exemple #8
0
 def __call__(self, previous_layer_shape, optimizer, calc_error=False):
     self._input_shape = previous_layer_shape
     num_of_channels = previous_layer_shape[2]
     self._weights = self._kernel_initializer((self._kernel[0], self._kernel[1],
                                               num_of_channels, self._num_of_filters))
     self._biases = self._bias_initializer((1, 1, 1, self._num_of_filters))
     self._optimizer = optimizer
     self._calc_error = calc_error
     nH, nW = Layer.calc_output_shape(previous_layer_shape, self._kernel, self._stride)
     self._output_shape = (nH, nW, self._num_of_filters)
     return self._output_shape
Exemple #9
0
    def __init__(self,
                 name,
                 input_dim,
                 output_dim,
                 non_linearity='linear',
                 init_type='uniform',
                 regularizable=True):
        """
        A simple fully connected layer that performs affine transformations following by a non-linearity.

        """
        Layer.__init__(self, name)
        self.non_linearity = NonLinearity(type=non_linearity)
        self.W = self.add_param(name="W",
                                shape=(input_dim, output_dim),
                                init_type=init_type,
                                regularizable=regularizable)
        self.b = self.add_param(name="b",
                                shape=(output_dim, ),
                                init_type='zeros')
Exemple #10
0
        def _clear(y, x, height, width, cells, mines_layer):

            cells[y][x] = -1

            if mines_layer.cell_at(y, x) > 0:
                # don't check anymore spots if we hit a spot that borders a mine
                return
            for ny, nx in Layer.each_neighbor(y=y, x=x, width=width, height=height):
                if cells[ny][nx] in [-1, 1]:
                    continue
                _clear(ny, nx, height, width, cells, mines_layer)
Exemple #11
0
 def __init__(self, layer):
     """
     Initializes the IP layer.
     """
     Layer.__init__(self, layer)
     self.getters = {
         "flags" : self.get_flags,
         "load"  : self.get_load
     }
     self.setters = {
         "flags" : self.set_flags,
         "load"  : self.set_load
     }
     self.generators = {
         "src"    : self.gen_ip,
         "dst"    : self.gen_ip,
         "chksum" : self.gen_chksum,
         "len"    : self.gen_len,
         "load"   : self.gen_load,
         "flags"  : self.gen_flags
     }
Exemple #12
0
 def __init__(self, name, collection_size, output_dim, **kwargs):
     Layer.__init__(self, name=name, **kwargs)
     self.collection_size = collection_size
     self.output_dim = output_dim
     self.W = self.add_param("W", shape=(collection_size, output_dim), init_type=self.init_type,
                             regularizable=self.regularizable)
Exemple #13
0
 def __init__(self, is_classifier, prev_layer):
     Layer.__init__(self, prev_layer)
     self.is_classifier = is_classifier
     self.out_shape = (1, )
     self.output = None
     self.prob = None
Exemple #14
0
 def __init__(self, prev_layer):
   Layer.__init__(self, prev_layer)
   self.out_shape = (1,)
   self.output = None
   self.prob = None
Exemple #15
0
def test_layer_choices():
    layer = Layer(height=3, width=3, default=0, choices={(1, 1): 5, (1, 2): 4})
    assert layer.raw_cells() == [[0, 0, 0], [0, 5, 4], [0, 0, 0]]
Exemple #16
0
 def __init__(self, is_classifier, prev_layer):
   Layer.__init__(self, prev_layer)
   self.is_classifier = is_classifier
   self.out_shape = (1,)
   self.output = None
   self.prob = None