Example #1
0
def test_interval():

    tol = 1e-3
    I_integral_ideal = [0.77272105923056, 46.639683900497, 6.80452330242669]
    I_terminal_ideal = 8.99891199975
    phase_errors_ideal = [34784.1137839443, 5.62296778644782e-07, 0.0]
    controller_variance_ideal = [4.0, 0.0, 0.0]
    terminal_error = 1e-3

    parameters = {
        'u1_0': Interval.from_value(5),
        'u1_1': Interval.from_value(6),
        'u1_2': Interval.from_value(7),
        'u2_0': Interval.from_value(2),
        'u2_1': Interval.from_value(2),
        'u2_2': Interval.from_value(2),
        'u2_3': Interval.from_value(2),
        'a': Interval.from_value(5)
    }

    error = core.request('sim', parameters).middle_point

    assert math.fabs(error - (sum(I_integral_ideal) + I_terminal_ideal +
                              terminal_error + sum(phase_errors_ideal) +
                              sum(controller_variance_ideal))) < tol
Example #2
0
def test_interval(client):

    tol = 1e-3
    I_integral_ideal = [0.77272105923056, 46.639683900497, 6.80452330242669]
    I_terminal_ideal = 8.99891199975
    phase_errors_ideal = [34784.1137839443, 5.62296778644782e-07, 0.0]
    controller_variance_ideal = [4.0, 0.0, 0.0]
    terminal_error = 1e-3

    parameters = {
        'u1_0': Interval.from_value(5),
        'u1_1': Interval.from_value(6),
        'u1_2': Interval.from_value(7),
        'u2_0': Interval.from_value(2),
        'u2_1': Interval.from_value(2),
        'u2_2': Interval.from_value(2),
        'u2_3': Interval.from_value(2),
        'a': Interval.from_value(5)
    }

    url = '/process_request?field=sim&scope=interval'
    for k, v in parameters.items():
        url += '&{0}={1}'.format(k, json.dumps(v))

    response = client.get(url)
    error = Interval.from_dict(json.loads(response.data)).middle_point

    assert response.status_code == 200
    assert math.fabs(error - (sum(I_integral_ideal) + I_terminal_ideal +
                              terminal_error + sum(phase_errors_ideal) +
                              sum(controller_variance_ideal))) < tol
Example #3
0
def test_interval_df(client):
    data = {
        'x': Interval(3, 4),
        'y': Interval(-2, 1),
        'z': Interval.from_value(11)
    }
    url = '/process_request?field=df_grad&scope=interval'
    for k, v in data.items():
        url += '&{0}={1}'.format(k, json.dumps(v))

    response = client.get(url)
    output = list(map(Interval.from_dict, json.loads(response.data)))

    assert response.status_code == 200
    assert output[0] == Interval(6, 8)
    assert output[1] == Interval(-8, 4)
    assert output[2] == Interval.from_value(66.0)
Example #4
0
def test_interval_derivatives():
    assert almost_equal_interval(core.request('df_x',
                                              {'x': Interval(3, 4),
                                               'y': Interval.from_value(2),
                                               'z': Interval.from_value(3)}),
                                 Interval(6, 8))
    assert almost_equal_interval(core.request('df_y',
                                              {'x': Interval.from_value(1),
                                               'y': Interval(-2, 1),
                                               'z': Interval.from_value(3)}),
                                 Interval(-8, 4))
    assert almost_equal_interval(core.request('df_z',
                                              {'x': Interval.from_value(1),
                                               'y': Interval.from_value(2),
                                               'z': Interval.from_value(11)}),
                                 Interval.from_value(66.0))
Example #5
0
def test_interval_gradient():
    grad = core.request('df_grad', {'z': Interval.from_value(11), 'x': Interval(3, 4), 'y': Interval(-2, 1)})
    assert almost_equal_interval(grad[0], Interval(6, 8))
    assert almost_equal_interval(grad[1], Interval(-8, 4))
    assert almost_equal_interval(grad[2], Interval.from_value(66.0))