def test_cash(): import sherpa.stats as ss sherpa_stat = ss.Cash() data, model, staterror, off_vec = get_test_data() desired, fvec = sherpa_stat.calc_stat(data, model, staterror=staterror) statsvec = gammapy_stats.cash(n_on=data, mu_on=model) actual = np.sum(statsvec) assert_allclose(actual, desired)
def test_cash(test_data): import sherpa.stats as ss sherpa_stat = ss.Cash() data = test_data['n_on'] model = test_data['mu_sig'] staterror = test_data['staterror'] off_vec = test_data['n_off'] desired, fvec = sherpa_stat.calc_stat(data, model, staterror=staterror) statsvec = stats.cash(n_on=data, mu_on=model) actual = np.sum(statsvec) assert_allclose(actual, desired)
def test_case(args): import sherpa.stats as ss mu_sig = float(args[1]) n_on = float(args[2]) n_off = float(args[3]) alpha = float(args[4]) model, data = get_data(mu_sig, n_on, n_off, alpha) wstat, cash, cstat = ss.WStat(), ss.Cash(), ss.CStat() print('wstat: {}'.format(wstat.calc_stat(model=model, data=data)[0])) print('cash: {}'.format(cash.calc_stat(model=model, data=data)[0])) print('cstat: {}'.format(cstat.calc_stat(model=model, data=data)[0]))
def statistic(self, stat): """Set Statistic to be used in the fit Parameters ---------- stat : `~sherpa.stats.Stat`, str Statistic """ import sherpa.stats as s if isinstance(stat, six.string_types): if stat == 'cash': stat = s.Cash() elif stat == 'wstat': stat = s.WStat() else: raise ValueError("Undefined stat string: {}".format(stat)) if not isinstance(stat, s.Stat): raise ValueError("Only sherpa statistics are supported") self._stat = stat
# The pytest.param calls seem to get recorded as 2 xfails; I think # this is for the error and because of warning messages, but it is not # clear. # @requires_data @requires_fits @pytest.mark.parametrize("stat", [None, stats.Chi2(), stats.Chi2ConstVar(), stats.Chi2DataVar(), stats.Chi2Gehrels(), stats.Chi2ModVar(), stats.Chi2XspecVar(), stats.LeastSq(), stats.Cash(), stats.CStat(), stats.WStat()]) def test_astro_data_plot_with_stat_simple(make_data_path, stat): from sherpa.astro import io infile = make_data_path('3c273.pi') pha = io.read_pha(infile) # tweak the data set so that we aren't using the default # options (it shouldn't matter for this test but just # in case). # # Note that background subtraction would normally be an issue # for some of the stats (e.g. WStat), but this shouldn't