Exemplo n.º 1
0
    def test_not_implemented_error(self):
        # Convert data to list
        values = self.data_single.tolist()

        # Create an object with links to the model and time series
        problem = pints.SingleOutputProblem(self.model_single, self.times,
                                            values)

        # Create error measure
        error = pints.NormalisedRootMeanSquaredError(problem)

        # Check that not implemented error is raised for evaluateS1
        self.assertRaisesRegex(NotImplementedError, '', error.evaluateS1, 1)
Exemplo n.º 2
0
    def test_call_two_dim_array_single(self):
        # Convert data to array of shape (n_times, 1)
        values = np.reshape(self.data_single, (self.n_times, 1))

        # Create an object with links to the model and time series
        problem = pints.SingleOutputProblem(self.model_single, self.times,
                                            values)

        # Create error measure
        error = pints.NormalisedRootMeanSquaredError(problem)

        # Evaluate likelihood for test parameters
        test_parameters = [3]
        score = error(test_parameters)

        # Check that error returns expected value
        # Expected = sqrt(mean((input - 1) ** 2)) / sqrt(mean(2 ** 2))
        self.assertEqual(score, 0.5)
Exemplo n.º 3
0
    def test_normalised_root_mean_squared_error(self):
        # Tests :class:`pints.NormalisedRootMeanSquaredError`.

        p = MiniProblem()
        e = pints.NormalisedRootMeanSquaredError(p)
        self.assertEqual(e.n_parameters(), 3)
        float(e([1, 2, 3]))
        self.assertEqual(e([-1, 2, 3]), 0)
        self.assertNotEqual(np.all(e([1, 2, 3])), 0)
        x = [0, 0, 0]
        y = 1.0
        self.assertEqual(e(x), y)
        x = [1, 1, 1]
        y = np.sqrt((4 + 1 + 4) / 3) / np.sqrt((1 + 4 + 9) / 3)
        self.assertAlmostEqual(e(x), y)

        p = MultiMiniProblem()
        self.assertRaisesRegex(
            ValueError,
            'This measure is only defined for single output problems.',
            pints.NormalisedRootMeanSquaredError, p)