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

Extended plotting and added sampling #667

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

m-a-huber
Copy link

Reference issues/PRs

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

Screenshots (if appropriate)

Any other comments?

Checklist

  • [x ] I have read the guidelines for contributing.
  • [x ] My code follows the code style of this project. I used flake8 to check my Python changes.
  • [x ] My change requires a change to the documentation.
  • [x ] I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed. I used pytest to check this on Python tests.

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

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):

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:

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

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.")

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]))

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.

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):

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)

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):

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

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")}})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comments as before

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

Successfully merging this pull request may close these issues.

None yet

2 participants