Esempio n. 1
0
    def __init__(self,
                 size: int,
                 activation_function: ActivationFunction = ReLu(),
                 optimizer: Optimizer = Adam(),
                 name="Simple Layer"):
        self.name = name
        self.size = size
        self._activation_function = activation_function
        self._initialised = False

        # Unknown for now, gets updated then when self.initialize get called.
        self._previous_layer_size = 0

        # Parameters for the affine transformation from layer l-1 to layer l
        self.W = None
        self.b = np.zeros(
            size) + 0.001  # Initialization with a small magnitude

        # Last activation from previous layer
        self.a_lm1 = None

        # Last affine transformation of combination of inputs on this layer
        self.z_l = None

        # Error on this layer l
        self.delta_l = None

        # Last gradient
        self._last_d_W = 0
        self._last_d_b = 0

        # Optimizers for weights and biases
        self._W_optimizer = copy.deepcopy(optimizer)
        self._b_optimizer = copy.deepcopy(optimizer)
Esempio n. 2
0
    def __init__(self, size: int, activation_function: ActivationFunction = ReLu(), name="Simple Layer"):
        self.name = name
        self.size = size
        self._activation_function = activation_function
        self._initialised = False

        # Unknown for now, gets updated then when self.initialize get called.
        self._previous_layer_size = 0

        # Parameters for the affine transformation from layer l-1 to layer l
        self.W = None
        self.b = np.zeros(size) + 0.001  # Initialization with a small magnitude

        # Last activation from previous layer
        self.a_lm1 = None

        # Last affine transformation of combination of inputs on this layer
        self.z_l = None

        # Error on this layer l
        self.delta_l = None

        # Last gradient
        self._last_d_W = 0
        self._last_d_b = 0

        # Adam parameters
        self.eps = 10 ** (-8)
        self.t = 1
        self.beta1_w = 0.9
        self.beta2_w = 0.999
        self.m_w = 0
        self.v_w = 0

        self.beta1_b = 0.9
        self.beta2_b = 0.999
        self.m_b = 0
        self.v_b = 0
Esempio n. 3
0
 def __init__(self, size: int):
     super().__init__(size, activation_function=ReLu(), name="SimpleMSEOutputLayer")
Esempio n. 4
0
    y_test = y_test.astype(int)

    return x_train, y_train, x_test, y_test


if __name__ == "__main__":
    # Loading data
    data_folder = "../data"  # set your own value
    x_train, y_train, x_test, y_test = load_sets(data_folder)
    y_train = one_hot(y_train)
    y_test = one_hot(y_test)

    # Defining the network
    network = Network(input_size=14, name="14-100-40-4 Arch")

    network.stack(Layer(size=100, activation_function=ReLu()))
    network.stack(Layer(size=40, activation_function=ReLu()))

    network.output(SoftMaxCrossEntropyOutputLayer(size=4))

    # Printing information
    print(network)

    # Defining a log file
    current_datetime = strftime("%Y-%m-%d-%H:%M:%S", gmtime())
    logs_folder = os.path.join("..", "logs")
    out_file = os.path.join(
        logs_folder, f"benchmark_{network.name}-{current_datetime}.csv")

    # Benchmarking the network
    logger = network.benchmark(x_train,