Electronicdesign 23374 Rulesengine Promo
Electronicdesign 23374 Rulesengine Promo
Electronicdesign 23374 Rulesengine Promo
Electronicdesign 23374 Rulesengine Promo
Electronicdesign 23374 Rulesengine Promo

Following Rules Might be Better than Machine Learning

Aug. 15, 2018
Though machine learning is often effective for many applications, it’s not always the solution. That’s where tools like expert systems or state machines can step in.

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.

Sponsored Recommendations

Article: Meeting the challenges of power conversion in e-bikes

March 18, 2024
Managing electrical noise in a compact and lightweight vehicle is a perpetual obstacle

Power modules provide high-efficiency conversion between 400V and 800V systems for electric vehicles

March 18, 2024
Porsche, Hyundai and GMC all are converting 400 – 800V today in very different ways. Learn more about how power modules stack up to these discrete designs.

Bidirectional power for EVs: The practical and creative opportunities using power modules

March 18, 2024
Bidirectional power modules enable vehicle-to-grid energy flow and other imaginative power opportunities. Learn more about Vicor power modules for EVs

Article: Tesla commits to 48V automotive electrics

March 18, 2024
48V is soon to be the new 12V according to Tesla. Size and weight reduction and enhanced power efficiency are a few of the benefits.

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!