Beispiel #1
0
def test_path():
    """Tests that Path behaves correctly."""
    # Test small edge cases thoroughly
    for device in h.get_devices():
        for batch_size in (1, 2):
            for input_stream, basepoints in zip(
                (1, 2), ((True, h.without_grad, h.with_grad),
                         (False, True, h.without_grad, h.with_grad))):
                for input_channels in (1, 2):
                    for depth in (1, 2):
                        path_grad = random.choice([False, True])
                        basepoint = random.choice(basepoints)
                        update_lengths, update_grads = _update_lengths_update_grads(
                            3)
                        _test_path(device,
                                   path_grad,
                                   batch_size,
                                   input_stream,
                                   input_channels,
                                   depth,
                                   basepoint,
                                   update_lengths,
                                   update_grads,
                                   extrarandom=False)

    # Randomly test larger cases
    for _ in range(50):
        device = random.choice(h.get_devices())
        batch_size = random.choice((1, 2, 5))
        input_stream = random.choice([3, 6, 10])
        input_channels = random.choice([1, 2, 6])
        depth = random.choice([1, 2, 4, 6])
        basepoint = random.choice([False, True, h.without_grad, h.with_grad])
        path_grad = random.choice([False, True])
        update_lengths, update_grads = _update_lengths_update_grads(10)
        _test_path(device,
                   path_grad,
                   batch_size,
                   input_stream,
                   input_channels,
                   depth,
                   basepoint,
                   update_lengths,
                   update_grads,
                   extrarandom=True)

    # Do at least one large test
    for device in h.get_devices():
        _test_path(device,
                   path_grad=True,
                   batch_size=5,
                   input_stream=10,
                   input_channels=6,
                   depth=6,
                   basepoint=True,
                   update_lengths=[5, 6],
                   update_grads=[False, True],
                   extrarandom=False)
Beispiel #2
0
def test_forward():
    """Tests that the forward calculations of the signature behave correctly."""
    for class_ in (False, True):
        for device in h.get_devices():
            # sometimes we do different calculations depending on whether we expect to take a gradient later, so we need
            # to check both of these cases
            for path_grad in (False, True):
                for batch_size in (0, 1, 2, 5):
                    for input_stream in (0, 1, 2, 3, 10):
                        for input_channels in (0, 1, 2, 6):
                            for depth in (1, 2, 4, 6):
                                for stream in (False, True):
                                    for basepoint in (False, True,
                                                      h.without_grad,
                                                      h.with_grad):
                                        for inverse in (False, True):
                                            for initial in (None,
                                                            h.without_grad,
                                                            h.with_grad):
                                                _test_forward(
                                                    class_, device, path_grad,
                                                    batch_size, input_stream,
                                                    input_channels, depth,
                                                    stream, basepoint, inverse,
                                                    initial)
def test_backward_expand_words():
    """Tests that the backward calculations produce the correct values."""
    for class_ in (False, True):
        for device in h.get_devices():
            for batch_size, input_stream, input_channels in h.random_sizes():
                for depth in (1, 2, 4, 6):
                    for stream in (False, True):
                        for mode in (h.expand_mode, h.words_mode):
                            _test_backward(class_, device, batch_size,
                                           input_stream, input_channels, depth,
                                           stream, mode)
def test_backward():
    """Tests that the backwards calculation for combing signatures produces the correct values."""
    for signature_combine, amount in ((True, 2), (False, 1), (False, 2),
                                      (False, 3), (False, 10)):
        for device in h.get_devices():
            for batch_size, input_stream, input_channels in h.random_sizes():
                for depth in (1, 2, 4, 6):
                    inverse = random.choice([False, True])
                    _test_backward(signature_combine, amount, device,
                                   batch_size, input_stream, input_channels,
                                   depth, inverse)
Beispiel #5
0
def test_backward_brackets():
    """Tests that the backwards operation through the logsignature gives the correct values."""
    for class_ in (False, True):
        for device in h.get_devices():
            for batch_size, input_stream, input_channels, basepoint in h.random_sizes_and_basepoint():
                for depth in (1, 2, 4, 6):
                    for mode in (h.brackets_mode,):
                        stream = random.choice([False, True])
                        inverse = random.choice([False, True])
                        _test_backward(class_, device, batch_size, input_stream, input_channels, depth, stream,
                                       basepoint, inverse, mode)
Beispiel #6
0
def test_backward():
    """Tests that the backwards operation through the signature gives the correct values."""
    for class_ in (False, True):
        for device in h.get_devices():
            for batch_size, input_stream, input_channels, basepoint in h.random_sizes_and_basepoint():
                for depth in (1, 2, 4, 6):
                    for stream in (False, True):
                        for inverse in (False, True):
                            for initial in (None, h.without_grad, h.with_grad):
                                for scalar_term in (False, True):
                                    _test_backward(class_, device, batch_size, input_stream, input_channels, depth,
                                                   stream, basepoint, inverse, initial, scalar_term)
