FRemoved a bunch of prints, str's and cats
This commit is contained in:
22
reWeight.R
22
reWeight.R
@@ -2,7 +2,6 @@ modules::import(magrittr)
|
||||
|
||||
reWeightLayer <- function(nestedLayerTib, fudge = 1) {
|
||||
for (idx in 1:nrow(nestedLayerTib)) {
|
||||
# print(nestedLayerTib$data[idx])
|
||||
thisData <- nestedLayerTib$data[idx][[1]]
|
||||
|
||||
# Calculate the overall depletion rate
|
||||
@@ -21,35 +20,28 @@ reWeightLayer <- function(nestedLayerTib, fudge = 1) {
|
||||
|
||||
effDepRate <- survived - 1
|
||||
effGrowthRate <- 1 - grown
|
||||
# print(effDepRate)
|
||||
|
||||
if (sum(thisData$values) == 0) {
|
||||
newValues <- rep(0, length(thisData$values))
|
||||
} else {
|
||||
newValues <- round(thisData$values / sum(thisData$values) * (effDepRate + effGrowthRate), digits = 3)
|
||||
}
|
||||
# print(paste(idx, paste(newValues, collapse=",")))
|
||||
|
||||
nestedLayerTib$data[idx][[1]]$values <- newValues / fudge
|
||||
}
|
||||
|
||||
return(nestedLayerTib %>% tidyr::unnest(cols = c(data)))
|
||||
}
|
||||
|
||||
assignWeights <- function(edgesTib,
|
||||
incode,
|
||||
outcode,
|
||||
value) {
|
||||
assignWeights <- function(edgesTib, incode, outcode, value) {
|
||||
for (idx in 1:length(incode)) {
|
||||
ref <- intersect(
|
||||
which(edgesTib$input == incode[idx]),
|
||||
which(edgesTib$output == outcode[idx])
|
||||
)
|
||||
|
||||
utils::str(ref)
|
||||
|
||||
if (length(ref) > 1) stop("Error has occurred with multiple edges between two nodes")
|
||||
print(paste(ref, edgesTib$values[ref], value[idx]))
|
||||
edgesTib$values[ref] <- value[idx]
|
||||
# Set the appropriate values
|
||||
}
|
||||
return(edgesTib)
|
||||
}
|
||||
@@ -64,9 +56,6 @@ reWeightModel <- function(thisNet, pressStatus) {
|
||||
dplyr::left_join(thisNet$edges, by = c("code" = "input")) %>%
|
||||
dplyr::mutate(values = values * 0.9)
|
||||
|
||||
print("before")
|
||||
print(sum(p_on$values))
|
||||
|
||||
p_on <- p_on %>%
|
||||
dplyr::rename(presscode = code) %>%
|
||||
dplyr::rename(ba_code = output) %>%
|
||||
@@ -76,7 +65,6 @@ reWeightModel <- function(thisNet, pressStatus) {
|
||||
newP <- reWeightLayer(p_on, fudge = 1)
|
||||
|
||||
|
||||
|
||||
print("About to recalc ba - op")
|
||||
|
||||
# Repeat for the linkage between ba and op
|
||||
@@ -92,6 +80,7 @@ reWeightModel <- function(thisNet, pressStatus) {
|
||||
|
||||
newBA <- reWeightLayer(ba_impacted, fudge = 4)
|
||||
|
||||
|
||||
print("About to recalc op - es")
|
||||
|
||||
# Repeat for the linkage between op and es
|
||||
@@ -107,10 +96,10 @@ reWeightModel <- function(thisNet, pressStatus) {
|
||||
|
||||
newOP <- reWeightLayer(op_impacted, fudge = 2)
|
||||
|
||||
|
||||
# Check for any more links through the system
|
||||
print("About to recalc es - es")
|
||||
|
||||
|
||||
ess <- unique(newOP$es_code)
|
||||
es_impacted <- thisNet$nodes %>%
|
||||
dplyr::filter(code %in% ess) %>%
|
||||
@@ -129,6 +118,7 @@ reWeightModel <- function(thisNet, pressStatus) {
|
||||
|
||||
thisNet$edges <- assignWeights(thisNet$edges, incode, outcode, value)
|
||||
|
||||
|
||||
print("exitting reweighting process")
|
||||
|
||||
return(thisNet)
|
||||
|
||||
Reference in New Issue
Block a user