-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathripser.noise.Rmd
98 lines (81 loc) · 1.91 KB
/
ripser.noise.Rmd
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
title: "Ripser with Noise"
author: "Ken Wang"
date: "10/7/2020"
output:
html_document:
df_print: paged
pdf_document: default
html_notebook: default
editor_options:
chunk_output_type: inline
---
```{r,message=FALSE,warning=FALSE}
library("ripserr")
library(tidyverse)
library(fitdistrplus)
```
```{r}
noise_num = 100
noise = data.frame(replicate(2,runif(noise_num,-1000,1000)))
names(noise) = c("x","y")
radius = 500
jitter = 50
data_num = 1000
a = runif(data_num,0,1) * 2 * pi
r = rnorm(data_num,radius,jitter)
data = data.frame(x = r * cos(a), y = r * sin(a))
dataa = rbind(data,noise)
dataa %>%
ggplot()+
geom_point(aes(x=x,y=y))
```
```{r}
rips = vietoris_rips(dataa)
deg0_num = data_num + noise_num - 1
plot1 = data.frame(num=1:deg0_num,length=rips$death[1:deg0_num])
plot1 %>%
ggplot(aes(x=num,y=length))+
geom_bar(stat="identity", fill="steelblue")+
theme_minimal()
```
```{r}
deg1 = rips[(deg0_num+1):nrow(rips),]
deg1 %>%
ggplot()+
geom_point(aes(x=birth,y=death))+
geom_abline(intercept = 0, slope = 1, color = "blue")+
geom_segment(aes(x=birth,y=death,xend=birth,yend=birth))
```
```{r}
noise_num = 1000
noise = data.frame(replicate(2,runif(noise_num,-1000,1000)))
names(noise) = c("x","y")
radius = 500
jitter = 50
data_num = 1000
a = runif(data_num,0,1) * 2 * pi
r = rnorm(data_num,radius,jitter)
data = data.frame(x = r * cos(a), y = r * sin(a))
dataa = rbind(data,noise)
dataa %>%
ggplot()+
geom_point(aes(x=x,y=y))
```
```{r}
rips = vietoris_rips(dataa)
deg0_num = data_num + noise_num - 1
plot1 = data.frame(num=1:deg0_num,length=rips$death[1:deg0_num])
plot1 %>%
ggplot(aes(x=num,y=length))+
geom_bar(stat="identity", fill="steelblue")+
theme_minimal()
```
```{r}
deg1 = rips[(deg0_num+1):nrow(rips),]
deg1 %>%
ggplot()+
geom_point(aes(x=birth,y=death))+
geom_abline(intercept = 0, slope = 1, color = "blue")+
geom_segment(aes(x=birth,y=death,xend=birth,yend=birth))
```