summaryrefslogtreecommitdiff
path: root/src/python/gudhi/datasets/generators/points/torus.py
blob: 2de696b257eb842ca8efce143d810e4bc9113dce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
# See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
# Author(s):       Hind Montassif
#
# Copyright (C) 2021 Inria
#
# Modification(s):
#   - YYYY/MM Author: Description of the modification

import numpy as np
import math


def generate_random_points(num_points, dim):

    # Generate random angles of size num_points*dim
    alpha = 2*math.pi*np.random.rand(num_points*dim)

    # Based on angles, construct points of size num_points*dim on a circle and reshape the result in a num_points*2*dim array
    array_points = np.asarray([[np.cos(a), np.sin(a)] for a in alpha]).ravel().reshape(num_points, 2*dim)
    
    return array_points


def generate_grid_points(num_points, dim):
    
    num_points_grid = (int(num_points**(1./dim)))**dim
    
    alpha = 2*math.pi*np.random.rand(num_points_grid*dim)
    
    array_points = np.asarray([[np.cos(a), np.sin(a)] for a in alpha]).ravel().reshape(num_points_grid, 2*dim)
    
    return array_points

def generate_points(num_points, dim, sample='random'):
    if sample == 'random':
        print("Sample is random")
        npoints = num_points
    elif sample == 'grid':
        print("Sample is grid")
        npoints = (int(num_points**(1./dim)))**dim
    else:
        print("Sample type '{}' is not supported".format(sample))
        return
    
    # Generate random angles of size num_points*dim
    alpha = 2*math.pi*np.random.rand(npoints*dim)
    
    # Based on angles, construct points of size num_points*dim on a circle and reshape the result in a num_points*2*dim array
    array_points = np.asarray([[np.cos(a), np.sin(a)] for a in alpha]).ravel().reshape(npoints, 2*dim)
    
    return array_points