How to use the xenonpy.utils.math.Product function in xenonpy

To help you get started, we’ve selected a few xenonpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yoshida-lab / XenonPy / tests / utils / test_product.py View on Github external
def test_product_1(data):
    abcd = list(product(*data))
    p = Product(*data)
    assert p.size == len(abcd), 'should have same length'
    assert p[0] == abcd[0]
    assert p[1] == abcd[1]
    assert p[3] != abcd[4]
    assert p[10] == abcd[10]
    assert p[22] == abcd[22]
    assert p[33] == abcd[33]

    with pytest.raises(IndexError):
        p[36]
github yoshida-lab / XenonPy / tests / utils / test_product.py View on Github external
def test_product_3(data):
    abcd = list(product(data[0], repeat=1))
    p = Product(data[0], repeat=1)
    assert p.size == len(abcd), 'should have same length'
    assert p[0] == abcd[0]
    assert p[1] == abcd[1]
    assert p[2] == abcd[2]
github yoshida-lab / XenonPy / tests / utils / test_product.py View on Github external
def test_product_5(data):
    abcd = list(product(product(*data), repeat=2))
    p = Product(Product(*data), repeat=2)
    assert p.size == len(abcd), 'should have same length'
    assert p[0] == abcd[0]
    assert p[1] == abcd[1]
    assert p[50] != abcd[55]
    assert p[333] == abcd[333]
    assert p[555] == abcd[555]
    assert p[666] != abcd[777]
github yoshida-lab / XenonPy / tests / utils / test_product.py View on Github external
def test_product_4(data):
    abcd = list(product(data[0], repeat=3))
    p = Product(data[0], repeat=3)
    assert p.size == len(abcd), 'should have same length'
    assert p[0] == abcd[0]
    assert p[1] == abcd[1]
    assert p[3] != abcd[4]
    assert p[5] == abcd[5]
    print(p.paras)
github yoshida-lab / XenonPy / tests / utils / test_product.py View on Github external
def test_product_2(data):
    with pytest.raises(ValueError):
        Product(data[0], repeat=1.5)
github yoshida-lab / XenonPy / xenonpy / model / nn / model_maker.py View on Github external
iterable
            Random models as generator.
            Can be access with :func:`next()` or ``for ... in models`` statement.

        Examples
        --------
        >>> from  math import ceil
        >>> from random import uniform
        >>> scheduler = lambda index, pars: dict(paras, n_out=ceil(paras['n_out'] * uniform(0.5, 0.8)))
        """
        from numpy.random import choice
        named_paras = ['n_in', 'n_out', 'drop_out', 'layer_func', 'act_func', 'batch_nor']
        layer = namedtuple('LayerParas', named_paras)

        if scheduler is None:
            all_ = Product(self.layer_var, repeat=hidden)
            all_size = self.layer_var.size ** hidden

            if n_models == 0:
                n_models = all_size
            if n_models > all_size and not replace:
                raise ValueError("larger sample than population({}) when 'replace=False'".format(all_size))

            # sampling all_
            samples = choice(all_size, n_models, replace).tolist()
            for i in samples:
                layer_paras = all_[i]

                # set layers
                layers = list()
                n_in = self.n_in
                for para in layer_paras:
github yoshida-lab / XenonPy / xenonpy / model / nn / model_maker.py View on Github external
act_func: [func]
            Activation functions. such like: :class:`torch.nn.ReLU`.
        batch_normalize: [bool]
            Batch Normalization. such like: :meth:`~.L1.batch_norm`.
        """
        self.output_layer = output_layer
        self.n_in, self.n_out = n_features, n_predict

        # save parameters
        self.drop_out = drop_out
        self.layer_func = layer_func
        self.act_func = act_func
        self.batch_normalize = batch_normalize

        # calculate layer's variety
        self.layer_var = Product(n_neuron, drop_out, layer_func, act_func, batch_normalize)