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

[Bug]: maxwell #23337

Closed
1 of 4 tasks
dash96 opened this issue Sep 9, 2023 · 0 comments · Fixed by #23358
Closed
1 of 4 tasks

[Bug]: maxwell #23337

dash96 opened this issue Sep 9, 2023 · 0 comments · Fixed by #23358
Assignees
Labels
Bug Report Report bugs detected in Ivy.

Comments

@dash96
Copy link
Contributor

dash96 commented Sep 9, 2023

Bug Explanation

I recently learnt that, to verify if the random function is working alright one needs to also plot the histogram graph of the particular function along side the histogram graph of a back-end function for a large number of outputs to verify if they look similar.

I had pushed a Maxwell function that passed all the tests. but when I plotted the histogram graph as explained above they looked very different. The graph is as shown bellow,

image

The code for the same is mentioned in the next section.

Steps to Reproduce Bug

`%matplotlib inline

import matplotlib
import ivy
import jax
from ivy.functional.frontends.jax.random import _get_seed

current function in Ivy repository

def maxwell_current(key, shape=None, dtype="float64"):
    seed = _get_seed(key)
    # generate uniform random numbers between 0 and 1
    z = ivy.random_uniform(seed=seed, shape=shape, dtype=dtype)
    # applying inverse transform sampling
    x = (z**2) * ivy.exp(-(z**2) / 2)
    return x

edited version

def maxwell(key, shape, dtype= "float64"):
    seed = _get_seed(key)
    shape = shape + (3,)
    random_normal = ivy.random_normal(seed=seed, shape=shape, dtype=dtype)
    return ivy.vector_norm(random_normal, axis=-1)

n = 1000000
import matplotlib.pyplot as plt
x = maxwell_current((123,123), (n,))
y = maxwell((123,123), (n,))
z = jax.random.maxwell(jax.numpy.array([123,123], dtype='uint32'), shape=(n,))

num_bins = int(ivy.sqrt(n))
n0, bins0, patches0 = plt.hist(x, bins=num_bins, histtype='step', color='blue')
n, bins, patches = plt.hist(y, bins=num_bins, histtype='step', color='black')
n, bins, patches = plt.hist(z, bins=num_bins, histtype='step', color='red')

plt.plot()

Environment

In general, in colab.

Ivy Version

v1.1.9

Backend

  • NumPy
  • TensorFlow
  • PyTorch
  • JAX

Device

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report Report bugs detected in Ivy.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants