Exemplo n.º 1
0
def test_grid_optimize_6():
    """
    Case 6: No xset is given to test. Should raise TypeError.
    """
    with pytest.raises(TypeError):
        loss = grid_optimizer(X_in, params, args=['n_reservoir'])

    return
Exemplo n.º 2
0
def test_grid_optimize_7():
    """
    Case 7: yset is given, but not xset.
    """
    with pytest.raises(TypeError):
        loss = grid_optimizer(X_in,
                              params,
                              args=['n_reservoir'],
                              yset=reservoir_set)

    return
Exemplo n.º 3
0
def test_grid_optimize_3():
    """
    Case 3: Two variables specified, only one set given.
    """
    with pytest.raises(AssertionError):
        loss = grid_optimizer(X_in.T,
                              params,
                              args=['n_reservoir', 'sparsity'],
                              xset=reservoir_set,
                              verbose=False,
                              visualize=False)

    return
Exemplo n.º 4
0
def test_grid_optimize_2():
    """
    Case 2: Variable not in params
    """
    with pytest.raises(AssertionError):
        loss = grid_optimizer(X_in.T,
                              params,
                              args=['jimmy'],
                              xset=trainingLengths,
                              verbose=False,
                              visualize=False)

    return
Exemplo n.º 5
0
def test_grid_optimize_1():
    """
    Case 1: Too many variables given
    """
    with pytest.raises(AssertionError):
        loss = grid_optimizer(X_in.T,
                              params,
                              args=['trainlen', 'rho', 'noise'],
                              xset=trainingLengths,
                              verbose=False,
                              visualize=False)

    return
Exemplo n.º 6
0
def test_grid_optimize_5():
    """
    Case 5: ESN does not train because of mismatched input shapes.
    """
    with pytest.raises(IndexError):
        loss = grid_optimizer(X_in,
                              params,
                              args=['n_reservoir'],
                              xset=reservoir_set,
                              yset=None,
                              verbose=False,
                              visualize=False)

    return
Exemplo n.º 7
0
def test_grid_optimize_4():
    """
    Case 4: One variable specified, two sets given.
    """
    with pytest.raises(AssertionError):
        loss = grid_optimizer(X_in.T,
                              params,
                              args=['n_reservoir'],
                              xset=reservoir_set,
                              yset=sparsity_set,
                              verbose=False,
                              visualize=False)

    return
Exemplo n.º 8
0
    X_in = np.array(X_in)
    print(X_in.shape, len(X_in.shape))

    # =============================================================================
    # ESN Optimization
    # =============================================================================
    MAX_TRAINLEN = int(len(xdf) - params['future'])
    print(f"Maximum training length is {MAX_TRAINLEN}")

    print('Optimizing spectral radius and regularization')
    tic = time.perf_counter()
    radiusxnoise_loss = grid_optimizer(X_in.T,
                                       params,
                                       args=['rho', 'noise'],
                                       xset=radius_set,
                                       yset=noise_set,
                                       verbose=True,
                                       save_path=save_prefix)

    toc = time.perf_counter()
    elapsed = toc - tic
    print(f"This simulation took {elapsed:0.02f} seconds")
    print(f"This simulation took {elapsed/60:0.02f} minutes")

    opt_radius, opt_noise = optimal_values(radiusxnoise_loss, radius_set,
                                           noise_set)
    params['rho'] = opt_radius
    params['noise'] = opt_noise

    print('Optimizing network size and sparsity')