The “Model Justice” series of posts (starting here) is chronicling my attempts to build a software model of certain aspects of the criminal justice system. As I explained in the most recent post, my first attempt at building a model ran into a dead end, so now I’m figuring out what to do for my next attempt.
I’ve identified several possible ways the model could be improved, and based on some feedback from lawyers Mark Bennett and Matt Haiduk, I think I want the new version of the model to eventually implement the following features:
- Allow defendants to have some degree of risk love instead of risk aversion when making plea bargaining decisions.
- Allow risk preferences to vary depending on case quality.
- Allow limits to the extremes of case quality. E.g. Always some chance of acquittal/conviction no matter how strong/weak the case.
- Allow prosecution and defense to have different views of the quality of the case.
In addition, I think I’d like to include a few other ideas:
- Allow mixes of different types of cases. E.g. Different severity of crime.
- Incorporate the way absolute sentencing severity — including collateral consequences — affects risk tolerance.
- Incorporate the effects of defendants being stuck in jail pending trial.
I also want to switch to a different model of plea bargaining — one informed by economic thinking — that I’ll describe in a future post.
Before I can do any of that, I need to make a big change to my approach. The system modeling tool I’ve been using, Insight Maker, is designed to model entities that transition through a series of states. That seemed appropriate tool for modeling a defendant going through various stages of the criminal justice system: Arrest, pre-trial, trial, jail, release, and so on.
However, nearly all of the things I want to change will have an effect at only one point in the process: Plea bargaining. Even things that do not happen until after the trial — prison, collateral consequences — are only part of the model because of how they affect plea bargaining. So the cumulative effect of all these changes will be to greatly complicate the model’s plea bargaining logic.
Unfortunately, while Insight Maker is a fantastic (and free) tool, it’s not really engineered for that kind of complex programming. For what I’m planning, Insight Maker falls short in several ways:
- You can add code to an Insight Maker model to control state transitions, or to execute independently as actions, but there’s no real place to add libraries of code that can be called from other code, which makes it awkward to do anything non-trivial.
- Insight Maker code is using its own private language, invented by the author of Insight Maker. It seems quite competent for a small language, but it doesn’t feel like a full-strength programming language.
- The editing environment for Insight Maker is primitive. It has an editor window implemented in JavaScript, but you can only open one piece of code at a time, and it doesn’t come close to the convenience features available in a modern language-aware integrated development environment.
- When developing software, it’s nice to be able manage multiple versions of the code base so you can try different approaches and easily back out of bad ideas, but there’s no easy way to manage multiple versions of Insight Maker code.
- You can download a model into a file, which you can edit in other tools, but you can’t easily modify or use the model in that format.
- Insight Maker doesn’t have libraries of open source code that you can leverage in your program to add features or speed development.
- Insight Maker graphic output is limited to only certain types of data and certain types of charts.
- Insight Maker doesn’t appear to be thriving. The official Insight Maker forum has only had 15 topics posted in the last three months, and the Insight Maker news stream hasn’t been updated in almost a year and a half.
I considered a number of possible alternatives to Insight Maker. I would love to play around with a professional-strength modeling tool like AnyLogic, Vensim, Powersim, or isee systems’ Stella/iThink packages. AnyLogic in particular can be extended with Java, which would allow me to use a whole world of open-source Java code. On the other hand, these tools are heavily focused on modeling complex business processes, and they are priced as if a corporation was buying them. (Some of them have free or low-cost versions, but those often have serious limitations, not all of which are documented.)
Something like MATLAB/Simulink, in addition to possibly being pricey, is also really intended for modeling physical systems, not system dynamics or the sort of agent-based modeling I was doing. Wolfram SystemModeler is similar, which is a shame, because I already have a home user license.
Speaking of Wolfram, I could probably use Mathematica, because you can do anything in Mathematica, at least according to the folks who make Mathematica. I have a home user license for that too, and I’ve already used it on this project to generate some of the graphics for these posts. The problem is, I get frustrated with Mathematica when I try to do anything complicated, because it’s not like a normal programming language.
But that got me thinking…maybe what I really need is not a simulation tool, but an ordinary programming environment in which I can build a simulation. It wouldn’t have the fancy drag-and-drop block diagrams that all those simulation products provide for building models, but I’m not sure I need that for what I’m doing. I think the connections and flows are simple enough that I can model them with ordinary programming structures.
In that case, the obvious choice for me would be C# and the .NET Framework, since that’s what I work with on my day job. I have access to a ton of development tools, and I’m very familiar with useful code patterns, the development toolchain, and the general approach to developing a C# project. On the other hand, C# is geared towards building production-quality systems, but since I’m still designing the model, I would probably benefit more from a development environment geared toward ad hoc queries and prototyping.
I think I need something that works like R Studio, where I can type in simple commands to change things, run code, and see the results, so I can easily try lots variations and ideas. Or maybe I’d be better with a notebook-style interface, like Mathematica. Both of those also provide data visualization, so you can change something, run it, and see a graphical representation of the result. I don’t actually want to use either of those, however, because I find both R and Mathematica’s “Wolfram Language” to be very annoying for writing anything substantial.
And that brings me to Python. Even though Python has been around for over 25 years, I have never really needed it for anything I was doing, so I’ve pretty much ignored it until now. I tend to prefer heavily-typed languages like C++, Java, and C# that compile down into machine code to run efficiently. Python is an interpreted scripting language that is usually used for writing short programs that stitch together powerful components. (Also, it uses indentation to delimit blocks, which is different from practically everything else in the world these days.)
However, unlike scripting languages such as Perl (or special-purpose tools such as R), Python was actually created from the beginning with full-strength programming features, and it has grown to become one of the most popular computer languages in the world, especially in the data science community. (So if nothing else, learning Python could turn out useful later.)
For my purposes, Python ticks several important boxes:
- Python is a full-strength software system with support for multiple-file software projects and organizational abstractions such as classes, modules, and packages.
- Python is a mature, well-known, and widely used language.
- Python is supported by numerous integrated development environments, including Eclipse (with the PyDev extension), Sublime, Visual Studio, Spyder, and PyCharm (for which I already have a license).
- Python projects are just files in directories, so you can easily edit them in a variety of ways and version control them with git.
- There are tons of usable third-party open source Python libraries at PyPi.
- Python is thriving and growing as a programming language due to its popularity among the data science community, so there are plenty of resources.
- There are development environments for Python that support both an R Studio-style environment (Spyder) and a notebook-style environment (Jupyter).
Of course, to use Python, I’m first going to have to learn Python. Writing tiny programs is easy and quick, but I want to build up a library of modeling components, so I need to learn about things like Python classes, Python modules, and Python packages, as well as figure out a development environment, all before I can start building the model.
I think it’s going to be a while.
Chuck says
I am wondering why you want to model the criminal justice system. I can think of several reasons, like see which factors can affect outcomes, or cause bottlenecks, or something. Given that the whole process is horribly inefficient, consumes huge amounts of very expensive time, and generally crushes anyone who gets so ensnared, it seems that what we need is some kind of revolution in the way we think about the justice system. But maybe that is asking for too much. Maybe chipping away is all we can do.
Mark Draughn says
Basically, I have some ideas about plea bargaining that I want to explore, and I hope that modeling the system will help me to explore those ideas. I’m not expecting to get the kind of accuracy need for a scientific tool, but maybe I’ll get a decent illustrative tool.