573
questions
2
votes
0
answers
72
views
Adding and Removing People within a For Loop in R [closed]
I have this 4 state Markov Chain in R:
I wrote the following (100 iteration) simulation that simulates 100 hospital patients (all patients start in state 1) and tracks which state they are in during ...
0
votes
1
answer
33
views
Transition matrices to fractional powers
I have a series of cumulative transition matrices (5y, 10y, ..., 30y), and am trying to get the one year annualised transition matrices defined as
1-Year Matrix ^ T = T-year Matrix
So I am solving for ...
1
vote
1
answer
42
views
Unable to get DiscreteMarkovChain to work in PyMC
I am trying to fit a two-state regime-switching model using PyMC.
The full model is given below.
The exact details of the model are not important (if you're curious anyways, I'm trying to fit a ...
0
votes
0
answers
19
views
Creating a pseudorandom matrix with a specific determinant and specific entropy
I was sampling several markov matrices for a project, for that:
I want to create a random matrix, which
is markovian(simply it's rows sum to one) and all its elements are between 0 and 1
it has a ...
2
votes
0
answers
50
views
Creating a random Markov matrix using Numpy
A Markov matrix is a matrix whose rows sum to 1 and whose determinant is 1 (at least according to one definition).
I am able to make a unimodular matrix using the following operation:
b = b/(np.linalg....
0
votes
1
answer
34
views
Probability of visiting state k at least once during first n steps in finite state Markov Chain
Assuming a Markov Chain of $M$ states, and assuming starting from state $X_0$, I was wondering if there is a method to calculate the probability of visiting state $X_k$ at least once during first n ...
3
votes
2
answers
68
views
Error in Matrix %*% Matrix: requires numeric/complex matrix/vector arguments
I am trying to do matrix multiplication in R. I have successfully created and run the matrix Matrix1, but caught an error when trying to do the multiplication:
Matrix1 = new("markovchain", ...
0
votes
0
answers
16
views
SteadyState and verification of the Markov property for multiple Markov chains
I'm building a Markov chain model to determine the probability of two states, WS (Working State) and CFS (Complete Failure State), for production machines. I applied the following code to generate a ...
0
votes
0
answers
24
views
First economic markov model based on R heemod define_transition
I am trying to build my first economic model in R and I get this error but cannot seem to figure it out. This is my first ever question here and first ever attempt to build something in R. The ...
0
votes
0
answers
51
views
Transition probabilities in Continuous Time Markov Chain following Poisson Processes
Let's imagine we have the following states corresponding to the number of users in a system in a Continuous Time Markov Chain:
---- [10] ------ [11] ------ [12] ........... [17]
The arrival of a new ...
0
votes
0
answers
24
views
Issue with specifying a MS-VAR using JAGS in Rstudio
I was trying to run a 2-regimes Markov switching VAR model with 6 variables and 13 lags, using R2jags in R
this is the code
data <- as.matrix(rawdata[2:323, c(2, 3, 5, 9, 10, 11)])
# Model ...
0
votes
1
answer
42
views
How would I convert this 4x4 transiton matrix to a 2x2 transition matrix while maintaing that all rows sum to 1
Say I have a transition matrix with 4 states labeled 1 to 4 as follows:
matrix = [[.25,.25,.5,0],
[ 0,.25,.5,.25],
[.25,.25,.25,.25],
[.25,.25,0, .5 ]]
Say I want to ...
1
vote
0
answers
22
views
Metropolis-Hastings algorithm in a lattice
Metropolis-Hastings (MH) algorithm is a MCMC method to compute high-dimensional integrals. It is usually formulated in the continuum version, i.e. the target function to be integrated is known.
The ...
0
votes
0
answers
51
views
Google Foobar : Doomsday Fuel Not passing hidden test cases
I have a google foobar question that involves absorbing markov chains and I've come up with code that I made using a theoretical answer I found on github and it seems to work pretty well but it doesnt ...
0
votes
0
answers
29
views
Markov Channel Attribution - Removal removal_effort formula for conversion amount
For below sample data Python Package "Channel Attribution" generating removal effort values as OutPut:
What formula is used to calculate removal effort for conversion amount?
Sample Data
I ...
0
votes
0
answers
81
views
Error in checkForRemoteErrors(val) : 3 nodes produced errors; first error: Error in node Y[3,5,3] Node inconsistent with parents
I am working with the R-package R2jags. After running the code I attach below, R produced the error message: "Error in checkForRemoteErrors(val) : 3 nodes produced errors; first error: Error ...
2
votes
1
answer
232
views
Algorithm to tell whether the graph of an underlying Markov chain is aperiodic
Markov chains from probability theory have underlying graphs associated with them, where every vertex is a state of the chain and the edges represent possible transition between the states. We're ...
1
vote
0
answers
110
views
An efficient way to use a markov chain to detect how cyclical a graph is?
I've been attempting to generate continuous adjacency matrices for undirected acyclic graphs (ideally trees) using a neural network, and I was thinking that I could solve this problem by creating a ...
1
vote
1
answer
74
views
How to make a reproducible example of 2nd Markov Chain Model or Higher in R?
I will start define a vector of values like this:
data <- c(2.3, 1.7, 1.7, 1.4, 1.7, 2.0, 2.2, 1.8, 1.7, 1.6, 2.0, 1.5, 1.1, 1.4, 1.8, 2.0, 1.5, 1.2, 1.0, 1.2, 1.5, 1.6, 1.1,
1.5, 2.0, 2.1, 2....
1
vote
1
answer
134
views
How to generate a sample using n-order Markov Chains with R?
I'm attempting to generate a sample from an n-order transition matrix using Markov Chains in R. I've successfully constructed this n-order transition matrix using the following code:
set.seed(1)
dat &...
0
votes
0
answers
151
views
Why does utilizing a simple strategy of Tic Tac Toe lower the AI's win rate?
I have a huge project that is a GUI Tic Tac Toe game, it has 6 AI players and offers you the opportunity to customize the UI. I have completed what I originally intended and posted it on Code Review, ...
0
votes
0
answers
97
views
MCMC algorithm for chemical kinetic parameter estimation
I'm currently envolved in application of MCMC algorithm to kinetic parameter estimation concerning the example reported below as part of the following reference.
Beers, Kenneth. Numerical Methods for ...
0
votes
0
answers
110
views
In RL how to tell an agent that some actions in the action space are currently not available in gym?
I want to make a task allocation decision by reinforcement learning. Suppose there are N tasks to be allocated and M severs to complete these task.
However, there is a constraint that one task should ...
1
vote
1
answer
1k
views
How to implement a Markov Chain in python for a squared spatial grid?
I'd like to understand how to implement in python a Markov Chain on a 2D grid (a 2D numpy array) given the values for all the states (positions) of the grid and also the transition matrix between all ...
1
vote
0
answers
38
views
Coerce the output of function markovchain::fitHigherOrder( ) to the same class as the output of markovchain::markovchainFit( )?
I'm working with the markovchain package in R to generate rudimentary sentences using Markov chains. I have successfully applied a function published on RPubs (Ref 1) named create_me to a text file of ...
0
votes
0
answers
101
views
Endless loop in a text generation script
I am trying to make a simple text generator using the Bulgarian language but my code is stuck in an endless loop. Here is the code:
from tokenization import tokenize_bulgarian_text
from nltk import ...
0
votes
0
answers
64
views
Pandas read_csv() is making more decimal digits than in original csv and thus ruins the sum of rows of dataframe
I have a markov chain related to cancer stored as csv, and each probability is up to 10 decimal digits,
Now when I am using pd.read_csv() form pandas the probabilities actually get more than 10 ...
0
votes
1
answer
70
views
Implementing Integration Limits when using Numerical Integration
I'm using numerical integration to model the trajectory of a particle passing through a non-uniform magnetic field. I'm specifically using a Markov Chain Monte Carlo algorithm (Metropolis-Hastings) ...
0
votes
2
answers
129
views
How to solve for a transition matrix in Python?
I have n vectors v_i, 1<=i<=n, and a starting vector v_0. I would like to solve for an nxn transition matrix A, s.t. A^i * v_0 = v_i for all i. What is the easiest way to implement this in ...
2
votes
0
answers
82
views
Python: how to calculate removal effect correctly using Markov Chains
I have a bunch of path-to-purchase chains, and the more I have, the more I'm getting stuck about building the graph and calculating the removal effect.
Let's imagine we have 5 different chains:
start ...
0
votes
1
answer
38
views
check whether event occurred in 30-second intervals
I have the data set with event ID and timestamp when this event happened. For example at 9/2/2019 17:06. I want to build Markov chain model with two states noevent and event. To avoid building ...
0
votes
1
answer
94
views
Cannot not find "calc.RL.0" function within "mixstock" package
I am trying to run through a mixed stock analysis in RStudio based on the walkthrough provided by Bolker (https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=...
2
votes
3
answers
289
views
How can I implement Metropolis Hastings algorithm in an undirected connected graph in R?
I have posted a problem in Stack Mathematics regarding a Metropolis Hastings algorithm in graph which someone can read it here
(A code solution is written in the stack mathematics link but it is in ...
2
votes
1
answer
187
views
Faster way to compute distributions from Markov chain?
Suppose that I have a probability transition matrix, say a matrix of dimensions 2000x2000, that represents a homogeneous Markov chain, and I want to get some statistics of each probability ...
1
vote
0
answers
142
views
LMest: problem introducing covariates to the measurement model when fitting a Latent Markov Model to continuous data
I am working with longitudinal continuous data that reflect the linguistic abilities of children. In that regard I seek to make a Latent Transition Model, more exact a Latent Markov Model using the ...
0
votes
1
answer
75
views
Rounding Stochastic Variables in R
When converting decimal values in a transition matrix to fractions with a specific denominator, how can I insure the resulting rows sum to 1? I understand that this is an issue relating to the choice ...
0
votes
1
answer
84
views
How to get a fixed value limiting Distribution. Markov Chains (no libraries/packages)
I would like to find the limiting distribution of my transition matrix after taking n = 30 steps
However, my problem was I kept could not get the exact same theoretical value as calculated by hand. My ...
0
votes
1
answer
219
views
Execute Markov chains with tree-structured state in parallel with JAX
I have a Markov chain function implemented in JAX that advances the chain from state s -> s' based on some training data (X_train).
def step(state: dict, key, X_train) -> dict:
new_state = ...
0
votes
0
answers
120
views
generating quasi-random sequences of events in R
I am trying to write a function in R that will generate random events over time following these criteria:
There are N initial events (say 10)
All events have roughly the same probability at the ...
0
votes
1
answer
858
views
How to restart iteration in R loop?
I made a loop to generate a Markov Chain. If the proposal does not satisfy a condition, I want to restart the iteration with a new proposal? Is there a way to do this? My current code is shown below ...
0
votes
1
answer
55
views
Montecarlo Markov Chain trouble! Changing Series to Float?
I'm trying to write a Montecarlo Markov chain algorithm, but when I try to run operations with data from the attached file (http://www.iiap.res.in/astrostat/School07/R/COUP551_rates.dat) I get the ...
0
votes
1
answer
177
views
How do I generate sentences with Rita.js?
I installed Rita through Node, following a RiTa.js egghead.io tutorial. After running the following code in my rita.js file on terminal, it shows a lot of data and says
Error: No valid sentence-...
0
votes
0
answers
137
views
Analyzing Clickstream Data using Markov models in R
I am working on clickstream data that does not have an end-state. For instance, some clickstream datasets have a user's journey, ending with a purchase or not. My data does not have an end-state and ...
1
vote
0
answers
22
views
Random generation of a finite Gaussian Markov Chain
Everything that I want to do is done through this code
sd = 1
v = c(0)
for (i in 1:10) {
rnorm(1,v[i],sd) -> v[i+1]
}
v
But I want to build confidence on Markov Chains, starting through chain ...
0
votes
2
answers
67
views
R: How to generate the following data
I need help with generating random numbers.
p - The probability that a pcr test of a sick person, will show us a positive result.
q - The probability that a pcr test of a healthy person, will show us ...
1
vote
0
answers
137
views
Implementation of a multigrid Montecarlo algorithm for a 2D Ising model
In the paper "Monte Carlo Methods in Statistical Mechanics: Fundation and New Algorithms", the author A.D. Sokal explain how to merge the Montecarlo Markov Chain algorithmic approach with ...
2
votes
0
answers
94
views
Transition probability with zero-frequency
With the below code I can calculate the Markov chain probabilities per time step. However I would like to make the following change to my code:
a.) speed up the transitions: increase the number of ...
2
votes
4
answers
613
views
How to find n average number of trials before criteria are met with differing probabilities per outcome?
I've spent a few days trying to figure this out and looking up tutorials, but everything I've found so far seems like it's close to what I need but don't give the results I need.
I have a device that ...
0
votes
2
answers
353
views
Calculate a sequence of Markov chain values
I have a Spark question, so for the input for each entity k I have a sequence of probability p_i with a value associated v_i, for example the data can look like this
entity | Probability | value
A ...
0
votes
0
answers
69
views
I need to generate Markov chain in R, there is given transaction matrix and pseudo random numbers sequence. How to implement that sequence?
My pseudo random numbers sequence and transaction matrix:
a1=293
c1=123
m1=584
x1<-c()
x1[1] = 5
#generating pseudo random numbers sequence
for (i in 1:(m1-1)){
x1[i+1]=(a1*x1[i]+c1)%%m1}
#...