Ejemplo n.º 1
0
 def sample(self, N, rule):
     """Sample from parameter distribution.
     
     **Parameters**
     
         **N:** [int] Number of samples.
         
         **rule:** [str] Sampling rule (e.g. "L" for latin hypercube sampling).
     """
     if not self._model: self._loadmodel()
     return J(*[i.distribution
                for i in self._params]).sample(N, rule).transpose()
Ejemplo n.º 2
0
 def sample(self, N, rule, uniform=False):
     """
     Return N samples from parameter distribution at given rule.
     
     Parameters
     ----------
     N : int
         Number of samples.
     rule : str
         Sampling rule.
     uniform=False : bool, optional
         Whether to assume a joint uniform distribution across parameter bounds. 
         Otherwise, sample from a joint distribution of all parameters.
     
     Notes
     -----
     Use the following ``rule`` flag for sampling:
     
     +-------+-------------------------------------------------+
     | key   | Description                                     |
     +=======+=================================================+
     | ``C`` | Roots of the first order Chebyshev polynomials. |
     +-------+-------------------------------------------------+
     | ``NC``| Chebyshev nodes adjusted to ensure nested.      |
     +-------+-------------------------------------------------+
     | ``K`` | Korobov lattice.                                |
     +-------+-------------------------------------------------+
     | ``R`` | Classical (Pseudo-)Random samples.              |
     +-------+-------------------------------------------------+
     | ``RG``| Regular spaced grid.                            |
     +-------+-------------------------------------------------+
     | ``NG``| Nested regular spaced grid.                     |
     +-------+-------------------------------------------------+
     | ``L`` | Latin hypercube samples.                        |
     +-------+-------------------------------------------------+
     | ``S`` | Sobol low-discrepancy sequence.                 |
     +-------+-------------------------------------------------+
     | ``H`` | Halton low-discrepancy sequence.                |
     +-------+-------------------------------------------------+
     | ``M`` | Hammersley low-discrepancy sequence.            |
     +-------+-------------------------------------------------+
         
     """
     if not self._update: self._load_parameters()
     parameters = self._parameters
     if uniform:
         distributions = [Uniform(*i.bounds) for i in parameters]
     else:
         distributions = [i.distribution for i in parameters]
     return J(*distributions).sample(N, rule).transpose()
Ejemplo n.º 3
0
 def sample(self, N, rule):
     """Return N samples from parameter distribution at given rule.
     
     Parameters
     ----------
     N : int
         Number of samples.
     rule : str
            Sampling rule.
     
     Notes
     -----
     Use the following ``rule`` flag for sampling:
     
     +-------+-------------------------------------------------+
     | key   | Description                                     |
     +=======+=================================================+
     | ``C`` | Roots of the first order Chebyshev polynomials. |
     +-------+-------------------------------------------------+
     | ``NC``| Chebyshev nodes adjusted to ensure nested.      |
     +-------+-------------------------------------------------+
     | ``K`` | Korobov lattice.                                |
     +-------+-------------------------------------------------+
     | ``R`` | Classical (Pseudo-)Random samples.              |
     +-------+-------------------------------------------------+
     | ``RG``| Regular spaced grid.                            |
     +-------+-------------------------------------------------+
     | ``NG``| Nested regular spaced grid.                     |
     +-------+-------------------------------------------------+
     | ``L`` | Latin hypercube samples.                        |
     +-------+-------------------------------------------------+
     | ``S`` | Sobol low-discrepancy sequence.                 |
     +-------+-------------------------------------------------+
     | ``H`` | Halton low-discrepancy sequence.                |
     +-------+-------------------------------------------------+
     | ``M`` | Hammersley low-discrepancy sequence.            |
     +-------+-------------------------------------------------+
         
     """
     if not self._update: self._loadparams()
     return J(*[i.distribution
                for i in self._params]).sample(N, rule).transpose()
Ejemplo n.º 4
0
"""
Created: Fri Jul 26 09:57:16 2019
@author: Christopher Albert <*****@*****.**>
"""

import time

from chaospy import Normal, J, generate_quadrature

params = [Normal(mu=0.999,  sigma=0.0052), 
          Normal(mu=27.1,   sigma=17.0), 
          Normal(mu=0.318,  sigma=0.1),
          Normal(mu=0.015,  sigma=0.0087),
          Normal(mu=0.0817, sigma=0.0077),
          Normal(mu=1.309,  sigma=0.086),
          Normal(mu=2.19,   sigma=0.22)]

dist = J(*params)
#%%
t = time.time()
nodes, weights = generate_quadrature(4, dist, rule='G', sparse=True)
print('time elapsed: {} s'.format(time.time() - t))
Ejemplo n.º 5
0
      pickle.dump(approx, filehandler)

#%%
indata = np.load('indata.npy')
outdata = np.load('outdata.npy')
with open('pce.pickle', 'rb') as filehandler:
  approx = pickle.load(filehandler)

params = OrderedDict()
data = np.genfromtxt('params_1998.txt', dtype=None, encoding=None)
for param in data:
    if(param[1] == 'Normal'):
        params[param[0]] = Normal(param[2], param[3])

#%%
distribution = J(*params.values())

#%%
F0 = E(approx, distribution)
dF = Std(approx, distribution)

#%%
F0[0] = F0[1]
dF[0] = dF[1]
plt.plot(np.arange(len(F0))-38, F0, 'k')
plt.fill_between(np.arange(len(F0))-38,F0-dF, F0+dF, color='k', alpha=0.3)
plt.ylim(-100,200)
plt.xlabel('t')
plt.ylabel('f(t)')
plt.show()