Revision 4f75faeded2cb284dedbc856a8b2ae56075ea158 authored by Collin Capano on 20 June 2020, 18:27:09 UTC, committed by GitHub on 20 June 2020, 18:27:09 UTC
* use different acl for every chain in epsie

* create base burn in class, move common functions to there; rename MCMCBurnInTests EnsembleMCMC, first stab at creating MCMC tests for independent chains

* more changes to burn in module

* simplify the attributes in the burn in classes

* add write method to burn in classes

* add write_data method to base_hdf

* remove write_burn_in method from mcmc io; use the write method in burn in module instead

* make use of new burn in functions in sampler/base_mcmc

* have emcee and emcee pt use ensemble burn in tests

* add compute_acf function to epsie

* start separating ensemble and mcmc io methods

* stop saving thin settings to file; just return on the fly

* make read/write samples stand alone functions, and update emcee

* rename write functions; update emcee

* move multi temper read/write functions to stand alone and update emcee_pt

* pass kwargs from emcee(_pt) io functions

* simplify get_slice method

* add function to base_mcmc to calculate the number of samples in a chain

* use nsamples_in_chain function to calculate effective number of samples

* add read_raw_samples function that can handle differing number of samples from different chains

* add forgotten import

* use write/read functions from base_multitemper in epsie io

* use stand alone functions for computing ensemble acf/acls

* separate out ensemble-specific attributes in sampler module; update emcee and emcee_pt

* add acl and effective_nsample methods to epsie

* simplify writing acls and burn in

* fix various bugs and typos

* use a single function for writing both acl and raw_acls

* add some more logging info to burn in

* reduce identical blocks of code in burn in module

* fix self -> fp in read_raw_samples

* reduce code duplication in base io and simplify read raw samples function

* fix missed rename

* reduce code redundacy in sampler/base_multitemper

* whitespace

* fix bugs and typos in burn_in module

* fix code climate issues

* use map in compute_acl

* more code climate fixes

* remove unused variable; try to silence pylint

* fix issues reading epsie samples

* only load samples from burned in chains by default

* add act property to mcmc files

* fix act logging message

* fix effective number of samples calculation in epsie

* remap walkers option to chains for reading samples

* fix thinning update

* fix acceptance ratio and temperature data thinning in epsie

* allow for different fields to have differing number of temperatures when loading

* don't try to figure out how many samples will be loaded ahead of time

* store acts in file instead of acls

* write burn in status to file before computing acls

* drop write_acts function

* fix issue with getting specific chains

* fix typo

* code climate issues

* fix plot_acl
1 parent 926b628
Raw File
test_resample.py
# Copyright (C) 2012  Alex Nitz, Josh Willis
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

#
# =============================================================================
#
#                                   Preamble
#
# =============================================================================
#
"""
These are the unittests for the pycbc.filter.matchedfilter module
"""
import sys
import unittest
from pycbc.types import *
from pycbc.filter import *
from pycbc.scheme import *
from utils import parse_args_all_schemes, simple_exit
from numpy.random import uniform
import scipy.signal
from pycbc.filter.resample import lfilter

_scheme, _context = parse_args_all_schemes("Resampling")

class TestUtils(unittest.TestCase):
    def setUp(self,*args):
        self.scheme = _scheme
        self.context = _context
        self.delta_t = 1.0 / 4096
        self.target_delta_t = 1.0 / 1024
        self.a = TimeSeries([1,2,3,4], delta_t=self.delta_t, dtype=float32)
        self.b = TimeSeries([1,2,3,4], delta_t=self.delta_t, dtype=float64)
        self.c = TimeSeries([1,2,3,4], delta_t=self.delta_t, dtype=complex64)
        self.d = Array([1,2,3,4], dtype=float32)

    if _scheme == 'cpu':
        def test_resample_float32(self):
            ra = resample_to_delta_t(self.a, self.target_delta_t)
            self.assertAlmostEqual(ra[0], 0.00696246)
            ra = resample_to_delta_t(self.a, self.delta_t)
            self.assertAlmostEqual(ra[0], 1)

        def test_resample_float64(self):
            rb = resample_to_delta_t(self.b, self.target_delta_t)
            self.assertAlmostEqual(rb[0], 0.00696246)
            rb = resample_to_delta_t(self.b, self.delta_t)
            self.assertAlmostEqual(rb[0], 1)

    def test_resample_errors(self):
        self.assertRaises(TypeError, resample_to_delta_t, self.c, self.target_delta_t)
        self.assertRaises(TypeError, resample_to_delta_t, self.d, self.target_delta_t)

        if self.scheme != 'cpu':
            with self.context:
                self.assertRaises(TypeError, resample_to_delta_t, self.a, self.target_delta_t)

    def test_lfilter(self):
        "Check our hand written lfilter"
        c = uniform(-10, 10, size=1024)
        ts = uniform(-1, 1, size=4323)

        ref = scipy.signal.lfilter(c, 1.0, ts)
        test = lfilter(c, ts)

        # These only agree where there is no fft wraparound
        # so excluded corrupted region from test
        ref = ref[len(c):]
        test = test[len(c):]

        maxreldiff =  ((ref - test) / ref).max()

        self.assertTrue(maxreldiff < 1e-7)

suite = unittest.TestSuite()
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestUtils))

if __name__ == '__main__':
    results = unittest.TextTestRunner(verbosity=2).run(suite)
    simple_exit(results)
back to top