Commit 4538f667 authored by Sebastian Schweer's avatar Sebastian Schweer

Small release. API to present_results slimmed down, added docu

parent 1ba11889
Package: queueingnetworkR
Title: Simulation and Estimation of a Geom/Geom/infty Tandem Network
Version: 0.0.1
Version: 0.1.0
[email protected]: person("Sebastian", "Schweer", email = "[email protected]", role = c("aut", "cre"))
Description: Simulation and Documentation for the Paper "Nonparametric Estimation of the Service Time Distribution in Discrete-Time Queueing Networks" by Cornelia Wichelhaus and Sebastian Schweer
Depends: R (>= 3.4.2), utils, stats, ggplot2, plyr, reshape2
......
......@@ -3,12 +3,18 @@
export(present_estimates)
export(queueing_network_poi_geom)
importFrom(ggplot2,aes)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_step)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggtitle)
importFrom(ggplot2,theme_bw)
importFrom(ggplot2,ylab)
importFrom(ggplot2,ylim)
importFrom(plyr,adply)
importFrom(reshape2,melt)
importFrom(stats,dgeom)
importFrom(stats,pgeom)
importFrom(stats,rbinom)
importFrom(stats,rgeom)
importFrom(stats,rpois)
importFrom(utils,head)
importFrom(utils,setTxtProgressBar)
......
......@@ -12,7 +12,7 @@
#' a column rep_id for each repetition, delta_reulst_df contains the same result, with
#' each value normalized by the theoretical g_2, plot_result and plot_delta_result are
#' ggplots for the result data sets.
#' @importFrom ggplot2 ggplot geom_line aes
#' @importFrom ggplot2 ggplot geom_step aes ylim theme_bw ggtitle ylab
#' @importFrom plyr adply
#' @importFrom reshape2 melt
#' @importFrom stats dgeom pgeom
......@@ -27,31 +27,90 @@ present_estimates <- function(n_reps, max_lag, G_2, ...){
result_df = as.data.frame(t(result_set))
colnames(result_df) = paste0("est_g2_", c(1:(max_lag - 1)))
result_G2_df = adply(result_df, 1, estimate_G2)[, c((max_lag):(2*(max_lag - 1)))]
colnames(result_G2_df) = paste0("est_G2_", c(1:(max_lag - 1)))
g_2_true = dgeom(c(1:(max_lag - 1)), G_2)
G_2_true = pgeom(c(1:(max_lag - 1)), G_2)
# Theoretical distributions
g_2_true = as.numeric(dgeom(c(0:(max_lag - 2)), G_2))
G_2_true = as.numeric(pgeom(c(0:(max_lag - 2)), G_2))
# Append the true distribution to plot it
result_G2_df = rbind(G_2_true, result_G2_df)
colnames(result_G2_df) = paste0("est_G2_", c(1:(max_lag - 1)))
delta_result_df = sweep(result_df, 2, g_2_true)
delta_result_G2_df = sweep(result_G2_df, 2, G_2_true)
colnames(delta_result_df) = paste0("delta_", colnames(result_df))
colnames(delta_result_G2_df) = paste0("delta_", colnames(result_G2_df))
result_df$rep_id = as.factor(index_set)
delta_result_df$rep_id = as.factor(index_set)
result_G2_df$rep_id = as.factor(index_set)
delta_result_G2_df$rep_id = as.factor(index_set)
#delta_result_df$rep_id = as.factor(index_set)
result_G2_df$rep_id = as.factor(c("True", index_set))
levels(result_G2_df$rep_id) <- c("True Dist", index_set)
#delta_result_G2_df$rep_id = as.factor(index_set)
plot_result_G2_df = melt(result_G2_df, id.vars = 'rep_id')
plot_result_G2 = ggplot(plot_result_G2_df, aes(x = variable, y = value)) + geom_line(aes(color = rep_id, group = rep_id))
plot_delta_result_df = melt(delta_result_df, id.vars = 'rep_id')
plot_delta_result = ggplot(plot_delta_result_df, aes(x = variable, y = value)) + geom_line(aes(color = rep_id, group = rep_id))
plot_result_G2 = ggplot(plot_result_G2_df, aes(x = variable, y = value)) +
geom_step(aes(linetype = rep_id, group = rep_id)) +
ylim(0,1) +
theme_bw() +
ggtitle(paste0("Distribution of ", n_reps, " repetitions of the Cross-Covariance Estimator")) +
ylab("G_2")
#plot_delta_result_df = melt(delta_result_df, id.vars = 'rep_id')
#plot_delta_result = ggplot(plot_delta_result_df, aes(x = variable, y = value)) + geom_line(aes(color = rep_id, group = rep_id))
return(list(result_df = result_df
, result_G2_df = result_G2_df
, delta_result_df = delta_result_df
, delta_result_G2_df = delta_result_G2_df
#, delta_result_df = delta_result_df
#, delta_result_G2_df = delta_result_G2_df
, plot_result_G2 = plot_result_G2
, plot_delta_result = plot_delta_result
#, plot_delta_result = plot_delta_result
))
}
\ No newline at end of file
}
#
#
# load("~/Downloads/resultate.zip")
# present <- rbind(firstrun$result_G2_df, c(0.5,pgeom(c(1:9), 0.5), "Null"))
#
# library(ggplot2)
# library(reshape2)
# library(plyr)
# result_df <- firstrun$result_df
# result_G2_df <- rbind(as.numeric(c(0.5,pgeom(c(1:9), 0.5), NA)), firstrun$result_G2_df)
#
# result_G2_df$rep_id[1] <- "True Dist."
#
# max_lag <- 8
# G_2 <- 0.5
# index_set <- c(c(1:3), "True Dist")
#
# g_2_true = dgeom(c(0:(max_lag)), G_2)
# G_2_true = pgeom(c(0:(max_lag)), G_2)
# delta_result_df = sweep(result_df, 2, g_2_true)
# delta_result_G2_df = sweep(result_G2_df, 2, G_2_true)
# colnames(delta_result_df) = paste0("delta_", colnames(result_df))
# colnames(delta_result_G2_df) = paste0("delta_", colnames(result_G2_df))
#
# result_df$rep_id = as.factor(index_set)
# delta_result_df$rep_id = as.factor(index_set)
# result_G2_df$rep_id = as.factor(index_set)
# levels(result_G2_df$rep_id) <- c("True Dist", c(1:3))
# result_G2_df <- cbind(as.numeric(c(0,0,0,0)), result_G2_df)
# colnames(result_G2_df) <- c("est_G2_0", colnames(result_G2_df[2:11]))
# delta_result_G2_df$rep_id = as.factor(index_set)
#
# plot_result_G2_df = melt(result_G2_df, id.vars = 'rep_id')
# plot_result_G2 = ggplot(plot_result_G2_df, aes(x = variable, y = value)) +
# geom_step(aes(linetype = rep_id, group = rep_id)) +
# ylim(0,1) +
# theme_bw() +
# ggtitle("Distribution of 3 repetitions of the Cross-Covariance Estimator") +
# ylab("G_2")
#
# plot_delta_result_df = melt(delta_result_df, id.vars = 'rep_id')
# plot_delta_result = ggplot(plot_delta_result_df, aes(x = variable, y = value)) + geom_line(aes(color = rep_id, group = rep_id))
#
# plot_delta_result
# plot_result_G2
\ No newline at end of file
......@@ -120,6 +120,24 @@ fill_vector_with_zeros <- function(vector, lead, length){
))
}
#' Simulate the movement of a single customer through the Network
#'
#' For any singular customer, thsi function calculates the service times and
#' routing pathways for the journey through the network
#'
#' @param enter_node Entry node of the customer, either 1 or 2.
#' @param p_12 Numeric, in [0,1], routing probability from node 1 to node 2
#' @param p_21 Numeric, in [0,1], routing probability from node 2 to node 1
#' @param G_1 Numeric (in [0,1]), parameter steering the (Geometric) service
#' time distribution at node 1
#' @param G_2 Numeric (in [0,1]), parameter steering the (Geometric) service
#' time distribution at node 2
#' @return Numeric vector, consisitng of (integer) service times, starting at
#' the entry node of the customer
#' @importFrom stats rgeom rbinom
simulate_single_customer <- function(enter_node, p_12, p_21, G_1, G_2){
if(p_12 < 1 & p_12 >= 0 & p_21 < 1 & p_12 >= 0 & G_1 < 1 & G_1 >= 0 & G_2 < 1 & G_2 >= 0){
......
......@@ -15,18 +15,27 @@ Here is a running example to try out:
```{r}
p_12 = 0.1
p_21 = 0.2
p_21 = 0.7
n_obs = 1000
burn_in = 1000
lambda_1 = 1
burn_in = 5000
lambda_1 = 0.8
lambda_2 = 0.3
G_1 = 0.3
G_2 = 0.9
G_1 = 0.2
G_2 = 0.5
firstrun <- present_estimates(n_reps = 10, max_lag = 10, p_12 = p_12, p_21 = p_21, n_obs = n_obs, burn_in = burn_in,
lambda_1 = lambda_1, lambda_2 = lambda_2, G_1 = G_1, G_2 = G_2,
progress = TRUE)
firstrun
ggsave("result_G2_plot.png", plot = firstrun$plot_result_G2, device = "png")
ggsave("delta_result_plot.png", plot = firstrun$plot_delta_result, device = "png")
test <- present_estimates(n_reps = 10, max_lag = 5, p_12 = p_12, p_21 = p_21, n_obs = n_obs, burn_in = burn_in,
lambda_1 = lambda_1, lambda_2 = lambda_2, G_1 = G_1, G_2 = G_2,
progress = TRUE)
system(paste0("mpack -s 'Skript durchgelaufen mit ", n_obs, " Beobachtungen: Plot G2' result_G2_plot.png [email protected]"))
system(paste0("mpack -s 'Skript durchgelaufen mit ", n_obs, " Beobachtungen: Plot G2' delta_result_plot.png [email protected]"))
```
This leads to plots:
......@@ -41,3 +50,6 @@ As well as
```{r, echo=FALSE}
test$plot_delta_result
```
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/queueing_network.R
\name{simulate_single_customer}
\alias{simulate_single_customer}
\title{Simulate the movement of a single customer through the Network}
\usage{
simulate_single_customer(enter_node, p_12, p_21, G_1, G_2)
}
\arguments{
\item{enter_node}{Entry node of the customer, either 1 or 2.}
\item{p_12}{Numeric, in [0,1], routing probability from node 1 to node 2}
\item{p_21}{Numeric, in [0,1], routing probability from node 2 to node 1}
\item{G_1}{Numeric (in [0,1]), parameter steering the (Geometric) service
time distribution at node 1}
\item{G_2}{Numeric (in [0,1]), parameter steering the (Geometric) service
time distribution at node 2}
}
\value{
Numeric vector, consisitng of (integer) service times, starting at
the entry node of the customer
}
\description{
For any singular customer, thsi function calculates the service times and
routing pathways for the journey through the network
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment