Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behaviour of tf.nn.sigmoid on complex inputs #61800

Open
jshepherd01 opened this issue Sep 6, 2023 · 3 comments
Open

Incorrect behaviour of tf.nn.sigmoid on complex inputs #61800

jshepherd01 opened this issue Sep 6, 2023 · 3 comments
Assignees
Labels
comp:ops OPs related issues stat:awaiting response Status - Awaiting response from author TF 2.13 For issues related to Tensorflow 2.13 type:bug Bug

Comments

@jshepherd01
Copy link

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

binary

TensorFlow version

tf v1.12.1-96406-gfa4d29bfef8 2.14.0-dev20230706

Custom code

Yes

OS platform and distribution

WSL Ubuntu 20.04.5 LTS

Mobile device

No response

Python version

No response

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current behavior?

tf.nn.sigmoid gives incorrect values for complex numbers with large, negative real parts (which should map to within a rounding error of 0). For example, when x = -709-1j (complex128) I expect tf.nn.sigmoid(x) = 0, but instead tf.nn.sigmoid(x) = 1.

Standalone code to reproduce the issue

import tensorflow as tf
x = tf.constant([-709-1j], dtype=tf.complex128)
tf.nn.sigmoid(x)  # <tf.Tensor: shape=(1,), dtype=complex128, numpy=array([1.+0.j])>

Relevant log output

No response

@google-ml-butler google-ml-butler bot added the type:bug Bug label Sep 6, 2023
@sushreebarsa sushreebarsa added comp:ops OPs related issues TF 2.13 For issues related to Tensorflow 2.13 labels Sep 11, 2023
@sushreebarsa
Copy link
Contributor

@sachinprasadhs I was able to replicate the issue on colab using TF v2.13, tf-nightly. Please find the gist here for reference. Thank you!

@sachinprasadhs sachinprasadhs added the stat:awaiting tensorflower Status - Awaiting response from tensorflower label Nov 20, 2023
@dlibk
Copy link

dlibk commented Mar 14, 2024

The same issue happens on tf.Tensor((-inf+0j), shape=(), dtype=complex128), the result is 1+0j instead of 0.
Please see the code below.

input = tf.constant(-np.inf, dtype='complex128')
print(input)  # tf.Tensor((-inf+0j), shape=(), dtype=complex128)

out = tf.nn.sigmoid(input)
print(out)  # tf.Tensor((1+0j), shape=(), dtype=complex128)

@LakshmiKalaKadali
Copy link
Contributor

Hi @jshepherd01,

The tf.nn.sigmoid is working as intended for complex inputs. Checked with different examples in TF 2.17 and TF 2.18.0.

test_inputs = [
        tf.constant([-np.inf], dtype=tf.complex128),
        tf.constant([-709-1j], dtype=tf.complex128),
        tf.constant([-709+1j], dtype=tf.complex128),
        tf.constant([-1-1j], dtype=tf.complex128),
        tf.constant([-1+1j], dtype=tf.complex128),
        tf.constant([0-1j], dtype=tf.complex128),
        tf.constant([0+1j], dtype=tf.complex128),
        
    ]
    
print("Complex Sigmoid Investigations:")
for x in test_inputs:
  result = tf.nn.sigmoid(x)
  print(f"\nInput: {x.numpy()}")
  print(f"Sigmoid Output: {result.numpy()}")

OUTPUT

Sigmoid Output: [0.+0.j]

Input: [-709.-1.j]
Sigmoid Output: [0.-0.j]

Input: [-709.+1.j]
Sigmoid Output: [0.+0.j]

Input: [-1.-1.j]
Sigmoid Output: [0.21795843-0.20194823j]

Input: [-1.+1.j]
Sigmoid Output: [0.21795843+0.20194823j]

Input: [0.-1.j]
Sigmoid Output: [0.5-0.27315124j]

Input: [0.+1.j]
Sigmoid Output: [0.5+0.27315124j]

Please refer to the gist as well.

Thank You

@LakshmiKalaKadali LakshmiKalaKadali added stat:awaiting response Status - Awaiting response from author and removed stat:awaiting tensorflower Status - Awaiting response from tensorflower stat:awaiting response Status - Awaiting response from author labels Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:ops OPs related issues stat:awaiting response Status - Awaiting response from author TF 2.13 For issues related to Tensorflow 2.13 type:bug Bug
Projects
None yet
Development

No branches or pull requests

5 participants