简体   繁体   English

从 R/MatLab 中的点创建一个随机圆

[英]Creating a randomized circle from points in R/MatLab

I'm doing some research with a professor at my university, and he is asking that I create some data for the purposes of Topological Data Analysis (TDA).我正在与我大学的一位教授进行一些研究,他要求我为拓扑数据分析 (TDA) 创建一些数据。

I used two packages from R and MatLab, however the authors seem to have a similar idea of how to randomize the data when performing an operation that relates to persistence of Betti points.我使用了 R 和 MatLab 的两个包,但是作者似乎对如何在执行与 Betti 点持久性相关的操作时随机化数据有类似的想法。

The issue in R (and MatLab) is that the circle is created with: R(和 MatLab)中的问题是圆是用以下方法创建的:

X <- circleUnif(n=30)

This generates a circle with evenly spaced points (30) with equal radius around a central point.这会生成一个圆,其中点 (30) 具有均匀分布的点 (30),围绕中心点的半径相等。 To randomize the data, both examples from the author of the packages randomly sample from the data.为了随机化数据,来自软件包作者的两个示例都从数据中随机抽样。 This leads to an image that looks like this: Alpha Complex What the professor asked is that I make it such that each point has some 'sigma' or deviation away from the radius.这导致了一个看起来像这样的图像: Alpha Complex教授问的是我让每个点都有一些 'sigma' 或偏离半径。 This would in essence create a 'fuzzy' ring with some degree of thickness.这实质上会产生具有一定厚度的“模糊”环。 That way when persistence is performed on the data, the birth/death axes would have a more interesting output.这样,当对数据执行持久化时,生/死轴会有更有趣的输出。

Around 2:30 in this video is an idea of what I'm trying to do: Persistent homology在这段视频中,大约 2:30 是我想要做的事情的一个想法: Persistent homology

If someone has an idea how to do this in Python, I'm willing to try other languages as well.如果有人知道如何在 Python 中做到这一点,我也愿意尝试其他语言。

The following should work fine for you as long as you have numpy installed (using pip install numpy at the command line if you don't).只要您pip install numpy (如果没有,请在命令行使用pip install numpy ,以下内容应该适合您。

import numpy as np

def circleUnif(n=30, radius=1, sigma=0, center=(0, 0)):
    radii = np.random.randn(n) * sigma + radius
    angles = np.random.rand(n) * np.pi * 2

    x = radii * np.cos(angles)
    y = radii * np.sin(angles)

    return np.transpose([x, y]) + center

As an example usage:作为示例用法:

>>> X = circleUnif(3, 1, 0, (2, 3))
>>> print X
[[1.29321773 3.70743115]
 [2.72817308 3.68539329]
 [2.35728855 2.06600595]]

In my experience though, python does not have the same maturity as R for topological data analysis.不过,根据我的经验,python 在拓扑数据分析方面的成熟度不如 R。 There isn't anything wrong with using the data science tools available in python, and you could generate data with python for use in R if you would like.使用 Python 中可用的数据科学工具没有任何问题,如果您愿意,可以使用 Python 生成数据以在 R 中使用。 But this is one of the few instances where python is really lacking in quality, stable tooling for a data science task.但这是 Python 真正缺乏用于数据科学任务的高质量、稳定工具的少数情况之一。 I might make some eventually, or somebody else might, but you don't have many options for most TDA algorithms right now.我最终可能会做一些,或者其他人可能会做一些,但是对于大多数 TDA 算法,您现在没有很多选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM