Exemplo n.º 1
0
def test_4():
    """Ensure that the basic conditions are satisfied by the multiattribute utility copula."""
    constr = dict()
    constr['version'] = 'scaled_archimedean'
    period = np.random.randint(1, 100)

    for _ in range(10):
        _, _, _, copula_spec = generate_random_request(constr)
        copula = UtilityCopulaCls(copula_spec)

        # Normalized range and domain
        np.testing.assert_equal(
            copula.evaluate(x=0, y=0, t=period, is_normalized=True), 0.0)
        np.testing.assert_equal(
            copula.evaluate(x=1, y=1, t=period, is_normalized=True), 1.0)

        # Nondecreasing in both arguments.
        v = np.random.uniform(0, 1, 2)
        base = copula.evaluate(*v, t=period, is_normalized=True)

        v_upper = []
        for item in v:
            v_upper += [np.random.uniform(item, 1)]
        np.testing.assert_equal(
            copula.evaluate(*v_upper, t=period, is_normalized=True) >= base,
            True)
Exemplo n.º 2
0
def test_3():
    """Ensure that linear transformations of the uniattribute utility functions...

    do not matter for the evaluation of the multiattribute utility copula.
    """
    constr = dict()
    constr['version'] = 'scaled_archimedean'
    period = np.random.randint(1, 100)

    for _ in range(10):
        x, y, is_normalized, copula_spec = generate_random_request(constr)

        copula = UtilityCopulaCls(copula_spec)
        base = copula.evaluate(x=x, y=y, t=period, is_normalized=is_normalized)

        for _ in range(10):
            copula_spec['a'] = np.random.uniform(0.01, 10)
            copula_spec['b'] = np.random.normal()

            copula = UtilityCopulaCls(copula_spec)
            np.testing.assert_almost_equal(
                base,
                copula.evaluate(x=x,
                                y=y,
                                t=period,
                                is_normalized=is_normalized))
Exemplo n.º 3
0
def test_1():
    """Ensure that a multiattribute utility function is always created."""
    for _ in range(10):
        x, y, is_normalized, copula_spec = generate_random_request()
        copula = UtilityCopulaCls(copula_spec)

        # Get all possible periods t that we can evaluate the copula at.
        periods = [0]
        if copula_spec['version'] == 'nonstationary':
            periods = copula_spec['nonstationary']['discount_factors'].keys()

        for period in periods:
            copula.evaluate(x=x, y=y, t=period, is_normalized=is_normalized)
Exemplo n.º 4
0
#!/usr/bin/env python
"""This script is a basic property testing setup."""
from copulpy.tests.test_auxiliary import generate_random_request
from copulpy.clsUtilityCopula import UtilityCopulaCls

for _ in range(10000):

    x, y, is_normalized, copula_spec = generate_random_request()
    version = copula_spec['version']

    if version in ['nonstationary', 'warmglow']:
        periods = copula_spec[version]['discount_factors'].keys()
    else:
        periods = [0]

    for period in periods:
        UtilityCopulaCls(copula_spec).evaluate(x, y, period, is_normalized)
Exemplo n.º 5
0
# from subprocess import CalledProcessError
# import pickle as pkl
# import subprocess
# import os

import numpy as np
# import pytest

from copulpy.tests.test_auxiliary import generate_random_request
from copulpy.clsUtilityCopula import UtilityCopulaCls
from copulpy.shared.auxiliary import distribute_copula_spec
# from copulpy.config_copulpy import PACKAGE_DIR
np.random.seed(123)

for _ in range(10):
    x, y, is_normalized, copula_spec = generate_random_request(
        {'version': 'nonstationary'})

    # copula_spec['marginals'] = ['exponential', 'exponential']
    # copula_spec['r'] = [-5, -5]
    # copula_spec['bounds'] = [500, 500]

    # print(is_normalized, 'out')
    copula = UtilityCopulaCls(copula_spec)
    util = copula.evaluate(x, y, is_normalized)

    alpha, beta, gamma, y_scale, version = \
        distribute_copula_spec(copula_spec, 'alpha', 'beta', 'gamma', 'y_scale', 'version')

    print('version: {}'.format(version))
    print('alpha: {0:.2f}, beta: {1:.2f}, gamma: {2:.2f}, y_scale: {3:.2f}'.
          format(alpha, beta, gamma, y_scale))