A decision tree transplantation and operation method based on MCU

By converting the decision tree model generated by MATLAB into a C language function executable by MCU, the problem of decision trees not being able to run efficiently on MCU is solved, and the smooth operation of decision trees and data classification prediction functions on MCU are realized.

CN115454499BActive Publication Date: 2025-09-26ZHEJIANG JINCHENG ELECTRONICS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211099816.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-07
Publication Date
2025-09-26
Estimated Expiration
2042-09-07

AI Technical Summary

Technical Problem

Most existing decision tree algorithms are generated and run on proprietary computer software and cannot run efficiently and reliably on embedded controllers such as MCUs, which have a wider range of applications.

Method used

The decision tree model generated by MATLAB is converted into a C language function that can be ported to the MCU using the wildcard method. The decision tree is run in the MCU using the goto jump structure and if-else if branch structure. The feature attributes are represented by the global variable xn.

Benefits of technology

The decision tree can run smoothly and efficiently on the MCU, with data classification and prediction functions, which increases the practicality of the MCU.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115454499B_ABST
    Figure CN115454499B_ABST
Patent Text Reader

Abstract

The present invention provides a decision tree transplantation and operation method based on MCU, which is characterized in that the decision tree model generated by MATLAB is converted into a C language function that can be transplanted to MCU by a wildcard method. Each labeled statement in the goto jump structure statement of C language represents an internal node or leaf node of the decision tree; the root node and the internal node are composed of if-elseif branch structure statements, and the current feature attributes are judged by the if-elseif branch structure statement, and then jump to the next internal node or leaf node by the goto jump structure statement. The internal node will eventually jump to the leaf node, and the leaf node represents the current decision classification result, and finally jumps to the "end" labeled statement to assign the result to the final result variable "result". This method can realize the smooth operation of the decision tree model in the MCU, so that it has intelligent data classification and data prediction functions, and increases the practicality of the MCU.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to machine learning prediction, and in particular to an MCU-based decision tree transplantation and operation method. Technical Background

[0002] Machine learning is a multidisciplinary field that encompasses probability theory, statistics, approximation theory, and algorithmic complexity theory. It specifically studies how computers can simulate or implement human learning behaviors to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their performance.

[0003] The research directions of traditional machine learning mainly include decision trees, random forests, artificial neural networks, Bayesian learning, etc.

[0004] A decision tree is a tree structure (which can be binary or non-binary). Each internal node represents a test judgment on a feature attribute, each branch represents the judgment output of this feature attribute within a certain value range, and each leaf node stores a category. The decision-making process using a decision tree starts at the root node, tests the corresponding feature attributes of the item to be classified, and selects the output branch based on the value until a leaf node is reached, where the category stored in the leaf node is used as the decision result.

[0005] Most existing decision tree algorithms are generated and run on proprietary computer software and cannot run reliably and efficiently on embedded controllers such as MCUs, which have a wider range of applications.

[0006] In response to the above problems, it is necessary to provide an MCU-based decision tree transplantation and operation method, so that the decision tree model generated by the computer in the early stage can be easily transplanted to the MCU and run efficiently and smoothly, giving full play to the data classification and data prediction functions of the decision tree. Summary of the Invention

[0007] In order to enable the decision tree model generated by the previous computer to be transplanted and run efficiently on the MCU, the present invention proposes a decision tree transplantation and operation method based on the MCU, which can enable the decision tree to run efficiently and smoothly on the MCU and give full play to the functions of the decision tree such as data classification and data prediction.

[0008] In order to achieve the above object, the technical solution adopted by the present invention is as follows:

[0009] A decision tree transplantation and operation method based on an MCU is characterized by: converting a decision tree model generated by MATLAB into a C language function that can be transplanted to the MCU through a wildcard method; and running the decision tree in the MCU through the C language goto jump structure statement and if-else if branch structure statement;

