[Python] Having issue with calculating SINR using TensorFlow, how numerically stable is TF...

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024.

  1. Stack

    Stack Membro Participativo

    I have code for training a neural network and the loss is negative SINR, for a system with multi group (G) and multi users (K). However when I calculate the sinr, something odd happens.

    the SINR formula is this:

    [​IMG]

    And this is my code:

    def find_sinr_over_group(H, W):

    sigma2 = 1
    # Compute the Hermitian transpose (conjugate transpose) of W
    W_H = tf.transpose(tf.math.conj(W), perm=[0, 2, 1]) # Shape: (batch_size, G, M)

    # Compute Signal Power for each user in each group
    signal_power = []
    for g in range(W.shape[-1]): # Loop over each group g
    w_h_g = W_H[:, g, :] # Shape: (batch_size, M)
    h_g = H[:, :, :, g] # Shape: (batch_size, M, K)

    # Matrix multiplication to compute signal power
    s = tf.matmul(w_h_g[:, tf.newaxis, :], h_g) # Shape: (batch_size, 1, K)
    s = tf.squeeze(s, axis=1) # Shape: (batch_size, K)
    signal_power.append(s)

    signal_power = tf.stack(signal_power, axis=-1) # Shape: (batch_size, K, G)
    signal_power = tf.math.real(tf.math.multiply(signal_power, tf.math.conj(signal_power)))
    # signal_power = tf.math.abs(signal_power) ** 2 # Take the absolute square

    # Compute Total Power for each user in each group
    total_power = []
    for g in range(W.shape[-1]): # Loop over each group g
    w_h = W_H[:, :, :] # Shape: (batch_size, G, M)
    h_g = H[:, :, :, g] # Shape: (batch_size, M, K)

    # Matrix multiplication to compute total power
    t = tf.matmul(w_h, h_g) # Shape: (batch_size, G, K)
    t = tf.math.real(tf.math.multiply(t, tf.math.conj(t)))
    # t = tf.math.abs(t) ** 2 # Shape: (batch_size, G, K)
    total_power.append(tf.reduce_sum(t, axis=1)) # Sum across G to get (batch_size, K)

    total_power = tf.stack(total_power, axis=-1) # Shape: (batch_size, K, G)

    # Isolate the Interference Power by subtracting Signal Power from Total Power
    interference_power = total_power - signal_power # Shape: (batch_size, K, G)

    # Add noise power
    interference_plus_noise_power = interference_power + sigma2 # Add noise

    # Compute SINR
    sinr = signal_power / interference_plus_noise_power # Shape: (batch_size, K, G)

    return sinr


    But the problem is, the interference power in some cases is negative. Which numerically impossible since the signal power is just a special case of the total power. Anyone knows why this happens and how should I fix it?

    As you can see, at first i used the tf.abd function and then raise by the power of 2. I thought that might be an issue with abs so I tried myltipying by conjugate to get the power of the signal. But still I have this issue.

    Continue reading...

Compartilhe esta Página