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

Some ideas for point clouds #6

Open
tmelorc opened this issue Apr 18, 2019 · 3 comments
Open

Some ideas for point clouds #6

tmelorc opened this issue Apr 18, 2019 · 3 comments

Comments

@tmelorc
Copy link

tmelorc commented Apr 18, 2019

Some time ago, before I had discovered scikit-tda, I created the following functions to generate some datasets. Feel free to use and improve if you wish. Regards.

def figure_eight_pts(N, a=1):
    theta_list = 2 * np.pi * np.random.sample(N)
    pts = np.zeros((N,2))
    print theta_list
    for i in range(len(theta_list)):
        pts[i,0] = a * np.cos(theta_list[i]) * np.sqrt(2*np.cos(2*theta_list[i]))
        pts[i,1] = a * np.sin(theta_list[i]) * np.sqrt(2*np.cos(2*theta_list[i]))
    return pts

def annulus_pts(N, R=2, r=1):
    theta_list = np.random.random_sample(N)
    radius_list = r + np.random.random_sample(N) * (R-r)
    pts = np.zeros((N,2))
    for i in range(len(theta_list)):
        pts[i,0] = radius_list[i] * np.cos(2*np.pi*theta_list[i])
        pts[i,1] = radius_list[i] * np.sin(2*np.pi*theta_list[i])
    return pts

def cube_pts(N):
    npts = N/6
    faces = {}
    for i in range(3):
        data0 = np.random.random((npts,3))
        data1 = np.random.random((npts,3))
        data0[:,i] = 0
        data1[:,i] = 1
        faces[i]   = data0
        faces[i+3] = data1
    cube = np.concatenate([faces[i] for i in range(6)])
    return cube
@ctralie
Copy link
Member

ctralie commented Apr 18, 2019

Cool, thanks. Note that you can often do without for loops. For instance,

def figure_eight_pts(N, a=1):
    theta_list = 2 * np.pi * np.random.sample(N)
    pts = np.zeros((N,2))
    pts[:, 0] = a * np.cos(theta_list) * np.sqrt(2*np.cos(2*theta_list))
    pts[:, 1] = a * np.sin(theta_list) * np.sqrt(2*np.cos(2*theta_list))
    return pts

@tmelorc
Copy link
Author

tmelorc commented Apr 18, 2019

Very interesting. This is my difficulty, I have no knowledge how to do better programs. I have only ideas... :-)
Thanks.

@ctralie
Copy link
Member

ctralie commented Apr 18, 2019 via email

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

No branches or pull requests

2 participants