~bendersteed/markov-chains-web-navigation

95d45081cf3a711ccf163fc75db92f5980080c47 — Dimos Dimakakos 1 year, 9 months ago eea495d
Fix: add option for skipping input lines
1 files changed, 4 insertions(+), 4 deletions(-)

M markov-chain-navigation.r
M markov-chain-navigation.r => markov-chain-navigation.r +4 -4
@@ 1,8 1,8 @@
library(tidyverse)

## παίρνει τις διαδρομές και τις κάνει character vectors
parseData <- function(data_file) {
    sapply(Filter(function(x) {nchar(x) > 2}, readLines(data_file)), function(x) { strsplit(x, " ") })
parseData <- function(data_file, skip) {
    sapply(Filter(function(x) {nchar(x) > 2}, read_lines(data_file, skip = skip)), function(x) { strsplit(x, " ") })
}

topics <- c("frontpage", "news", "tech", "local", "opinion", "on-air", "misc", "weather", "msn-news",


@@ 92,8 92,8 @@ bic <- function(likelihood_ratio, dof, observation_count) {



simulation <- function(input, k, states, topics) {
    data <- parseData(input)
simulation <- function(input, k, states, topics = topics, skip = 7) {
    data <- parseData(input, skip)

    freqs <- sapply(0:k, function (x) { fitPaths(data, x, states) })
    zero_order <- tail(freqs[[1]][[1]], n = states) # remove reset element count for the calculation