#๐Ÿ”’ Need help checking my logic

6 messages ยท Page 1 of 1 (latest)

full shuttle
#

I am about to make a TCN to use in my GANs. I am working with a receptive field of 1440 and 9 kernels,8 layers. I found a code on github and I basically adapted it to my use cases by expanding some features.
https://github.com/JamesSullivan/temporalCN/blob/main/tf_model.ipynb

Can someone check my implementations?
So far it compiled in colab but I am afraid there are parts of the logic where I don't understood entirely that I messed up. Code is too long so its i the comments

GitHub

Implementation of 2019 Quant GANs: Deep Generation of Financial Time Series paper - JamesSullivan/temporalCN

wicked copperBOT
#

@full shuttle

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

full shuttle
#

Here is the code.

def add_temporal_block(previous, skip, dilation, cropping):
    for _ in range(block_size):
        convs = []
        convs.append(Conv1D(fixed_filters, kernel_size, dilation_rate=(dilation,), padding='causal')(previous))
        if len(convs) > 1:
            previous = Concatenate(axis=-1)(convs)
        else:
            previous = convs[0]
        previous = BatchNormalization(axis=2)(previous)
        previous = PReLU(shared_axes=[1])(previous)
    # Adjust cropping to never be negative
    drop_left = block_size * (kernel_size - 1) * dilation
    cropping += drop_left
    if skip is None:
        skip = Conv1D(fixed_filters, 1, padding='causal')(previous)
    cropping_value = max(cropping - (receptive_field_size - 1), 0)
    #print(f'cropping_value{cropping_value}')
    out = Add()([Cropping1D(cropping=(drop_left, 0))(previous), previous])
    skip_out = Cropping1D(cropping=(cropping_value, 0))(out) if cropping_value > 0 else out
    if skip is not None:
        skip_out = Add()([skip, Conv1D(fixed_filters, 1, padding='causal')(skip_out)])
    else:
        skip_out = Conv1D(fixed_filters, 1, padding='causal')(skip_out)
    return PReLU(shared_axes=[1])(out), skip_out, cropping
def TCN(input_dim):
    dilations = [2 ** i for i in range(8)]
    input_layer = Input(shape=(None, input_dim[1]))
    cropping = 0
    prev_layer, skip_layer, _ = add_temporal_block(input_layer, None, 1, cropping)
    for dilation in dilations:
        prev_layer, skip_layer, cropping = add_temporal_block(prev_layer, skip_layer, dilation, cropping)
    output_layer = PReLU(shared_axes=[1])(skip_layer)
    output_layer = Conv1D(fixed_filters, kernel_size=1, padding='causal')(output_layer)
    output_layer = PReLU(shared_axes=[1])(output_layer)
    output_layer = Conv1D(1, kernel_size=1, padding='causal')(output_layer)
    return Model(input_layer, output_layer)
#

Here are the parameters, it was too long so I didn't include in the original post

fixed_filters = 256  # Number of filters in Conv1D layers
receptive_field_size = 1792  # Target receptive field size
kernel_size = 9  # Kernel size for Conv1D layers
block_size = 2  # Number of layers in each block
wicked copperBOT
#

@full shuttle

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.