Problems with Mathematica Code for Markov Models?

  • Context: Mathematica 
  • Thread starter Thread starter johalia
  • Start date Start date
  • Tags Tags
    Code Mathematica
Click For Summary
SUMMARY

The forum discussion centers on issues encountered while implementing Markov models in Mathematica, specifically using code from H. Timbley's paper. The user reports errors related to undefined variables and part specifications when executing a section of the code. The primary issue identified is the lack of definition for the variable randomUser, which leads to multiple error messages. Users are encouraged to ensure all variables are properly defined before execution to avoid such errors.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of Markov models and their applications
  • Knowledge of list manipulation and indexing in Mathematica
  • Ability to troubleshoot and debug Mathematica code
NEXT STEPS
  • Define the randomUser variable to resolve the error messages
  • Review the complete code from H. Timbley's paper for any missing components
  • Learn about error handling in Mathematica to better manage runtime issues
  • Explore the use of Position and IndexOf functions in Mathematica for effective list indexing
USEFUL FOR

This discussion is beneficial for researchers and developers working with Markov models in Mathematica, particularly those who are new to the software and need guidance on debugging code and understanding error messages.

johalia
Messages
1
Reaction score
0
Hello!

I'm writing a paper where I'm going to use markov models to evalute a device. My base for this paper is the paper written by H. Timbley. I have never used Mathematica before and thought that I would start by trying the complete code that Timbley has written in the appendix of the paper. The code is:

DiscreteMath`Combinatorica`;
IndexOf[vector , e ] := Position[vector, e][[1, 1]];

device =
{{"Clock", "Clock", "Clock", "Clock", "Clock", "Clock"},
{"Quick Defrost", "Quick Defrost", "Quick Defrost",
"Quick Defrost", "Quick Defrost", "Quick Defrost"},
{"Timer1", "Timer1", "Timer2", "Timer1", "Timer2", "Timer1"},
{"Clock", "Clock", "Clock", "Clock", "Clock", "Clock"},
{"Clock", "Quick Defrost", "Power1",
"Power2", "Power1", "Power2"}
};

buttonNames = {"Clock", "Quick Defrost", "Time", "Clear", "Power"};
stateNames = {"Clock", "Quick Defrost", "Timer1", "Timer2", "Power1",
"Power2"};

numberOfStates = Length@stateNames;
numberOfButtons = Length@buttonNames;

start = IndexOf[stateNames, "Power1"];
goal = IndexOf[stateNames, "Power2"];


Until then the code work just fine, but when I type in the next section described in the appendix (see below), some error codes pop up.

Do[randomUser[[i, IndexOf[stateNames, device[[b, i]]]]] +=
1/numberOfButtons, {b, numberOfButtons}, {i, numberOfStates}];


Error codes:
Part::partw: Part 1 of {} does not exist. >>
Part::pspec: Part specification {}[[1,1]] is neither a machine-sized integer nor a list of machine-sized integers. >>
Part::partw: Part 1 of {} does not exist. >>
Set::pspec: Part specification {}[[1,1]] is neither a machine-sized integer nor a list of machine-sized integers. >>
Part::partw: Part 3 of {Quick Defrost,(Quick Defrost)^5} does not exist. >>
General::stop: Further output of Part::partw will be suppressed during this calculation. >>
Part::pspec: Part specification {}[[1,1]] is neither a machine-sized integer nor a list of machine-sized integers. >>
Set::pspec: Part specification {}[[1,1]] is neither a machine-sized integer nor a list of machine-sized integers. >>
Part::pspec: Part specification {}[[1,1]] is neither a machine-sized integer nor a list of machine-sized integers. >>
General::stop: Further output of Part::pspec will be suppressed during this calculation. >>
Set::pspec: Part specification {}[[1,1]] is neither a machine-sized integer nor a list of machine-sized integers. >>
General::stop: Further output of Set::pspec will be suppressed during this calculation. >>


Is there anybody that could tell me what's wrong with the code?
 
Last edited:
Physics news on Phys.org
What version of Mathematica are you using? Because I get different error messages.

The problem seems to be that randomUser is not defined.

Can you give a reference for the paper you mention?
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
7K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
613
  • · Replies 94 ·
4
Replies
94
Views
14K