Esempio n. 1
0
    def run_test_data(self, epoch_data: NNData, one_hot=0) -> float:
        """
        Helper function. Runs testing pool example data through the input
        layer, and then compares the predicted values to the expected label
        values. Returns the root mean square error of the test run.

        Args:
            epoch_data (NNData): Object containing data set.
            one_hot: one hot encoding data

        Returns:
            rmse (float): Root mean squared error of the test run.
        """
        error = 0
        size = epoch_data.get_number_samples(NNData.Set.TEST)

        for _ in range(size):
            single_data = epoch_data.get_one_item(NNData.Set.TEST)
            self.send_data_to_inputs(single_data[0])
            self._visualize_x.append(single_data[0])
            self._visualize_y_nw.append(self.collect_outputs(one_hot))
            self._visualize_y.append(single_data[1])
            self.print_testing_data(single_data[0],
                                    self.collect_outputs(one_hot),
                                    single_data[1])
            error += self.calculate_error(single_data[1])
        return self.calculate_rmse(size, error)
Esempio n. 2
0
    def run_train_data(self, epoch_data: NNData, verbosity, epoch):
        """
        Helper function. Sends input data to the input layer, calculates
        the error from the output nodes against the expected values,
        and then sends the expected values to the output nodes to backprop
        through the network.

        Args:
            epoch_data (NNData): Object containing the data set.
            verbosity: how often to print epoch details
            epoch: current epoch

        Returns:
            The root mean squared error of the epoch. (float)
        """
        error = 0
        size = epoch_data.get_number_samples(NNData.Set.TRAIN)
        outputs = []
        labels = []
        for _ in range(size):
            single_data = epoch_data.get_one_item(NNData.Set.TRAIN)

            self.send_data_to_inputs(single_data[0])
            error += self.calculate_error(single_data[1])
            self.send_data_to_outputs(single_data[1])
            outputs.append(self.collect_outputs())
            labels.append(single_data[1])
        self.print_training_data(verbosity, epoch, outputs, labels,
                                 self.calculate_rmse(size, error))