[0010] Furthermore, the decision tree model generated by MATLAB is converted into a C language function that can be ported to the MCU through the wildcard method. The method specifically includes the following steps, in which all characters within double quotes are processed, including spaces:

[0011] Step 1: Convert all “then nodes” in the model to “){goto node_”;

[0012] Step 2: Convert all "elseif" in the model to ";}else if(";

[0013] Step 3: Convert all “else^#” in the model to “;}”;

[0014] Step 4: Convert all “class=^#” in the model to “^&;goto end;”;

[0015] Step 5: Convert the corresponding node number according to the total number of nodes in the generated model;

[0016] Step 6: Convert all “if” in the model to “if(”;

[0017] Step 7: Convert all “node_{1,10}” in the model to “node_”;

[0018] Step 8: Convert all “class=” in the model to “Tempresult=”;

[0019] Step 9: Convert all “:” in the model to “:”;

[0020] Step 10: Convert all “node_1:” in the model to “”;

[0021] Step 11: Add “end:result=Tempresult;” to the end of the code.

[0022] Step 12: Put the above code into VoidDecision_Tree_Core(){};

[0023] Furthermore, the step 5 specifically includes the following steps:

[0024] If the total number of nodes in the model is 1-9:

[0025] (a1): Convert all “^#” in the model results to “node_^&:”;

[0026] If the total number of nodes in the model is 10-99:

[0027] (b1): Convert all “^#” in the model results to “node_^&:”;

[0028] (b2): Convert all “^#^#” in the model results to “node_^&:”;

[0029] If the total number of nodes in the model is 100-999:

[0030] (c1): Convert all “^#” in the model to “node_^&:”;

[0031] (c2): Convert all “^#^#” in the model to “node_^&:”;

[0032] (c3): Convert all “^#^#^#” in the model to “node_^&:”;

[0033] If the total number of nodes in the model is 1000-9999:

[0034] (d1): Convert all “^#” in the model to “node_^&:”;

[0035] (d2): Convert all “^#^#” in the model to “node_^&:”;

[0036] (d3): Convert all “^#^#^#” in the model to “node_^&:”;

[0037] (d4): Convert all “^#^#^#^#” in the model to “node_^&:”;

[0038] Furthermore, each labeled statement in the goto jump structure statement represents an internal node or leaf node. The root node and internal nodes are composed of if-else if branching structures. The if-else if branching structures judge the current feature attributes through the if-else if branching structures, and then jump to the next internal node or leaf node through the goto jump structure statement. The internal node will eventually jump to the leaf node, which represents the current decision classification result and is assigned to the temporary result variable "Tempresult". Finally, the goto jump structure statement jumps to the "end" labeled statement, assigning the current temporary result variable "Tempresult" to the final result variable "result", completing the operation and judgment of the decision tree.

[0039] Furthermore, each characteristic attribute of the decision tree running on the MCU is represented by a global variable xn (n=positive integer).

[0040] The beneficial effects of the present invention are that the MCU-based decision tree transplantation and operation method can realize the smooth operation of the decision tree model on the MCU, so that it has intelligent data classification and data prediction functions, and increases the practicality of the MCU. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] Figure 1 It is the main flow chart for converting the computer-generated decision tree model into a C language function on the MCU.

[0042] Figure 2 It is a flowchart for converting a computer-generated decision tree model into a node number conversion in a C language function on an MCU.

[0043] Figure 3 It is a simple diagram of the decision tree model structure generated by a computer.

[0044] Figure 4 This is a schematic diagram of how a computer-generated decision tree model actually runs in an MCU. DETAILED DESCRIPTION

[0045] The solution of this invention is described in detail below with reference to the accompanying drawings.

[0046] The present invention discloses a decision tree transplantation and operation method based on MCU. The early decision tree model is generated using the mainstream computer decision tree software MATLAB. The final decision tree result cannot be directly run on the MCU, so conversion and transplantation are required. Figure 1 As shown in the figure, it is the main flow chart for converting the decision tree model generated by the computer into the C language function on the MCU. First, start the conversion, and the processing objects are all characters in double quotes, including spaces, all in English punctuation mode. The conversion uses wildcard mode. The first step is to convert all "then node" into "){goto node_"; the second step is to convert all "elseif" into ";}else if("; the third step is to convert all "else^#" into ";}"; the fourth step is to convert all "class=^#" into "^&;goto end;"; the fifth step is to perform corresponding processing according to the total number of nodes in the generated model. The specific steps are as follows Figure 2 shown.

[0047] Figure 2This is a flowchart for converting a computer-generated decision tree model into a node number conversion function in a C language function on an MCU. If the model has 1-9 nodes, the first step is to convert all "^#" in the model to "node_^&:". If the model has 10-99 nodes, the first step is to convert all "^#" in the model to "node_^&:". The second step is to convert all "^#^#" in the model to "node_^&:". If the model has 100-999 nodes, the first step is to convert all "^#" in the model to "node_^&:". The second step is to convert all "^#^#" in the model to "node_^&:". The third step is to convert all "^#^#^#" in the model to "node_^&:". If the total number of nodes in the model is 1000-9999, the first step is to convert all “^#” in the model to “node_^&:”; the second step is to convert all “^#^#” in the model to “node_^&:”; the third step is to convert all “^#^#^#” in the model to “node_^&:”; the fourth step is to convert all “^#^#^#^#” in the model to “node_^&:”.

[0048] Step 6. Convert all “if” to “if(”; Step 7. Convert all “node_{1,10}” to “node_”; Step 8. Convert all “class=” to “Tempresult=”; Step 9. Convert all “:” to “:”; Step 10. Convert all “node_1:” to “”; Step 11. Add “end:result=Tempresult;” at the end of the code; Step 12. Put the above code into Void Decision_Tree_Core(){} according to the C language function definition. This completes the conversion of the generated decision tree model into a C language function on the MCU, and it can be transplanted to the MCU for smooth operation.

[0049] like Figure 3 As shown in FIG, a simple diagram of a decision tree model generated by a computer is shown, which contains a total of 4 nodes, including a root node, an internal node and two leaf nodes.

[0050] like Figure 4 The following is a schematic diagram of the computer-generated decision tree model actually running on the MCU. Figure 3Take the structure of the generated decision tree model as an example. The root node of the decision tree is the first sentence of the transplanted C language decision tree function Decision_Tree_Core(). Among them, "if(x1<X1)" and "else if(x1>=X1)" are a classification rule judgment of the decision tree function for the feature attribute "x1", and "X1" is the specific value compared by the decision tree under this classification rule. It is not limited to positive numbers. In the transplanted decision tree function, x1, x2... xn (n is a positive integer) are a series of feature attribute variables of the decision tree function, and they all exist in the form of global variables during the operation of the decision tree program.

[0051] The "{goto node_2;}" following "if(x1<X1)" means that when the feature attribute "x1" satisfies being less than the value of "X1", it will jump to the internal node node_2; the "{goto node_3;}" following "if(x1>=X1)" means that when the feature attribute "x1" satisfies being not less than the value of "X1", it will jump to the leaf node 1 of node_3. The statement where the internal node is located is node_2. Similar to the root node, "if(x2<X2)" and "else if(x2>=X2)" are a classification rule judgment of the decision tree function for the feature attribute "x2", and "X2" is the specific value compared by the decision tree under this classification rule. The "{goto node_3;}" following "if(x2<X2)" means that when the feature attribute "x2" satisfies being less than the value of "X2", it will jump to the leaf node 1 of node_3; the "{goto node_4;}" following "if(x2>=X2)" means that when the feature attribute "x2" satisfies being not less than the value of "X2", it will jump to the leaf node 2 of node_4.

[0052] In leaf nodes 1 and 2, first assign the decision tree judgment result to the temporary result variable "Tempresult", and then directly jump to the "end" statement to end the decision judgment. In the "end" statement, assign the value of the temporary result variable "Tempresult" to the final result variable "result", which completes the operation and result judgment of the decision tree in the MCU.

[0053] The present invention provides an MCU-based decision tree transplantation and operation method. A decision tree model is generated using MATLAB, a universal decision tree generation software, and the generated decision tree model is converted into a corresponding C language function using a wildcard method. In the C language function, jumps to each node of the decision tree are implemented using a goto jump structure statement, and rule judgments are performed on each characteristic attribute of the decision tree using an if-else if branch structure statement. This C language function enables the decision tree model to run smoothly and efficiently on the MCU, implementing the decision tree's decision and classification functions in the MCU. The method has high data classification and judgment accuracy and is practical.

[0054] The above is a detailed introduction to the technical solution of the present invention. Any content involving the present invention and related scope will be regarded as plagiarism.

Claims

1. A decision tree transplantation and operation method based on MCU, characterized by: The decision tree model generated by MATLAB is converted into a C language function that can be ported to the MCU using the wildcard method. The specific steps include the following, where all characters within double quotes are processed, including spaces: Step 1: Convert all "then nodes" in the model to "){goto node_"; Step 2: Convert all "elseif" in the model to ";}else if("; Step 3: Convert all "else^#" in the model to ";}"; Step 4: Convert all "class=^#" in the model to "^&;goto end;"; Step 5: Convert the corresponding node number according to the total number of nodes in the generated model; Step 6: Convert all "if" in the model to "if("; Step 7: Convert all "node_{1,10}" in the model to "node_"; Step 8: Convert all "class=" in the model to "Tempresult="; Step 9: Convert all ":" in the model to ":"; Step 10: Convert all "node_1:" in the model to ""; Step 11: Add "end:result = Tempresult;" to the end of the code. Step 12: Put the above code into Void Decision_Tree_Core(){}; The decision tree is run in the MCU through the C language goto jump structure statement and if-else if branch structure statement, specifically: Each labeled statement in the goto jump structure statement represents an internal node or leaf node; the root node and internal nodes are composed of if-else if branch structure statements, which judge the current feature attributes through the if-else if branch structure statement, and then jump to the next internal node or leaf node through the goto jump structure statement; the internal node will eventually jump to the leaf node, which represents the current decision classification result and is assigned to the temporary result variable "Tempresult". Finally, the goto jump structure statement jumps to the "end" labeled statement, and the current temporary result variable "Tempresult" is assigned to the final result variable "result", completing the operation of the decision tree and the result judgment.

2. The MCU-based decision tree transplantation and operation method according to claim 1, characterized in that: The step 5 specifically includes the following steps: If the total number of nodes in the model is 1-9: (a1): Convert all "^#" in the model to "node_^&:"; If the total number of nodes in the model is 10-99: (b1): Convert all "^#" in the model to "node_^&:"; (b2): Convert all "^#^#" in the model to "node_^&:"; If the total number of nodes in the model is 100-999: (c1): Convert all "^#" in the model to "node_^&:"; (c2): Convert all "^#^#" in the model to "node_^&:"; (c3): Convert all "^#^#^#" in the model to "node_^&:"; If the total number of nodes in the model is 1000-9999: (d1): Convert all "^#" in the model to "node_^&:"; (d2): Convert all "^#^#" in the model to "node_^&:"; (d3): Convert all "^#^#^#" in the model to "node_^&:"; (d4): Convert all "^#^#^#^#" in the model to "node_^&:".

3. The MCU-based decision tree transplantation and operation method according to claim 1, characterized in that: Each feature attribute of the decision tree running on the MCU is represented by a global variable xn, where n = a positive integer.

Citation Information

Patent Citations

  • Transformation method and device for random forest model

    CN106997330A

  • Decision engine implementation method based on decision tree

    CN111638883A