Skip to content

Commit

Permalink
Merge branch 'develop' into multithreaded
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/org/matsim/episim/analysis/AnalyzeSnzData.java
#	src/main/java/org/matsim/run/batch/BerlinPercolation.java
#	src/main/java/org/matsim/run/batch/StrainPaperAdaptivePolicy.java
#	src/main/java/org/matsim/run/modules/SnzBerlinProductionScenario.java
#	src/main/java/org/matsim/run/modules/SnzDresdenScenario.java
#	src/main/java/org/matsim/run/modules/SyntheticScenario.java
#	src/main/java/org/matsim/scenarioCreation/RunTrial.java
#	src/main/python/analysis/percolation.py
  • Loading branch information
rakow committed Jun 18, 2021
2 parents 3103463 + b9f9c38 commit 12bb9a6
Show file tree
Hide file tree
Showing 32 changed files with 3,261 additions and 795 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
![Build Status](https://github.com/matsim-org/matsim-episim-libs/workflows/build/badge.svg?branch=master)
![license](https://img.shields.io/github/license/matsim-org/matsim-episim.svg)
![JDK](https://img.shields.io/badge/JDK-11+-green.svg)
[![Join the chat at https://gitter.im/matsim-episim-libs/community](https://badges.gitter.im/matsim-episim-libs/community.svg)](https://gitter.im/matsim-episim-libs/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)


This repository contains an epidemic simulation based on MATSim, provided by the [Transport Systems Planning and Transport Telematics group](https://www.vsp.tu-berlin.de) of [Technische Universität Berlin](https://www.tu-berlin.de).
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.matsim-org</groupId>
<artifactId>matsim-episim</artifactId>
<version>21.4-SNAPSHOT</version>
<version>21.5-SNAPSHOT</version>

<name>MATSim Episim</name>
<description>Epidemic simulation for MATSim</description>
Expand Down
12 changes: 11 additions & 1 deletion scenarios/Germany.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@ $(out)/germany_snz_entirePopulation_emptyPlans_100pt.xml.gz:
$(out)/germany_snz_entirePopulation_emptyPlans_withDistricts_100pt.xml.gz: $(out)/germany_snz_entirePopulation_emptyPlans_100pt.xml.gz
$(sc) districtLookup $<\
--output $@\
--shp ../public-svn/matsim/scenarios/countries/de/episim/original-data/landkreise-in-germany/landkreise-in-germany.shp
--shp ../public-svn/matsim/scenarios/countries/de/episim/original-data/landkreise-in-germany/landkreise-in-germany.shp

$(out)/germany_snz_entirePopulation_emptyPlans_withDistricts_25pt.xml.gz: $(out)/germany_snz_entirePopulation_emptyPlans_withDistricts_100pt.xml.gz
$(sc) downSample 0.25\
--population $<\
--events $(in)/de2020gsmwt_events_reduced.xml.gz\
--events $(in)/de2020gsmsa_events_reduced.xml.gz\
--events $(in)/de2020gsmso_events_reduced.xml.gz\
--output $(tmp)

mv $(tmp)/population0.25.xml.gz $(out)/germany_snz_entirePopulation_emptyPlans_withDistricts_25pt.xml.gz
196 changes: 99 additions & 97 deletions src/main/python/analysis/dispersion.R → src/main/R/dispersion.R
Original file line number Diff line number Diff line change
@@ -1,97 +1,99 @@

library(fitdistrplus)
library(dplyr)
library(purrr)
library(ggplot2)
library(reticulate)

use_miniconda(required = TRUE)

np <- import("numpy")

f <- "C:/home/Development/matsim-org/matsim-episim/output-berlin-25pct-superSpreader-calibrParam-1.65E-5/infectionEvents.txt"
f <- "C:/home/Development/matsim-org/matsim-episim/output-berlin-25pct-superSpreader-calibrParam-2.7E-5/infectionEvents.txt"
f <- "C:/home/Development/matsim-org/matsim-episim/output-base/infectionEvents.txt"

counts <- function(f) {

data <- read.csv(f, sep = "\t")

df <- table(data[[2]])

v <- as.numeric(df)

# Persons who did not infect other persons
no_inf <- setdiff(data$infected, data$infector)

res <- sort(c(rep(0, length(no_inf)), v))
}

est_disp <- function(f) {

matrix <- np$load(f)

est <- list()
inf80 <- list()

for(row in 1:nrow(matrix)) {

sprintf("Processing row %d\n", row)
v <- matrix[row,]
v <- v[!is.na(v)]

if (length(v) == 0) {
next
}

fit <- try(fitdist(v, fix.arg=list(mu=2.5), "nbinom"), silent = T)
if(inherits(fit, "try-error")) {
fit <- list(estimate=NaN)
}

est <- c(est, as.numeric(fit$estimate))

total = sum(v)
s80 <- v[0:-length(v) * 0.8]

inf80 <- c(inf80, sum(s80) * 100 / total)

}

df <- data.frame(as.numeric(est), as.numeric(inf80))
colnames(df) <- c("est", "top20")

return(df)
}


est_disp_zip <- function(f) {

tmpdir <- tempdir()
unzip(f, exdir = tmpdir )

res <- data.frame()

for (f in list.files(tmpdir, pattern = "*.npy", full.names = T)) {
df <- est_disp(f)
means <- colMeans(df, na.rm = T)
df <- data.frame(t(means))

row.names(df) <- c(basename(f))

res <- rbind(res, df)
}

return(res)
}

setwd("C:/home/Development/matsim-org/matsim-episim/src/main/python/analysis")


df <- est_disp_zip("data/infections.zip")

# Testing the distribution
df <- sort(rnbinom(15000, size=1, mu=2.5))
plot(hist(df, breaks = 30))

ggplot() + aes(df) + geom_histogram(binwidth=1, colour="black", fill="white", alpha=0.2)

library(fitdistrplus)
library(dplyr)
library(purrr)
library(ggplot2)
library(reticulate)

use_miniconda(required = TRUE)

np <- import("numpy")

f <- "C:/home/Development/matsim-org/matsim-episim/output-berlin-25pct-superSpreader-calibrParam-1.65E-5/infectionEvents.txt"
f <- "C:/home/Development/matsim-org/matsim-episim/output-berlin-25pct-superSpreader-calibrParam-2.7E-5/infectionEvents.txt"
f <- "C:/home/Development/matsim-org/matsim-episim/output-base/infectionEvents.txt"

counts <- function(f) {

data <- read.csv(f, sep = "\t")

df <- table(data[[2]])

v <- as.numeric(df)

# Persons who did not infect other persons
no_inf <- setdiff(data$infected, data$infector)

res <- sort(c(rep(0, length(no_inf)), v))
}

est_disp <- function(f, mu=1) {

matrix <- np$load(f)

est <- list()
inf80 <- list()

# Loaded vector is one row
v <- as.numeric(matrix)
#for(row in 1:nrow(matrix)) {

#sprintf("Processing row %d\n", row)
#v <- matrix[row,]
v <- v[!is.na(v)]

if (length(v) == 0) {
next
}

fit <- try(fitdist(v, fix.arg=list(mu=mu), "nbinom"), silent = T)
if(inherits(fit, "try-error")) {
fit <- list(estimate=NaN)
}

est <- c(est, as.numeric(fit$estimate))

total = sum(v)
s80 <- v[0:-length(v) * 0.8]

inf80 <- c(inf80, sum(s80) * 100 / total)

#}

df <- data.frame(as.numeric(est), as.numeric(inf80))
colnames(df) <- c("est", "top20")

return(df)
}


est_disp_zip <- function(f) {

tmpdir <- tempdir()
unzip(f, exdir = tmpdir )

res <- data.frame()

for (f in list.files(tmpdir, pattern = "*.npy", full.names = T)) {
df <- est_disp(f)
means <- colMeans(df, na.rm = T)
df <- data.frame(t(means))

row.names(df) <- c(basename(f))

res <- rbind(res, df)
}

return(res)
}

setwd("C:/Users/chris/Development/matsim-org/matsim-episim/biggest-jan")

est_disp("0.46.npy")
est_disp("0.56.npy")

# Testing the distribution
df <- sort(rnbinom(15000, size=1, mu=2.5))
plot(hist(df, breaks = 30))

ggplot() + aes(df) + geom_histogram(binwidth=1, colour="black", fill="white", alpha=0.2)
Loading

0 comments on commit 12bb9a6

Please sign in to comment.