Skip to content

Instantly share code, notes, and snippets.

@masterdezign
Last active April 20, 2024 16:17
Show Gist options
  • Select an option

  • Save masterdezign/4f09e4444d0330e2984c2e11c593386e to your computer and use it in GitHub Desktop.

Select an option

Save masterdezign/4f09e4444d0330e2984c2e11c593386e to your computer and use it in GitHub Desktop.

Revisions

  1. masterdezign revised this gist Apr 20, 2024. 1 changed file with 10 additions and 7 deletions.
    17 changes: 10 additions & 7 deletions spirals.py
    Original file line number Diff line number Diff line change
    @@ -1,20 +1,23 @@
    import numpy as np

    def spirals(n_samples=400):
    N = n_samples
    theta = np.sqrt(np.random.rand(N))*2*pi # np.linspace(0,2*pi,100)
    r_a = 2*theta + pi
    theta = np.sqrt(np.random.rand(N))*2*np.pi

    r_a = 2*theta + np.pi
    data_a = np.array([np.cos(theta)*r_a, np.sin(theta)*r_a]).T
    x_a = data_a + np.random.randn(N,2)
    r_b = -2*theta - pi

    r_b = -2*theta - np.pi
    data_b = np.array([np.cos(theta)*r_b, np.sin(theta)*r_b]).T
    x_b = data_b + np.random.randn(N,2)

    res_a = np.zeros((N,1), dtype='uint8')
    res_b = np.ones((N,1), dtype='uint8')

    x = np.concatenate([x_a, x_b], axis=0)
    res = np.concatenate([res_a, res_b], axis=0).reshape(-1)
    return x, res


    Xdata, ydata = spirals()
  2. masterdezign created this gist Apr 20, 2024.
    20 changes: 20 additions & 0 deletions spirals.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    def spirals(n_samples=400):
    N = n_samples
    theta = np.sqrt(np.random.rand(N))*2*pi # np.linspace(0,2*pi,100)

    r_a = 2*theta + pi
    data_a = np.array([np.cos(theta)*r_a, np.sin(theta)*r_a]).T
    x_a = data_a + np.random.randn(N,2)

    r_b = -2*theta - pi
    data_b = np.array([np.cos(theta)*r_b, np.sin(theta)*r_b]).T
    x_b = data_b + np.random.randn(N,2)

    res_a = np.zeros((N,1), dtype='uint8')
    res_b = np.ones((N,1), dtype='uint8')

    x = np.concatenate([x_a, x_b], axis=0)
    res = np.concatenate([res_a, res_b], axis=0).reshape(-1)
    return x, res

    Xdata, ydata = spirals()