scikit-tda / tadasets

Synthetic data sets apt for Topological Data Analysis
http://tadasets.scikit-tda.org
MIT License
34 stars 7 forks source link

Some ideas for point clouds #6

Open tmelorc opened 5 years ago

tmelorc commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

ctralie commented 5 years ago

Yeah numpy is great, and whenever you can avoid for loops it's usually faster

On Thu, Apr 18, 2019, 12:26 PM Thiago notifications@github.com wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/scikit-tda/tadasets/issues/6#issuecomment-484581789, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJWDZXE54X3XJVGMSC2TZ3PRCOKZANCNFSM4HG4Z6TA .