From d95c1714a939174693bd8da9199277241e61192a Mon Sep 17 00:00:00 2001 From: lmauviard Date: Fri, 6 Dec 2024 15:38:09 +0100 Subject: [PATCH] Moved the chi2 calculation to Signal.py --- xpsi/PostProcessing/_residual.py | 2 +- xpsi/Signal.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/xpsi/PostProcessing/_residual.py b/xpsi/PostProcessing/_residual.py index a34037d4..7f60c5ac 100644 --- a/xpsi/PostProcessing/_residual.py +++ b/xpsi/PostProcessing/_residual.py @@ -337,7 +337,7 @@ def add_pulses( self ): double_pulse_model = _np.concatenate( (pulse_model , pulse_model) ) # Compute the chi squared - chi2 = _np.sum( (pulse_data - pulse_model)**2 / pulse_model ) + chi2 = self._signal.chi2 # Plot pulse self._ax_pulse.errorbar(x=doubles_phases, diff --git a/xpsi/Signal.py b/xpsi/Signal.py index c2d579c5..bea5a442 100644 --- a/xpsi/Signal.py +++ b/xpsi/Signal.py @@ -733,6 +733,25 @@ def synthesise(self, phase_shifts, directory, **kwargs): """ raise NotImplementedError('Cannot synthesise data.') + + @property + def chi2( self ): + """ Return the chi2 value for the current likelihood value or a given parameter vector if required. + + :param list p: + Parameter vector, optional. + + """ + + # Get the pulse of data and model + pulse_data = self.data.counts.sum( axis = 0 ) + pulse_model = self.expected_counts.sum( axis = 0 ) + + # Compute the chi squared + chi2 = _np.sum( (pulse_data - pulse_model)**2 / pulse_model ) + + return chi2 + def construct_energy_array(num_energies, signals, max_energy=None):