Jump to content

Markov chains: Difference between revisions

From SELESwiki
No edit summary
 
 
(One intermediate revision by the same user not shown)
Line 14: Line 14:
In the following sections we will examine all of the model files for this model. Note that instead of downloading the zip file above, you could just copy the text in the boxes below into a text editor and save it with the appropriate name (Section title). Opening the resulting .scn file in the SELES simulator would run this model.
In the following sections we will examine all of the model files for this model. Note that instead of downloading the zip file above, you could just copy the text in the boxes below into a text editor and save it with the appropriate name (Section title). Opening the resulting .scn file in the SELES simulator would run this model.


===MLM.scn===
===MarkovChain.scn===


  SELES Scenario
  SELES Scenario
  $gisData$ = ..\..\CaseStudy_Morice\gisData\cell
  MarkovChain.sel
StudyArea = $gisData$\BEC
Model Dimensions: StudyArea
Model.sel
  SimPriority Low Priority
  SimPriority Low Priority
//SimStart 100000 1


===Model.sel===
===MarkovChain.sel===


  Seles Model
  Seles Model
  Time Units: Step kiloStep 1000 100000
Model Size: 200, 200
  Time Units: na Step 1 1000
  Landscape Events:
  Landscape Events:
  ConvexHull.lse
  MarkovChain.lse
Spatial Constants:
StudyArea
  Spatial Variables:
  Spatial Variables:
  ConvexHullPoints[1] <= 0
  CellState[4] <= 0
  ConvexHull[1] <= 0
  PrevCellState[4] <= 0
  Global Variables:
  Global Variables:
  TRLoc = 0
  pInitial = 0, 1, 0, 0, 0
pChange = 0.01
UseNeighbs = FALSE
  Output Frequency: 1
  Output Frequency: 1


===ConvexHull.lse===
===MarkovChain.lse===
 
  // Simple Markov Chain
  // Sweep-line approach to identifying convex hull using a worker agent
  LSEVENT: MarkovChain
  LSAGENT: ConvexHull
  DEFINITIONS
DEFINITIONS
LAYER: CellState, PrevCellState
  LAYER: StudyArea, ConvexHull, ConvexHullPoints
GLOBAL VARIABLE: pInitial[], pChange, UseNeighbs
  GLOBAL VARIABLE: TRLoc
  LOCAL VARIABLE: EndingPivotLoc
  AGENT VARIABLE: PivotLocation, EdgeLocation, EdgeRow, EdgeCol
  ENDDEF
  ENDDEF
  INITIALSTATE
  INITIALSTATE
  INITIALSTATE = 1
  INITIALSTATE = 1
  // Find the top-right-most point
CellState = CLASSIFIED_DIST[pInitial]
  TRLoc = 0
ENDIS
  OVER REGION WHOLE MAP
  RETURNTIME
       DECISION StudyArea > 0
RETURNTIME = 1
       TRLoc = MAX(TRLoc, Location)
  PrevCellState = CellState
ENDRT
  TRANSITIONS
TRANSITIONS = TRUE
IF UseNeighbs
      n = 0
      t = 0
      x = PrevCellState
      OVER REGION CENTRED(0, 1.5)
        n = n + 1
        t = t + PrevCellState
        x = IF (PrevCellState EQ 0) OR (x EQ 0) THEN 0 ELSE MAX(x, PrevCellState)
       ENDFN
       currState = CLAMP(ROUND(t/n), 0, 4)
      currState = x
  ELSE
      currState = PrevCellState
   ENDFN
   ENDFN
  ConvexHull = 1 // Initialize convex hull layer to all ones (will erase areas outside hull)
  CellState = CLASSIFY(currState)
ENDIS
                0: 0
NUMAGENTS = 1 // Only need a single worker
                1: CLASSIFIED_DIST
// Start on the first pivot vertex on convex hull
                    1:1 - pChange
AGENTLOCATION
                    2:pChange
  REGION LOCATION(TRLoc)
                  ENDFN
ENDAL
                2: CLASSIFIED_DIST
PROBINIT
                    2:1 - pChange
  PROBINIT = 1
                    3:pChange
// Set up first pivot vertex, and first raster boundary location
                  ENDFN
  PivotLocation = Location
                3: CLASSIFIED_DIST
  EdgeRow = NUMROWS-1
                    3:1 - pChange
  EdgeCol = COL(Location)
                    4:pChange
  EdgeLocation = LOCATION(EdgeRow, EdgeCol)
                  ENDFN
  EndingPivotLoc = -1
                4: CLASSIFIED_DIST
