def test_batch_average(self): expected_error = 0.9 # or 225 / 250 actual_error = average_batch_errors([1, 1, 0.5], 250, 100) self.assertAlmostEqual(expected_error, actual_error) expected_error = 0.8 # or 240 / 300 actual_error = average_batch_errors([1, 1, 0.4], 300, 100) self.assertAlmostEqual(expected_error, actual_error)
def test_batch_average(self): expected_error = 0.9 # or 225 / 250 actual_error = average_batch_errors([1, 1, 0.5], 250, 100) self.assertAlmostEqual(expected_error, actual_error) expected_error = 0.8 # or 270 / 300 actual_error = average_batch_errors([1, 1, 0.4], 300, 100) self.assertAlmostEqual(expected_error, actual_error)
def prediction_error(self, input_data, target_data=None): """ Compute the pseudo-likelihood of input samples. Parameters ---------- input_data : array-like Values of the visible layer Returns ------- float Value of the pseudo-likelihood. """ is_input_feature1d = (self.n_visible == 1) input_data = format_data(input_data, is_input_feature1d) errors = self.apply_batches( function=self.methods.prediction_error, input_data=input_data, description='Validation batches', show_error_output=True, ) return average_batch_errors(errors, n_samples=len(input_data), batch_size=self.batch_size)
def prediction_error(self, input_data, target_data=None): """ Compute the pseudo-likelihood of input samples. Parameters ---------- input_data : array-like Values of the visible layer Returns ------- float Value of the pseudo-likelihood. """ is_input_feature1d = (self.n_visible == 1) input_data = format_data(input_data, is_input_feature1d) errors = self.apply_batches( function=self.methods.prediction_error, input_data=input_data, description='Validation batches', show_error_output=True, ) return average_batch_errors( errors, n_samples=len(input_data), batch_size=self.batch_size, )
def train_epoch(self, input_train, target_train=None): """ Train one epoch. Parameters ---------- input_train : array-like (n_samples, n_features) Returns ------- float """ errors = self.apply_batches( function=self.methods.train_epoch, input_data=input_train, description='Training batches', show_error_output=True, ) n_samples = len(input_train) return average_batch_errors(errors, n_samples, self.batch_size)