This project extends the gfpop package to support time-dependent constraints in changepoint detection models. The implementation allows constraints to vary over time, enabling implementations like Labeled Optimal Partitioning and unconstrained optimal partitioning.
easy_test/
- Implementation of the Easy Test (visualizing gfpop graphs)plotModel.R
- Main function for graph visualizationtest_plotModel.R
- Examples showing how to use plotModelsimple_gfpop_example.R
- Beginner-friendly example scriptREADME.md
- Instructions specific to the easy test
problem.md
- Original problem statement and tests description
We've implemented a solution for the easy test:
Write an R function `plotModel` which takes a `gfpop::graph` as above and draws a matrix of nodes (one row for each state, one column for each rule) and edges.
Our implementation visualizes gfpop graphs as a matrix with:
- Each row representing a state
- Each column representing a rule ID
- Nodes at each state/rule intersection
- Directed edges showing valid transitions
- R (version 3.6.0 or higher)
- Rtools (for Windows users building packages from source)
Run these commands in an R console:
install.packages("igraph") # For graph visualization
install.packages("remotes") # For installing packages from GitHub
remotes::install_github("vrunge/gfpop") # Install gfpop from GitHub
For a fully reproducible environment, we use renv:
-
Start an R Console: Open RStudio or VS Code with R extension
-
Install renv:
install.packages("renv")
-
Navigate to the project directory:
setwd("path/to/gfpop-time-dependent-constraints")
-
Initialize the environment:
renv::init()
-
Install required packages in the isolated environment:
renv::install("igraph") renv::install("remotes") remotes::install_github("vrunge/gfpop") # For testing renv::install("testthat")
<<<<<<< HEAD
- Save the environment state:
renv::snapshot()
======= 2. Clone the Repository:
git clone https://github.com/Transcendental-Programmer/gfpop-time-dependent-constraints.git
>>>>>>> 7eb01425ac58e93e3e3d2978611808a48225b131
- When returning to the project later:
renv::restore() # Reinstall all packages from the lockfile
We use testthat for testing the implementation:
-
Navigate to the easy_test directory:
setwd("path/to/gfpop-time-dependent-constraints/easy_test")
-
Run the example script:
source("test_plotModel.R")
-
What you'll observe: Three graph visualizations will appear:
- Simple Graph Example (2 states, 2 rules)
- LOPART Graph Example (complex graph with multiple transitions)
- Complex Graph Example (up/down states with multiple rules)
-
For a simpler example:
source("simple_gfpop_example.R")
The plotModel
function visualizes gfpop graphs using these steps:
- Extract unique states and rules from the graph
- Create a matrix layout with states as rows and rules as columns
- Build an igraph object with nodes at each state/rule intersection
- Add edges according to the transitions defined in the graph
- Render the visualization with igraph's plotting functions
easy_test/plotModel.R
: Contains the mainplotModel
function implementationeasy_test/test_plotModel.R
: Demonstrates usage with multiple example graphseasy_test/simple_gfpop_example.R
: A beginner-friendly example that works with any gfpop version
library(gfpop)
library(igraph)
# Source the plotModel function
source("easy_test/plotModel.R")
# Create a graph (using the approach that works with all gfpop versions)
g <- list()
g$edges <- data.frame(
state1 = c("normal", "normal", "noChange", "noChange"),
state2 = c("normal", "noChange", "noChange", "normal"),
type = c("null", "std", "null", "null"),
penalty = c(0, 5.5, 0, 0),
rule = c(1, 2, 2, 3),
stringsAsFactors = FALSE
)
class(g) <- "graph"
# Visualize the graph
plotModel(g, title="Example Graph")
- Priyansh Saxena - Implemented the Easy Test solution
- Primary: Vincent Runge - [email protected]
- Co-Mentor: Toby Dylan Hocking - [email protected]
For distribution details, run in an R session:
license()
This work extends established changepoint detection methods by incorporating time-sensitive constraints, with contributions from both the gfpop community and the broader changepoint research community.
7eb01425ac58e93e3e3d2978611808a48225b131