ENDPI
                    0: pChange
TRANSITIONS
                    4:1 - pChange
  // Continue until we reach the ending pivot location (which is actually second time we hit the second pivot          vertex,
                  ENDFN
  // since the first pivot vertex gets only partially processed on first pass)
              ENDFN
  TRANSITIONS = (PivotLocation NEQ EndingPivotLoc)
   ENDTR
ConvexHullPoints = 1
// Walk line from boundary to vertex and erase until a new pivot vertex is hit (then move there)
  oldPivot = PivotLocation
  hitPivot = FALSE
  OVER REGION VECTOR(EdgeLocation, PivotLocation)
    DECISION !hitPivot
  IF (StudyArea > 0) // hit new vertex
        hitPivot = TRUE
        IF (EndingPivotLoc EQ -1) AND (Location NEQ PivotLocation)
          EndingPivotLoc = PivotLocation
        ENDFN
        PivotLocation = Location
    ELSE
        ConvexHull = 0 // erase
    ENDFN
  ENDFN
// Move boundary location clockwise around outside edge of raster
  IF (EdgeRow EQ NUMROWS-1) AND (EdgeCol < NUMCOLS-1)
    EdgeCol = EdgeCol + 1
  ELSE IF (EdgeCol EQ NUMCOLS-1) AND (EdgeRow > 0)
    EdgeRow = EdgeRow - 1
  ELSE IF (EdgeRow EQ 0) AND (EdgeCol > 0)
    EdgeCol = EdgeCol - 1
  ELSE
    EdgeRow = EdgeRow + 1
  ENDFN
   EdgeLocation = LOCATION(EdgeRow, EdgeCol)
ENDTR
POPULATIONTIME = 1
// Move to current/new pivot location
MOVELOCATION
  REGION LOCATION(PivotLocation)
ENDML


==Suggested Experiments==
==Suggested Experiments==


To explore this cellular automata model further, try the following:
To explore this cellular automata model further, try the following:

Latest revision as of 21:20, 8 November 2006

Summary

Screenshot

Download Model

Download the .scn, .sel and .lse files by clicking on the following link: File:MarkovChain.zip

Model Code Exploration

In the following sections we will examine all of the model files for this model. Note that instead of downloading the zip file above, you could just copy the text in the boxes below into a text editor and save it with the appropriate name (Section title). Opening the resulting .scn file in the SELES simulator would run this model.

MarkovChain.scn

SELES Scenario
MarkovChain.sel
SimPriority Low Priority

MarkovChain.sel

Seles Model
Model Size: 200, 200
Time Units: na Step 1 1000
Landscape Events:
MarkovChain.lse
Spatial Variables:
CellState[4] <= 0
PrevCellState[4] <= 0
Global Variables:
pInitial = 0, 1, 0, 0, 0
pChange = 0.01
UseNeighbs = FALSE
Output Frequency: 1

MarkovChain.lse

// Simple Markov Chain
LSEVENT: MarkovChain
 DEFINITIONS
LAYER: CellState, PrevCellState
GLOBAL VARIABLE: pInitial[], pChange, UseNeighbs 
ENDDEF
 INITIALSTATE
INITIALSTATE = 1
CellState = CLASSIFIED_DIST[pInitial]
ENDIS
 RETURNTIME
RETURNTIME = 1
PrevCellState = CellState
ENDRT
 TRANSITIONS
TRANSITIONS = TRUE
IF UseNeighbs 
     n = 0
     t = 0
     x = PrevCellState
     OVER REGION CENTRED(0, 1.5)
        n = n + 1
        t = t + PrevCellState
        x = IF (PrevCellState EQ 0) OR (x EQ 0) THEN 0 ELSE MAX(x, PrevCellState)
     ENDFN
     currState = CLAMP(ROUND(t/n), 0, 4)
     currState = x
  ELSE
     currState = PrevCellState
  ENDFN
CellState = CLASSIFY(currState)
               0: 0
               1: CLASSIFIED_DIST
                    1:1 - pChange
                    2:pChange
                  ENDFN
               2: CLASSIFIED_DIST
                    2:1 - pChange 
                    3:pChange
                  ENDFN
               3: CLASSIFIED_DIST
                    3:1 - pChange
                    4:pChange
                  ENDFN
               4: CLASSIFIED_DIST
                    0: pChange
                    4:1 - pChange
                  ENDFN
             ENDFN
 ENDTR

Suggested Experiments

To explore this cellular automata model further, try the following: