Пример #1
0
def test_Neuron():

    act_fun = lambda x: x * x
    act_der = lambda x: 2

    def init_fun(i):
        if i is -1:
            return 0.5
        else:
            return (i + 1)

    neuron = Neuron(
        dim_in=3,
        act_fun=act_fun,
        act_der=act_der,
        init_fun=init_fun,
    )
    neuron._test = True

    def output(vector):
        return act_fun(wsum(vector))

    def wsum(vector):
        return vector[0] + 2 * vector[1] + 3 * vector[2] + 0.5

    vector_1 = np.array([1, 2, 3])
    vector_2 = np.array([1, 0, 3])
    assert neuron.forward(vector_1) == output(vector_1)
    assert neuron.forward(vector_2) == output(vector_2)
    assert neuron.read_memory('input') == [vector_1, vector_2]
    assert neuron.read_memory('wsum') == [wsum(vector_1), wsum(vector_2)]
Пример #2
0
 def objectSizer(self, parentWindow):
     if not hasattr(self, '_sizer'):
         self._sizer = wx.FlexGridSizer(3, 2, 8, 8)
         self._sizer.SetFlexibleDirection(wx.HORIZONTAL)
         
         neuronImage = Neuron.image()
         if neuronImage == None:
             self._regionBitmap = wx.EmptyBitmap(16, 16)
         else:
             self._regionBitmap = wx.BitmapFromImage(neuronImage.Rescale(16, 16, wx.IMAGE_QUALITY_HIGH))
         
         
         self._sizer.Add(wx.StaticText(parentWindow, wx.ID_ANY, gettext('Sends output to region:')))
         self._sendsOutputChoice = wx.Choice(parentWindow, wx.ID_ANY)
         self._sendsOutputChoice.Append(gettext('Yes'), True)
         self._sendsOutputChoice.Append(gettext('No'), False)
         self._sendsOutputChoice.Append(gettext('Unknown'), None)
         self._multipleSendsOuputsId = wx.NOT_FOUND
         self._sizer.Add(self._sendsOutputChoice)
         parentWindow.Bind(wx.EVT_CHOICE, self.onChooseSendsOutput, self._sendsOutputChoice)
         
         self._sizer.Add(wx.StaticText(parentWindow, wx.ID_ANY, gettext('Receives input from region:')))
         self._receivesInputChoice = wx.Choice(parentWindow, wx.ID_ANY)
         self._receivesInputChoice.Append(gettext('Yes'), True)
         self._receivesInputChoice.Append(gettext('No'), False)
         self._receivesInputChoice.Append(gettext('Unknown'), None)
         self._multipleReceivesInputsId = wx.NOT_FOUND
         self._sizer.Add(self._receivesInputChoice)
         
         #add a neuron sizer
         self._sizer.Add(wx.StaticText(parentWindow, wx.ID_ANY, gettext('Neuron: ')))
         parentSizer = wx.BoxSizer(wx.HORIZONTAL)
         parentSizer.Add(wx.StaticBitmap(parentWindow, wx.ID_ANY, self._regionBitmap))
         self._parentNameField = wx.StaticText(parentWindow, wx.ID_ANY)
         parentSizer.Add(self._parentNameField, 1, wx.LEFT, 2)
         self._selectParentButton = wx.Button(parentWindow, wx.ID_ANY, gettext('Select'), style = wx.BU_EXACTFIT)
         self._selectParentButton.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)
         self._selectParentButton.SetSize(wx.Size(50, self._selectParentButton.GetSize().GetHeight()))
         self._selectParentButton.SetMinSize(self._selectParentButton.GetSize())
         self._window.Bind(wx.EVT_BUTTON, self.onSelectNeuron, self._selectParentButton)
         parentSizer.Add(self._selectParentButton, 0, wx.LEFT, 8)
         self._selectParentButton.Disable()
         self._sizer.Add(parentSizer)
         
         
         parentWindow.Bind(wx.EVT_CHOICE, self.onChooseReceievesInput, self._receivesInputChoice)
         
     return self._sizer
Пример #3
0
 def bitmap(cls):
     image = Neuron.image()
     if image == None:
         return None
     else:
         return wx.BitmapFromImage(image)
Пример #4
0
 def bitmap(cls):
     image = Neuron.image()
     if image == None:
         return None
     else:
         return wx.BitmapFromImage(image)