-
Notifications
You must be signed in to change notification settings - Fork 175
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
Extended plotting and added sampling #667
base: master
Are you sure you want to change the base?
Conversation
Add parameters for labelling/coloring and naming points of a point cloud; added parameters for custom marker size and opacity; added parameters to toggle the plot being to scale or not, and printed or not.
Add directory "sampling" containing "sample_point_clouds.py". The file contains functions to sample points from a round sphere, a standardly embedded torus and a circle in the x-y-plane in $\mathbb{R}^3$ uniformly and at random.
import plotly.graph_objs as gobj | ||
|
||
from gtda.utils import validate_params | ||
from gtda.utils.intervals import Interval as Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a good reason to import Interval as Int
? Interval
is already a good name and I don't see why you should change it as Int
. Moreover, Int is really a bad variable name. It is similarm to int
but it is totally another thing.
marker_size=5, | ||
opacity=0.8, | ||
to_scale=False, | ||
display_plot=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- indentation is wrong
- typing is missing
# If no labels provided, just enumerate data points, and record | ||
# if there were user-provided labels to use in `names`. | ||
labels_were_provided = labels is not None | ||
if not labels_were_provided: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can just write
if labels is not None:
labels = np.arange(point_cloud.shape[0])
or in one line
labels = np.arange(point_cloud.shape[0]) if labels is not None else labels
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also put np.arange(point_cloud.shape[0])
as default value for labels. I think this is the best solution.
|
||
if names is not None: | ||
if not labels_were_provided: | ||
raise ValueError("No lables were provided.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be done at the very beginning of the method not after all the calls at the validate_params
{"display_plot": {"type": (bool,)}}) | ||
|
||
if dimension is None: | ||
dimension = np.min((3, point_cloud.shape[1])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just do it in one-line
|
||
def sphere_sampling(n=1000, r=1, noise=0): | ||
"""Uniformly and randomly samples points from a round | ||
sphere centered at the origin of 3-space. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from a round sphere? There exists a sphere which is not round? Or are there different types of spheres?
delete round here.
from gtda.utils.intervals import Interval | ||
|
||
|
||
def sphere_sampling(n=1000, r=1, noise=0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use descriptive name. For example, r is for radius. Therefore, use radius as variable name.
for i in range(n): | ||
theta = np.random.uniform(low=0, high=2*np.pi) | ||
phi = U_phi_inverse(np.random.uniform()) | ||
pt = parametrization(theta, phi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are using the method parametrisation just here in this for loop.
Just write
pt = np.array(
[
r*np.cos(theta)*np.sin(phi),
r*np.sin(theta)*np.sin(phi),
r*np.cos(phi),
]
)
it is much easier to understand what it is happening
And use another name for the variable pt. Is it a point? Just use the name point.
return points | ||
|
||
|
||
def torus_sampling(n=1000, R=3, r=1, noise=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will suggest to find better names for the variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you using these default values here?
validate_params({"noise": noise}, | ||
{"noise": {"type": (int, float), | ||
"in": Interval(0, np.inf, closed="left")}}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comments as before
Reference issues/PRs
Types of changes
Description
Screenshots (if appropriate)
Any other comments?
Checklist
flake8
to check my Python changes.pytest
to check this on Python tests.