-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
93 lines (70 loc) · 2.24 KB
/
README.Rmd
File metadata and controls
93 lines (70 loc) · 2.24 KB
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
---
output: rmarkdown::github_document
---
```{r include=FALSE}
library("reticulate") # Para usar python no R
```
```{python echo=FALSE, results="hide"}
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(314)
seq1 = [i if i==1 else -1 for i in np.random.randint(2, size=900)]
seq2 = [i if i==1 else -1 for i in np.random.randint(2, size=900)]
seq3 = [i if i==1 else -1 for i in np.random.randint(2, size=900)]
seq1.insert(0,0)
seq2.insert(0,0)
seq3.insert(0,0)
road1 = np.cumsum(seq1)
road2 = np.cumsum(seq2)
road3 = np.cumsum(seq3)
n_seq = list(range(901))
plt.style.use("ggplot")
fig,ax = plt.subplots()
ax.plot(n_seq,road1, c='#E66625', linestyle='--')
ax.plot(n_seq,road2, c='#15E65B', linestyle=':')
ax.plot(n_seq,road3, c='#0D0EE6', linestyle="-")
ax.axhline(y=0, color='white')
plt.xlim([0,900])
lim_y = max(-min(min(road1),min(road2),min(road3)),max(max(road1),max(road2),max(road3)))+10
plt.ylim([-lim_y,+lim_y])
ax.set_xlabel('n')
ax.set_ylabel('Sn')
ax.set_title("Random Walk Simulation - 3 Roads")
```
```{python echo=FALSE}
# plt.show()
```
```{python eval=FALSE}
import numpy as np
import matplotlib.pyplot as plt
# Definindo a semente de pseudo-aleatorização
np.random.seed(314)
# Sequência de v.a's de Bernoulli transformadas em -1 e +1
seq1 = [i if i==1 else -1 for i in np.random.randint(2, size=900)]
seq2 = [i if i==1 else -1 for i in np.random.randint(2, size=900)]
seq3 = [i if i==1 else -1 for i in np.random.randint(2, size=900)]
# Inserindo S0 = 0 para cada uma das 3 sequências
seq1.insert(0,0)
seq2.insert(0,0)
seq3.insert(0,0)
# Soma acumulativa para gerar a sequência {Sn}
road1 = np.cumsum(seq1)
road2 = np.cumsum(seq2)
road3 = np.cumsum(seq3)
# Lista dos estados de tempo (de 0 a 900)
n_seq = list(range(901))
# Criação e exibição do gráfico
plt.style.use("ggplot")
fig,ax = plt.subplots()
ax.plot(n_seq,road1, c='#E66625', linestyle='--')
ax.plot(n_seq,road2, c='#15E65B', linestyle=':')
ax.plot(n_seq,road3, c='#0D0EE6', linestyle="-")
ax.axhline(y=0, color='white')
plt.xlim([0,900])
lim_y = max(-min(min(road1),min(road2),min(road3)),max(max(road1),max(road2),max(road3)))+10
plt.ylim([-lim_y,+lim_y])
ax.set_xlabel('n')
ax.set_ylabel('Sn')
ax.set_title("Random Walk Simulation - 3 Roads")
plt.show()
```