Esempio n. 1
0
    def __init__(self,
                 cases=[1],
                 K=[5],
                 n_total=[1000],
                 n_samples=[[5, 5]],
                 b_true=[None],
                 w_true=[None],
                 num_results=[10e3],
                 baseline_index=None,
                 formula="x_0"):
        """
        constructor. Simulated Parameters are passed to the constructor as lists, except the type of model, which is fixed for all simulations.
        The simulation is carried out over all possible combinations of specified parameters.
        See the default values for examples

        Parameters
        ----------
        cases -- List
            Number of (binary) covariates
        K -- List
            Number of cell types
        n_total -- List
            number of cells per sample
        n_samples -- List
            number of samples. Each sublist specifies the number of samples for each covariate combination, length 2**cases
        b_true -- List
            Base composition. Each sublist has dimension K.
        w_true -- List
            Effect composition. Each sublist is a nested list that represents a DxK effect matrix
        num_results -- List
            MCMC chain length
        baseline_index -- int
            Index of reference cellltype (None for no baseline)
        formula -- str
            R-style formula used in model specification
        """

        # HMC Settings
        self.n_burnin = int(5e3)  # number of burn-in steps
        self.step_size = 0.01
        self.num_leapfrog_steps = 10

        # All parameter combinations
        self.simulation_params = list(
            itertools.product(cases, K, n_total, n_samples, b_true, w_true,
                              num_results))

        # Setup result objects
        self.mcmc_results = {}
        self.parameters = pd.DataFrame({
            'cases': [],
            'K': [],
            'n_total': [],
            'n_samples': [],
            'b_true': [],
            'w_true': [],
            'num_results': []
        })

        self.baseline_index = baseline_index
        self.formula = formula

        np.set_seed(1234)
Esempio n. 2
0
# limitations under the License.

from __future__ import print_function

import unittest
import numpy
import paddle.fluid as fluid
import paddle.fluid.layers as layers
import paddle.fluid.core as core
from paddle.fluid.contrib.layers import BasicLSTMUnit
from paddle.fluid.executor import Executor
from paddle.fluid import framework

import numpy as np

np.set_seed(123)

SIGMOID_THRESHOLD_MIN = -40.0
SIGMOID_THRESHOLD_MAX = 13.0
EXP_MAX_INPUT = 40.0


def sigmoid(x):
    y = np.copy(x)
    y[x < SIGMOID_THRESHOLD_MIN] = SIGMOID_THRESHOLD_MIN
    y[x > SIGMOID_THRESHOLD_MAX] = SIGMOID_THRESHOLD_MAX
    return 1. / (1. + np.exp(-y))


def tanh(x):
    y = -2. * x
Esempio n. 3
0
# %%
plt.plot()
film_deaths.IMDB_Rating.hist(bins=10)
plt.xlabel('IMBD_Rating')
plt.ylabel('Films Count')
plt.show()

# %%
imdb_mean = film_deaths.IMDB_Rating.mean()
imdb_std = film_deaths.IMDB_Rating.std()

print(f'IMDB mean = {imdb_mean:.3}, std = {imdb_std:.3}')

# %%
np.set_seed(42)
film_deaths['imdb_simulation'] = np.random.normal(loc=imdb_mean,
                                                  scale=imdb_std,
                                                  size=len(film_deaths))

plt.plot()

film_deaths.imdb_simulation.hist(bins=10)

plt.xlabel('IMDB_Rating (Simulation)')
plt.ylabel('Films Count (Simulation)')
plt.show()

# %%
from scipy.stats import probplot