Machine learning (ML) can be quite useful in a wide range of applications from voice processing to optimizing ray traced images. But for other applications, ML may not be the right fit, and developers may find tools like expert systems or state machines a better option. Many of these have lower overhead than ML solutions, making them more suitable for edge nodes where small microcontrollers are employed.
One of the simplest tools is the finite state machine (FSM); lots of developers implement state machines in their code. Innumerable macro and FSM class implementations are available, although there’s no standard. These frameworks may or may not handle large and complex FSM definitions. One open-source tool is the State Machine Compiler (SMC).
Graphic-based FSM solutions are also available. The advantage is that FSMs are often defined graphically, even if they’re manually implemented using a text-based approach. Manual translation tends to be error-prone, and keeping a definition matched to an implementation is problematic.
Automatic conversion between a graphical FSM to code can be done using a number of tools, enabling code and diagrams to be kept in sync. IAR’s VisualState tool provides a graphical FSM editor that generates C/C++ code (see figure). One advantage of this type of tool is that it essentially compiles the graphical representation to source code and can perform optimizations. The code compiler may perform additional optimizations, but these would not take into account details related to the FSM.
IAR’s VisualState provides a graphical environment for creating state machines that are then converted to C code.
VisualState is based on the Object Management Group’s (OMG) Unified Modeling Language (UML). Part of the UML definition includes state diagrams that define FSMs. The benefit of UML is that it’s a standard, and as a result, a number of commercial and open-source tools are available for UML. Not all UML tools can generate source or object code based on a UML application, but a number of them do. The open-source Eclipse project includes one, as does IBM’s Rational Rhapsody.
Other tools that support FSM include MathWorks’ MATLAB, Simulink, and StateFlow that can also generate program code based on an FSM model. AdaCore’s QGen code generator will generate C, C++, or Ada from Simulink and StateFlow models.
National Instruments’ LabVIEW is another graphical tool that supports FSM. LabVIEW also has the ability to target source code for embedded systems as well as the ability to target FPGAs.
The Law of Rule
A rule-based system is another tool that has similarities to FSMs, but is quite different overall. Rule-based systems include behavior-based systems as well as expert systems. These are actually a form of ML, but different than today’s popular neural-network ML solutions.
In general, rule-based expert systems consist of a set of rules that have a set of conditions and a set of actions that will be performed if those conditions are met. The conditions are tested as inputs to the system changes. A collection of rules is often referred to as a knowledge base. Logic programming languages like Prolog implement a type of rule-based solution.
Many rule-based systems are interpreted, but it’s possible to compile rules into code. Many Prolog systems generated programs. Functional programming languages like Haskell can be used to implement rule-based systems.
It’s often assumed that rule-based expert systems were a failure and that the latest ML incarnations are the successful alternatives. That’s not actually the case as rule-based systems have been quite successful, although the hype associated with them has long faded. They didn’t necessarily meet the goals of some artificial-intelligence (AI) research, but that doesn’t mean these tools haven’t been useful. They continue to be ones that developers should consider but only when applicable.
So, before diving into the latest neural-network craze, examine the problem and see what tools should be considered in solving the problem. It may be that none of these tools mentioned here or other ML-type tools will be applicable. If they are, though, such tools can make the programming job significantly easier.