Beispiel #7
0
def test_no_adjustments():
    """Tests that the logsignature computations don't modify any memory that they're not supposed to."""
    for class_ in (False, True):
        for device in h.get_devices():
            for batch_size, input_stream, input_channels, basepoint in h.random_sizes_and_basepoint():
                for depth in (1, 2, 5):
                    for mode in h.all_modes:
                        path_grad = random.choice([False, True])
                        stream = random.choice([False, True])
                        inverse = random.choice([False, True])
                        _test_no_adjustments(class_, device, batch_size, input_stream, input_channels, depth, stream,
                                             basepoint, inverse, mode, path_grad)
def test_forward():
    """Tests that the forward calculations produce the correct values."""
    for class_ in (False, True):
        for device in h.get_devices():
            for batch_size, input_stream, input_channels in h.random_sizes():
                for depth in (1, 2, 4, 6):
                    for stream in (False, True):
                        for mode in h.all_modes:
                            for signature_grad in (False, True):
                                _test_forward(class_, device, batch_size,
                                              input_stream, input_channels,
                                              depth, stream, mode,
                                              signature_grad)
def test_no_adjustments():
    """Tests that no memory is modified that shouldn't be modified."""
    for class_ in (False, True):
        for device in h.get_devices():
            for batch_size, input_stream, input_channels in h.random_sizes():
                for depth in (1, 2, 5):
                    for stream in (False, True):
                        for mode in h.all_modes:
                            for signature_grad in (False, True):
                                _test_no_adjustments(class_, device,
                                                     batch_size, input_stream,
                                                     input_channels, depth,
                                                     stream, mode,
                                                     signature_grad)
Beispiel #10
0
def test_no_adjustments():
    """Tests that the signature computations don't modify any memory that they're not supposed to."""

    for class_ in (False, True):
        for path_grad in (False, True):
            for device in h.get_devices():
                for batch_size, input_stream, input_channels, basepoint in h.random_sizes_and_basepoint():
                    for depth in (1, 2, 5):
                        for stream in (False, True):
                            for inverse in (False, True):
                                for initial in (None, h.without_grad, h.with_grad):
                                    for scalar_term in (False, True):
                                        _test_no_adjustments(class_, device, batch_size, input_stream, input_channels,
                                                             depth, stream, basepoint, inverse, initial, path_grad,
                                                             scalar_term)
def test_forward():
    """Tests that the forward calculation for combing signatures produces the correct values."""
    for signature_combine, amount in ((True, 2), (False, 1), (False, 2),
                                      (False, 3), (False, 10)):
        for signature_grad in (False, True):
            for device in h.get_devices():
                for batch_size in (1, 2, 5):
                    input_stream = 2
                    for input_channels in (1, 2, 6):
                        for depth in (1, 2, 4, 6):
                            for inverse in (False, True):
                                _test_forward(signature_combine,
                                              signature_grad, amount, device,
                                              batch_size, input_stream,
                                              input_channels, depth, inverse)
def test_no_adjustments():
    """Tests that the calculations for combining signatures don't modify memory they're not supposed to."""
    for signature_combine, amount in ((True, 2), (False, 1), (False, 2),
                                      (False, 3), (False, 10)):
        for signature_grad in (False, True):
            for device in h.get_devices():
                for batch_size, input_stream, input_channels in h.random_sizes(
                ):
                    for depth in (1, 2, 5):
                        for inverse in (False, True):
                            _test_no_adjustments(signature_combine, amount,
                                                 device, batch_size,
                                                 input_stream, input_channels,
                                                 depth, inverse,
                                                 signature_grad)
Beispiel #13
0
def test_forward():
    """Tests that the forward calculations of the logsignature behave correctly."""
    for class_ in (False, True):
        for device in h.get_devices():
            for batch_size in (0, 1, 2, 3):
                for input_stream in (0, 1, 2, 3, 10):
                    for input_channels in (0, 1, 2, 6):
                        for depth in (1, 2, 4, 6):
                            for mode in h.all_modes:
                                # Cuts down on the amount of iterations dramatically!
                                # We're randomising over the arguments which we happen to know aren't really important
                                # to the operation of logsignatures (as compared to signatures), so we're not missing
                                # much by doing this.
                                stream = random.choice([False, True])
                                path_grad = random.choice([False, True])
                                basepoint = random.choice([False, True, h.without_grad, h.with_grad])
                                inverse = random.choice([False, True])
                                _test_forward(class_, device, path_grad, batch_size, input_stream, input_channels,
                                              depth, stream, basepoint, inverse, mode)