From 7b0ca6a89444b69b34f5fc54376da943e845c25f Mon Sep 17 00:00:00 2001 From: josura Date: Thu, 13 Jul 2023 10:10:28 +0200 Subject: [PATCH] additional plotting, problems with reshape2, new version of icu has broken the library --- scripts/R/plotTimeSeriesToyExample.R | 10 ++++++--- scripts/R/testingComputation.R | 33 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 scripts/R/testingComputation.R diff --git a/scripts/R/plotTimeSeriesToyExample.R b/scripts/R/plotTimeSeriesToyExample.R index 8300aff..4170b7d 100644 --- a/scripts/R/plotTimeSeriesToyExample.R +++ b/scripts/R/plotTimeSeriesToyExample.R @@ -2,7 +2,9 @@ library(ggplot2) timeSeries.t0 <- read.csv("/home/josura/Projects/ccc/c2c-sepia/outputsTimeSeries/t2_outputAll.tsv",sep = "\t",header = TRUE) -library(reshape2) +library(tidyverse) + + x <- timeSeries.t0[, 1] y <- timeSeries.t0[, (ncol(timeSeries.t0)-11):ncol(timeSeries.t0)] @@ -12,10 +14,11 @@ interesting.list <- c("v.in.t3","v.in.t1","v.out.t3","v.out.t1","v.out.t2") y.int <- timeSeries.t0[, interesting.list] # Combine x and y into a new dataframe -df_new <- data.frame(x = rep(x, ncol(y)), c(y)) +df_new <- data.frame(x = rep(x, ncol(y)), y) # Convert y columns into a single column -df_new <- melt(df_new, id.vars = "x") +df_new <- df_new %>% + pivot_longer(cols = starts_with("v."), names_to = "variable", values_to = "value") # Plot the matrix of scatter plots ggplot(df_new, aes(x = x, y = value, color = variable)) + @@ -23,3 +26,4 @@ ggplot(df_new, aes(x = x, y = value, color = variable)) + labs(x = "X Axis", y = "Y Axis") + scale_color_discrete(name = "Y Variables") + facet_wrap(~ variable, ncol = 3) # Adjust the number of columns as needed + diff --git a/scripts/R/testingComputation.R b/scripts/R/testingComputation.R new file mode 100644 index 0000000..6e14a15 --- /dev/null +++ b/scripts/R/testingComputation.R @@ -0,0 +1,33 @@ +library(MASS) + +matriceTest <- t(matrix(c(0,0.2,0.4,0.5,0,0,0,0, + 0.2,0,0.4,0.5,0,0,1,0, + 0.3,0.2,0,0.5,0,0,0,0, + 0.4,0.2,0.4,0,0,0,0,1, + 0,1,0,0,0,0,0,0, + 1,1,1,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0),nrow=8)) + +normalizedMatrix <- apply(t(matriceTest), 2, function(col) { + if (sum(col) != 0) { + col / sum(col) + } else { + rep(0, length(col)) + } +}) + + +# Creating the identity matrix with the same dimensions as normalizedMatrix +identityMatrix <- diag(nrow(normalizedMatrix)) + +# Subtracting the transpose of the normalizedMatrix from the identity matrix +resultMatrix <- identityMatrix - normalizedMatrix + +inverted <- ginv(resultMatrix) + +input <- c(1,1,0.1,2,0,0,0,0) + +perturbation <- inverted %*% input + +perturvation.conserverd <- inverted %*% input - (input/2)