-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestPackage.Rmd
256 lines (161 loc) · 4.63 KB
/
TestPackage.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#Install R3.4.0
#Install Rtools34.exe > https://cran.r-project.org/bin/windows/Rtools/history.html
#Use R 3.4 > change in Tool s > Global Options > General >R Version
```{r}
#install.packages("rmarkdown")
#update.packages(ask = FALSE)
#install.packages("Rcpp")\
install.packages("reticulate")
```
#Make sure built under R 4.0.0
#Restart Rstudio
---
title: "testing modified density clustering code"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
----------------------------------------------------------------------------------
```{r}
#writeLines(strsplit(Sys.getenv("PATH"), ";")[[1L]])
library(Rcpp)
library(reticulate)
source("RcppExports.R")
source("plotDensityClust.R")
source("densityClust.R")
#sourceCpp("RcppExports.cpp")
sourceCpp("localDensity.cpp")
sourceCpp("findDistValueByRowColInd.cpp")
sourceCpp("distanceToPeak.cpp")
```
```{r}
```
---------------BCI Data Prep--------------------------
#Read in the BCI Data
```{r}
Colnames = c('X','Y','Weight')
BCI_3_Null <- read.csv(file.choose(), header = FALSE)
#dimnames(BCI_3_Null) <- NULL
```
```{r}
BCI_Weights <- as.vector(BCI_3_Null[,3])
BCI_Noweights <- as.vector(BCI_3_Null[,1:2])
BCIDist <- dist(BCI_3_Null[,1:2])
```
---------------BCI Data with Rodriguez Clustering--------------------------
#cluster with non-gaussian distance
```{r}
BCIClust <- densityClust(BCI_Noweights, BCI_Weights, BCIDist, gaussian=TRUE, verbose = TRUE)
```
#get validation metrics fro rho/gamma combinations
```{r}
BCIChart1 <- findCluster_validationChart(BCIClust, DBCV = FALSE, status = FALSE)
View(BCIChart1)
```
#Plot the BCI Data with Chosen Clusters
```{r}
plot(BCIClust) # Inspect clustering attributes to define thresholds
BCIClust <- findClusters(BCIClust, rho=4.01, delta=0.21, verbose = FALSE)
#BCIClust <- findClusters_DBCV(BCIClust, rho=338, delta=0.21, verbose = FALSE)
BCIRAW = plotRAW(BCIClust)
BCIMDS = plotMDS(BCIClust)
BCITSNE = plotTSNE(BCIClust)
#split(iris[,5], BCIClust$clusters)
```
---------------BCI Weights as third dimension--------------------------
```{r}
BCI_Weights <- rep(1,224)
BCI_Noweights <- as.vector(BCI_3_Null[,1:3])
BCIDist <- dist(BCI_3_Null[,1:2])
```
```{r}
BCIClust <- densityClust(BCI_Noweights, BCI_Weights, BCIDist, gaussian=TRUE, verbose = TRUE)
```
```{r}
BCIChart2 <- findCluster_validationChart(BCIClust, DBCV = FALSE, status = FALSE)
View(BCIChart2)
```
```{r}
plot(BCIClust)
BCIClust <- findClusters(BCIClust, rho=2.31, delta=0.101, verbose = FALSE)
BCIRAW = plotRAW(BCIClust)
BCIMDS = plotMDS(BCIClust)
BCITSNE = plotTSNE(BCIClust)
```
---------Test Iris Code/ Old Code---------------
```{r}
iris <- iris
noweights <- rep(1,150)
irisDist <- dist(iris[,1:4])
irisClust <- densityClust(iris[,1:4], noweights, irisDist, gaussian=TRUE)
plot(irisClust) # Inspect clustering attributes to define thresholds
```
```{r}
irisChart <- findCluster_validationChart(irisClust)
```
```{r}
irisClust <- findClusters(irisClust, rho=0.01, delta=0.74)
raw = plot(irisClust)
mds = plotMDS(irisClust)
tsne = plotTSNE(irisClust)
#split(iris[,5], irisClust$clusters)
```
Create A Formatted Dataset where each value is multiplied to fit it's num of observations
```{r}
total = nrow(BCI_3_Null)
BCI_3_Format <- data.frame("Cord1" = double(), "Cord2" = double())
for (i in 1:total){
for (j in 1:(BCI_3_Null[i,3])){
newRow <- BCI_3_Null[i,1:2]
BCI_3_Format<- rbind(BCI_3_Format, newRow)
}
}
```
```{r}
same = 0
frame = BCI_3_Null
total = nrow(frame)
for (i in 1:total){
for (j in 1:total){
if ((i != j) & (frame[i,1] == frame[j,1]) & (frame[i,2] == frame[j,2])){
same = 1
cat("same value detected at rows ")
i
j
}
}
}
if (same == 0){
cat("no rows same ")
}
```
#make sure distance has no 0 values
```{r}
BCIDist <- dist(BCI_3_Null[,1:2])
d = as.matrix(BCIDist)
same = 0
total = nrow(d)
for (i in 1:total){
for (j in 1:total){
if ((i != j) & (d[i,j] == 0.0)){
same = 1
cat("same dist detected at rows ")
i
j
}
}
}
if (same == 0){
cat("no dist = 0 ")
}
```
#cluster without gaussian distance
```{r}
BCIDist <- dist(BCI_3_Null[,1:2])
BCIClust <- densityClust(BCIDist, gaussian=FALSE)
plot(BCIClust) # Inspect clustering attributes to define thresholds
BCIClust2 <- findClusters(BCIClust, rho=5, delta=0.15, verbose = TRUE)
plotMDS(BCIClust2)
#split(iris[,5], BCIClust$clusters)
```