Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ShinySbm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VANRENTERGHEM Théodore
ShinySbm
Commits
63b757f4
Commit
63b757f4
authored
1 year ago
by
VANRENTERGHEM Théodore
Browse files
Options
Downloads
Patches
Plain Diff
file in progress
parent
722105af
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
R/building_new_table.R
+103
-101
103 additions, 101 deletions
R/building_new_table.R
with
103 additions
and
101 deletions
R/building_new_table.R
+
103
−
101
View file @
63b757f4
get_datatable
<-
function
(
model
,
matrix
,
type
=
c
(
'raw'
,
'ordered'
,
'predicted'
)){
UseMethod
(
"get_datatable"
,
model
)
}
get_datatable.default
<-
function
(
model
,
matrix
,
type
=
c
(
'raw'
,
'ordered'
,
'predicted'
)){
return
(
NULL
)
}
### still need to make table and build them as dataframe as doing this for simple sbm
get_datatable.BipartiteSBM
<-
function
(
model
,
matrix
,
type
=
c
(
'raw'
,
'ordered'
,
'predicted'
)){
if
(
type
[[
1
]]
==
'raw'
){
return
(
shinySbm
:::
as.data.frame.sbmMatrix
(
matrix
))
}
else
{
clustering
<-
setNames
(
model
$
memberships
,
c
(
"row"
,
"col"
))
oRow
<-
order
(
clustering
$
row
,
decreasing
=
TRUE
)
oCol
<-
order
(
clustering
$
col
)
uRow
<-
cumsum
(
table
(
clustering
$
row
))
+
0.5
uCol
<-
cumsum
(
table
(
clustering
$
col
))
+
0.5
if
(
type
[[
1
]]
==
'ordered'
){
oMat
<-
model
$
networkData
[
oRow
,
oCol
]
%>%
`colnames<-`
(
matrix
$
nodes_names
$
col
[
oCol
])
%>%
`rownames<-`
(
matrix
$
nodes_names
$
row
[
oRow
])
%>%
as.data.frame
()
return
(
oMat
)
}
else
{
pMat
<-
model
$
connectParam
$
mean
[
clustering
$
row
,
clustering
$
col
][
oRow
,
oCol
]
%>%
`colnames<-`
(
matrix
$
nodes_names
$
col
[
oCol
])
%>%
`rownames<-`
(
matrix
$
nodes_names
$
row
[
oRow
])
%>%
as.data.frame
()
return
(
pMat
)
}
}
}
get_datatable.SimpleSBM
<-
function
(
model
,
matrix
,
type
=
c
(
'raw'
,
'ordered'
,
'predicted'
)){
if
(
type
[[
1
]]
==
'raw'
){
return
(
shinySbm
:::
as.data.frame.sbmMatrix
(
matrix
))
}
else
{
clustering
<-
list
(
row
=
model
$
memberships
,
col
=
model
$
memberships
)
if
(
ordered
)
{
oRow
<-
order
(
clustering
$
row
)
uRow
<-
cumsum
(
table
(
clustering
$
row
))
+
0.5
uCol
<-
uRow
[
-
length
(
uRow
)]
uRow
<-
uRow
[
length
(
uRow
)]
-
uRow
[
-
length
(
uRow
)]
+
0.5
nb_rows
<-
dim
(
model
$
networkData
)[
1
]
if
(
type
[[
1
]]
==
'ordered'
){
oMat
<-
model
$
networkData
[
oRow
,
oRow
][
nb_rows
:
1
,
]
%>%
`colnames<-`
(
matrix
$
nodes_names
[
oRow
])
%>%
`rownames<-`
(
matrix
$
nodes_names
[
oRow
][
nb_rows
:
1
])
%>%
as.data.frame
()
return
(
oMat
)
}
else
{
pMat
<-
model
$
connectParam
$
mean
[
clustering
$
row
,
clustering
$
col
][
oRow
,
oRow
][
nb_rows
:
1
,
]
%>%
`colnames<-`
(
matrix
$
nodes_names
[
oRow
])
%>%
`rownames<-`
(
matrix
$
nodes_names
[
oRow
][
nb_rows
:
1
])
%>%
as.data.frame
()
return
(
pMat
)
}
}
}
}
library
(
shinySbm
)
binetmat
<-
fungusTreeNetwork
$
fungus_tree
%>%
`colnames<-`
(
fungusTreeNetwork
$
tree_names
)
%>%
`rownames<-`
(
fungusTreeNetwork
$
fungus_names
)
bisbmmat
<-
binetmat
%>%
as.data.frame
()
%>%
shinySbm
:::
buildSbmMatrix
()
bisbm
<-
estimateBipartiteSBM
(
netMat
=
bisbmmat
$
matrix
,
model
=
'bernoulli'
,
estimOptions
=
list
(
plot
=
T
,
verbosity
=
3
))
uninetmat
<-
fungusTreeNetwork
$
tree_tree
%>%
`colnames<-`
(
fungusTreeNetwork
$
tree_names
)
%>%
`rownames<-`
(
fungusTreeNetwork
$
tree_names
)
unisbmmat
<-
uninetmat
%>%
as.data.frame
()
%>%
shinySbm
:::
buildSbmMatrix
()
unisbm
<-
estimateBipartiteSBM
(
netMat
=
unisbmmat
$
matrix
,
model
=
'poisson'
,
estimOptions
=
list
(
plot
=
T
,
verbosity
=
3
))
get_datatable
(
bisbm
,
bisbmmat
,
type
=
c
(
'raw'
,
'ordered'
,
'predicted'
)[
3
])
%>%
View
get_datatable
(
unisbm
,
unisbmmat
,
type
=
c
(
'raw'
,
'ordered'
,
'predicted'
)[
3
])
%>%
View
# remember to change my ref from row and col to first and scnd col
# get_datatable <- function(model,matrix, type = c('raw','ordered','predicted')){
# UseMethod("get_datatable",model)
# }
#
# get_datatable.default <- function(model,matrix, type = c('raw','ordered','predicted')){
# return(NULL)
# }
#
# ### still need to make table and build them as dataframe as doing this for simple sbm
# get_datatable.BipartiteSBM <- function(model,matrix, type = c('raw','ordered','predicted')){
# if(type[[1]] == 'raw'){
# return(shinySbm:::as.data.frame.sbmMatrix(matrix))
# }else{
# clustering <- setNames(model$memberships, c("row", "col"))
# oRow <- order(clustering$row, decreasing = TRUE)
# oCol <- order(clustering$col)
# uRow <- cumsum(table(clustering$row)) + 0.5
# uCol <- cumsum(table(clustering$col)) + 0.5
# if(type[[1]] == 'ordered'){
# oMat <- model$networkData[oRow, oCol] %>%
# `colnames<-`(matrix$nodes_names$col[oCol]) %>%
# `rownames<-`(matrix$nodes_names$row[oRow]) %>%
# as.data.frame()
# return(oMat)
# }else{
# pMat <- model$connectParam$mean[clustering$row, clustering$col][oRow, oCol] %>%
# `colnames<-`(matrix$nodes_names$col[oCol]) %>%
# `rownames<-`(matrix$nodes_names$row[oRow]) %>%
# as.data.frame()
# return(pMat)
# }
# }
# }
#
#
# get_datatable.SimpleSBM <- function(model,matrix, type = c('raw','ordered','predicted')){
# if(type[[1]] == 'raw'){
# return(shinySbm:::as.data.frame.sbmMatrix(matrix))
# }else{
# clustering <- list(row = model$memberships, col = model$memberships)
# if (ordered) {
# oRow <- order(clustering$row)
# uRow <- cumsum(table(clustering$row)) + 0.5
# uCol <- uRow[-length(uRow)]
# uRow <- uRow[length(uRow)] - uRow[-length(uRow)] + 0.5
# nb_rows <- dim(model$networkData)[1]
# if(type[[1]] == 'ordered'){
# oMat <- model$networkData[oRow, oRow][nb_rows:1, ] %>%
# `colnames<-`(matrix$nodes_names[oRow]) %>%
# `rownames<-`(matrix$nodes_names[oRow][nb_rows:1]) %>%
# as.data.frame()
# return(oMat)
# }else{
# pMat <- model$connectParam$mean[clustering$row, clustering$col][oRow, oRow][nb_rows:1, ] %>%
# `colnames<-`(matrix$nodes_names[oRow]) %>%
# `rownames<-`(matrix$nodes_names[oRow][nb_rows:1]) %>%
# as.data.frame()
# return(pMat)
# }
# }
# }
# }
#
#
#
# library(shinySbm)
#
# binetmat <- fungusTreeNetwork$fungus_tree %>%
# `colnames<-`(fungusTreeNetwork$tree_names) %>%
# `rownames<-`(fungusTreeNetwork$fungus_names)
#
# bisbmmat <- binetmat %>%
# as.data.frame() %>%
# shinySbm:::buildSbmMatrix()
#
# bisbm <- estimateBipartiteSBM(netMat = bisbmmat$matrix, model = 'bernoulli',
# estimOptions = list(plot = T, verbosity = 3))
#
#
#
#
# uninetmat <- fungusTreeNetwork$tree_tree %>%
# `colnames<-`(fungusTreeNetwork$tree_names) %>%
# `rownames<-`(fungusTreeNetwork$tree_names)
#
# unisbmmat <- uninetmat %>%
# as.data.frame() %>%
# shinySbm:::buildSbmMatrix()
#
# unisbm <- estimateBipartiteSBM(netMat = unisbmmat$matrix, model = 'poisson',
# estimOptions = list(plot = T, verbosity = 3))
#
#
# get_datatable(bisbm,bisbmmat, type = c('raw','ordered','predicted')[3]) %>% View
#
# get_datatable(unisbm,unisbmmat, type = c('raw','ordered','predicted')[3]) %>% View
#
#
#
#
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment