示例#1
0
文件: test_eee.py 项目: Mazzol/pyeee
    def test_eee_g(self):
        from functools import partial
        import numpy as np
        from pyeee import eee
        from pyeee.utils import func_wrapper
        from pyeee.functions import G

        # Function and parameters
        func = G
        npars = 6
        params = [78., 12., 0.5, 2., 97., 33.]  # G

        # Partialise function with fixed parameters
        arg = [params]
        kwarg = {}
        obj = partial(func_wrapper, func, arg, kwarg)

        # Screening
        lb = np.zeros(npars)
        ub = np.ones(npars)

        out = eee(obj,
                  lb,
                  ub,
                  mask=None,
                  ntfirst=self.ntfirst,
                  ntlast=self.ntlast,
                  nsteps=self.nsteps,
                  processes=1)

        # Check
        self.assertEqual(list(np.where(out)[0] + 1), [2, 3, 4, 6])
示例#2
0
文件: test_eee.py 项目: mcuntz/pyeee
    def test_eee_fmorris(self):
        from functools import partial
        import os
        import numpy as np
        from pyeee import eee
        from partialwrap import function_wrapper
        from pyjams.functions import fmorris

        # Function and parameters
        func = fmorris
        npars = 20
        beta0 = 0.
        beta1 = np.random.standard_normal(npars)
        beta1[:10] = 20.
        beta2 = np.random.standard_normal((npars, npars))
        beta2[:6, :6] = -15.
        beta3 = np.zeros((npars, npars, npars))
        beta3[:5, :5, :5] = -10.
        beta4 = np.zeros((npars, npars, npars, npars))
        beta4[:4, :4, :4, :4] = 5.

        # Partialise Morris function with fixed parameters beta0-4
        arg = [beta0, beta1, beta2, beta3, beta4]
        kwarg = {}
        obj = partial(function_wrapper, func, arg, kwarg)

        # Screening
        lb = np.zeros(npars)
        ub = np.ones(npars)

        # Check
        ff = open('tlog.txt', 'w')
        out = eee(obj,
                  lb,
                  ub,
                  mask=None,
                  ntfirst=self.ntfirst,
                  ntlast=self.ntlast,
                  nsteps=self.nsteps,
                  processes=4,
                  logfile=ff,
                  verbose=1)
        ff.close()

        self.assertEqual(list(np.where(out)[0] + 1),
                         [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 15, 20])
        self.assertTrue(os.path.exists('tlog.txt'))

        # Clean
        if os.path.exists('tlog.txt'):
            os.remove('tlog.txt')
示例#3
0
文件: test_eee.py 项目: mcuntz/pyeee
    def test_eee_fmorris_dist(self):
        from functools import partial
        import numpy as np
        import scipy.stats as stats
        from pyeee import eee
        from partialwrap import function_wrapper
        from pyjams.functions import fmorris

        # Function and parameters
        func = fmorris
        npars = 20
        beta0 = 0.
        beta1 = np.random.standard_normal(npars)
        beta1[:10] = 20.
        beta2 = np.random.standard_normal((npars, npars))
        beta2[:6, :6] = -15.
        beta3 = np.zeros((npars, npars, npars))
        beta3[:5, :5, :5] = -10.
        beta4 = np.zeros((npars, npars, npars, npars))
        beta4[:4, :4, :4, :4] = 5.

        # Partialise Morris function with fixed parameters beta0-4
        arg = [beta0, beta1, beta2, beta3, beta4]
        kwarg = {}
        obj = partial(function_wrapper, func, arg, kwarg)

        # Screening
        lb = np.zeros(npars)
        ub = np.ones(npars)
        dist = [stats.uniform for i in range(npars)]
        distparam = [(lb[i], ub[i] - lb[i]) for i in range(npars)]
        lb = np.zeros(npars)
        ub = np.ones(npars)

        # Check
        out = eee(obj,
                  lb,
                  ub,
                  mask=None,
                  ntfirst=self.ntfirst,
                  ntlast=self.ntlast,
                  nsteps=self.nsteps,
                  dist=dist,
                  distparam=distparam,
                  processes=4)

        self.assertEqual(list(np.where(out)[0] + 1),
                         [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 15, 20])
示例#4
0
文件: test_eee.py 项目: mcuntz/pyeee
    def test_eee_g_dist_mask(self):
        from functools import partial
        import numpy as np
        import scipy.stats as stats
        from pyeee import eee
        from partialwrap import function_wrapper
        from pyjams.functions import G

        # Function and parameters
        func = G
        npars = 6
        params = [78., 12., 0.5, 2., 97., 33.]  # G

        # Partialise function with fixed parameters
        arg = [params]
        kwarg = {}
        obj = partial(function_wrapper, func, arg, kwarg)

        # Screening
        lb = np.zeros(npars)
        ub = np.ones(npars)
        dist = [stats.uniform for i in range(npars)]
        distparam = [(lb[i], ub[i] - lb[i]) for i in range(npars)]
        lb = np.zeros(npars)
        ub = np.ones(npars)

        x0 = np.ones(npars) * 0.5
        mask = np.ones(npars, dtype=bool)
        mask[1] = False

        out = eee(obj,
                  lb,
                  ub,
                  x0=x0,
                  mask=mask,
                  ntfirst=self.ntfirst,
                  ntlast=self.ntlast,
                  nsteps=self.nsteps,
                  dist=dist,
                  distparam=distparam,
                  processes=1)

        # Check
        self.assertEqual(list(np.where(out)[0] + 1), [3, 4])
示例#5
0
文件: test_eee.py 项目: Mazzol/pyeee
    def test_eee_k(self):
        from functools import partial
        import os
        import numpy as np
        import schwimmbad
        from pyeee import eee
        from pyeee.utils import func_wrapper
        from pyeee.functions import bratley

        # Function and parameters
        func = bratley
        npars = 10
        params = []  # k

        # Screening
        lb = np.zeros(npars)
        ub = np.ones(npars)

        nprocs = 4
        ipool = schwimmbad.choose_pool(mpi=False, processes=nprocs)
        out = eee(func,
                  lb,
                  ub,
                  mask=None,
                  ntfirst=self.ntfirst,
                  ntlast=self.ntlast,
                  nsteps=self.nsteps,
                  processes=nprocs,
                  pool=ipool,
                  logfile='tlog.txt')
        ipool.close()

        # Check
        self.assertEqual(list(np.where(out)[0] + 1),
                         [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
        self.assertTrue(os.path.exists('tlog.txt'))

        # Clean
        if os.path.exists('tlog.txt'): os.remove('tlog.txt')