AUTOMATIC CONSTRUCTION OF A FUZZY SYSTEM WITH A MATRIX REPRESENTATION OF RULES AND A CORRECT KNOWLEDGE BASE

.


Introduction
It is known that most modern approaches to machine learning have had a great impact on many industries [1]. The development of technologies has made it possible to widely apply artificial intelligence systems to support decision-making in such areas of knowledge as economy, industry, medicine, science, trade, construction, transport. Domain information is a large amount of data that needs to be processed to make the right decisions. Therefore, to solve a wide class of practical problems, such methods of artificial intelligence as fuzzy logic, neural networks, genetic algorithms, and others are used. This avoids the use of accurate mathematical models based on the apparatus of mathematical equations and classical decision theory. With the help of artificial intelligence, systems are being created to simulate the activities of experts in various fields. The tasks of control, identification, modeling of complex physical phenomena, classification, pattern recognition are successfully solved using elements of fuzzy logic [1]. The use of fuzzy logic is due to the fact that it intuitively corresponds to the process of human reasoning under conditions of fuzziness and incompleteness of the conditions of the problem. Since the system of production rules can be incomplete, incoherent, and contradictory, it is necessary to check this system for correctness after its formation.
A number of works consider various models for the representation of production knowledge bases and examine the correctness of the expert system after its formation [2][3][4][5][6][7]. However, the proposed approaches for checking the correctness of the rule base do not allow for automatic verification, taking into account information about the object of study, which predetermines the need for theoretical and practical research in this field of knowledge.

Literature review and problem statement
Automatic formation of the production base of rules in expert systems and proof of its correctness is an urgent task since it makes it possible to ensure the simplicity of the development of such systems and the high quality of logical inference. In the literature, different approaches are developing to solve such problems.
To analyze the reliability of the knowledge base of fuzzy logical inference, work [2] considers the representation of the system of rules in the form of a meta graph. At the same time, a fuzzy knowledge base is represented using the Mamdani model. After the verification procedure, the database of rules must satisfy the following conditions: non-redundancy, linguistic consistency, absence of looping, and linguistic completeness. It is proposed to carry out static verification of bases of fuzzy knowledge on the basis of the structure of the meta graph by finding looping in the structure of the graph. The paper considers the knowledge base built by the expert; it makes sense to test this approach on automatically generated knowledge bases with a large number of rules.
Paper [3] deals with the issue of automating the verification of the correctness of the knowledge base of product rules. A quantum model of encoding symbols of the multivalued alphabet using cubic calculus is proposed. The Mamdani algorithm is used as the output algorithm. A computer program is being developed that makes it possible to perform a formal check of the database of production rules for correctness using the resolution method. Set-theoretic operations on alphabet characters are reduced to corresponding bitwise logical operations on their qubits. The disadvantages of this approach include the following: input linguistic variables must have the same number of terms, and the terms of different input linguistic variables must have the same ranges of values. In addition, the production rules must be fully defined, i.e., any combination of term values of input linguistic variables corresponds to a certain value of the terms of the output linguistic variable.
Acyclic graphs are also used to represent the knowledge base. In work [4], an algorithm for constructing a directed acyclic graph is used to accumulate large sets of knowledge in real time. Subsequent translation of the graph is carried out using a specialized language TLC (Target Language Compiler). The paper proposes to check the knowledge base for correctness at the translation stage. Both classical methods are used, using disjunctive and conjunctive normal forms, and using the normal form of negation NNF (Negation Normal Form). This allows the user to display counterexamples if the knowledge base is contradictory or incomplete. The paper discusses the construction of a knowledge base in real time but does not consider the effect of retraining.
If it is necessary to represent data in tabular form for the application of matrix and vector processing operations, the decision-making table (DMT) is used [5]. In the subsequent work of the author, changes were made to the algorithm of formation, but the representation with the help of decision-making tables remained unchanged [6]. A big advantage of DMT is the visibility and convenient representation of data for the expert in the process of analyzing and filling out the database of rules. Another advantage is that the main operations of the production cycle are logical (vector and matrix) operations that make it possible to get a high processing speed. This makes it possible to use the tabular model of knowledge representation very effectively. To check the knowledge base, a disjunctive normal form is used, which is convenient for automatic proof of theorems. The proof process is based on the logic of propositions and the logic of predicates. In works [5,6], when using DMT, antecedents and consequents are represented compositionally, it is possible to consider antecedents as a separate matrix, and consequents as a vector.
To generate a database of Mamdani-type rules, paper [7] proposes the determination of optimal sequences based on the use of multiagent optimization algorithms, in particular ants. This approach makes it possible to effectively generate rule bases in the following cases: 1) if there is insufficient amount of initial information; 2) with a sufficiently large number of rules, for which the compilation of a database of fuzzy rules based on the knowledge of experts is not always effective; 3) with different levels of qualification of experts.
This does not address the question of a sufficient number of generation cycles and time to achieve the required level of model accuracy.
These approaches in [2][3][4][5][6][7] significantly increase the efficiency of using intelligent systems. Make it possible to form and verify the database of product rules, however: 1) impose limits on the number of terms of linguistic variables; 2) require the presence of an expert to analyze the verification work; 3) impose limits on the number of logical conclusions. The task of classification is considered. To solve the problem, an approach based on fuzzy logic is used.
Information about the subject area is represented in the form of a production model under the assumption that the left parts of the product rules describe combinations of features of objects, and the right ones correspond to classes.
In the formation of the left parts of products, the attributes of objects from some finite (quasi-finite, if it is permissible to replenish the model) set are used, the conjunction of the true values of which determines the conditions for the applicability of the product. On the right side, you specify classes from some finite allowable set of feature classes.
To ensure the reliability of inference based on the formulated knowledge base, it is necessary that the knowledge base has the properties of completeness, minimality (not redundancy), consistency, and coherence. An approach is being developed that provides validation for these properties.

The aim and objectives of the study
The purpose of the study is to develop an approach to the automatic generation of fuzzy production rules based on a training sample for solving the classification problem with the subsequent verification of the correctness of the constructed model. This will create fuzzy expert systems that can learn from test datasets. The production bases of the rules of such trained systems will allow experts to find hidden dependences between the features of objects and their classes.
To accomplish the aim, the following tasks have been set: -to create a production model for the representation of knowledge about objects of the subject area, combining the Mamdani and Takagi-Sugeno-Kang models, based on the results of observation of objects of the subject area: -to develop an algorithm for automatic generation and choose a way to represent the database of rules; -to develop an approach to verify the correctness of the rule base using Hoare logic and the resolution method. Apply Simplify software for automatic consistency proof; -to select metrics to assess the quality of the resulting fuzzy base of rules; -to apply the developed approach to check the correctness of the rule base for solving the classification problem.

The study materials and methods
The object of the study is the process of automatic formation of fuzzy production rules on the basis of a training sample for solving the classification problem. The task is stated in the following way: it is required to build fuzzy production rules for the MISO system on the basis of the training sample. At the same time, the basis of the hypothesis of the formation of rules is that the rules are built on the basis of linguistic variables and their term sets.
To construct the antecedents of the rules, the attributes of objects from the finite term set are used, the conjunction of the true values of which determines the conditions for the applicability of the product. The antecedents of the rules are represented as a matrix, this is necessary for the automatic formation of the matrix using the Cartesian product. For consequents, you specify classes from some finite allowable set of feature classes. Rule consequents are represented as a column vector, the values of the elements of the vector depend on the matrix of antecedents and the objects of the training sample. The formation of the vector of consequents is carried out using the training procedure of the knowledge base.
To check the obtained knowledge base for correctness, criteria are used: completeness, minimality, coherence, and consistency. To prove completeness, Hoare logic, the resolution method, and the Simplify application are used, which automatically check the system for consistency using first-order logic.
The developed approach is applied to solving the classification problem, the quality assessment of the resulting fuzzy base of rules is carried out using accuracy, precision, recall, f1-score metrics.

1. Production model of knowledge representation and inference method
Domain objects in the classification problem are described by a feature system , ,..., for each object x i ∈X, the features correspond to the linguistic variables k 1 , k 2 , ..., k L , wherein each linguistic variable contains a term set A lt , where l is the number of feature l L = 1, , and t T l = 1, ; T l is the number of terms for feature k l . The output variable y corresponds to the class to which the object of the subject area belongs. To solve the classification problem, we will build a production model of knowledge representation that combines the Mamdani and Takagi-Sugeno-Kang models [8].
Rules P p of the MISO type take the form: ... , IF is AND is AND AND is where k 1 , k 2 ,..., k L are the input linguistic variables;  a pl is a variable that takes fuzzy values A lt for the rule p; A lt is a fuzzy term set of the linguistic variable k l for the rule p; t is the number of term for k l , t T l = 1, ; T l is the number of terms for the feature k l ; y is the output variable; p is the rule number in the rule database, p P = 1, ; P is the total number of rules P; c p is a variable that takes fuzzy values of C m for the rule p; C m is the label of the fuzzy class to which the object x i ∈X belongs; m is the number of class C, m M = 1, ; M is the number of classes C. The real, non-negative, normalized function f(k 1 , ..., k L , p) is continuous over the interval [a, b] and is used as a weighting factor for the consequent of the rule. It determines the degree to which the output variable y belongs to the term set C m and is calculated as follows: ( The fuzzification procedure is defined as follows: where µ a l pl k ( ) is the function of attributing a clear value of the input variable k l to a fuzzy term a pl .
To automate the process of building rules, it is convenient to represent the antecedents of the rules in the form of a matrix A: ...
where a pl is an element of the matrix that takes the value  a pl of a variable from the rule system, and is equal to the fuzzy value A lt for the rule p; P -number of rules; L is the dimensionality of the feature vector K k k k L = ( ) 1 2 , ,..., of the object x i ∈X. We will represent the rule consequents as a column vector Further, the fuzzy set of classes  C that correspond to the output variable y is defined as: Thus, the set  C will consist of ordered pairs <f m |C m > such that: where the pair <f m |C m > determines the degree of belonging f m of object y i to class C m .
For  C defuzzification, the Mamdani's algorithm with the centroid method is used. The fuzzy set  C of classes corresponding to the input object X is defined as: wherein imp implication and agg aggregation operations are implemented by finding min and max, respectively.
The clear value of the logical inference C * is determined as a result of the defuzzification of the fuzzy set  C by the center of gravity method.

2. Algorithm of automatic formation of the rule da tabase
Below is the process of automatic formation of a knowledge representation model in the form of a matrix of antecedents A and a vector of consequents  C.
For each linguistic variable k l , there is a finite (quasifinite, if it is permissible to replenish the model) fuzzy term set A l = (A l1, A l2, A l3 , ..., A lt ), which defines the finite alphabet for describing the states or sets of states of the linguistic Variable.
The number of fuzzy classes C m to which the object x i ∈X belongs is also limited. Thus, the elements A lt and C m define the alphabet of the production model.
Formally, the matrix of antecedents A is given by an ordered set <A 11 , ..., A lt >, where each vector-row of matrix A is a set of conditions of the production rule. The vector of consequents  C consists of classes C m and has a dimensionality equal to the number of rules, sets the correspondence between the production rule in the matrix A and the fuzzy class C m .
The set of production rules P can be represented as: P p = <a p , c p >, where a p is the vector-string of the matrix A. Term-set A l = (A l1, A l2, A l3,..., A lt ) is ordered with respect to the semantic order and boundaries of the terms. To construct the matrix A, it is proposed to use the Cartesian product: Then, this set A xl can be represented as the following matrix A: .
The number of rules P is determined from the properties of the Cartesian product and is equal to the product of the number of elements of the multiplier sets: The formation of the vector of consequents is carried out using the training procedure of the knowledge base. Each object from the training sample X Train undergoes a fuzzification procedure fuzz x i where cord() is a function of the power of the set.
The vector  C must contain all C m classes, otherwise an incomplete or incorrect training sample is fed as input, and the system must be retrained on a different dataset.

3. Knowledge base correctness analysis
The knowledge base should meet uniform formal requirements of correctness, namely, be complete, minimal, coherent, and consistent [3].
Completeness is understood as any incoming combination of values of the terms of input linguistic variables corresponds to a certain rule in the rule base. The minimum database of rules is the base from which none of the production rules can be removed without violating its completeness. A knowledge base is consistent if it does not contain inconsistent rules -rules with the same linguistic conditions but different conclusions. The minimality and consistency of the formed knowledge base is ensured by the properties of the Cartesian product. The vector  C, built in the learning process on the basis of the training sample (8), is responsible for coherence. Each row of matrix (4) differs only in one of l subconditions since at the beginning of the formation of the matrix A the term-set A l = (A l1 , A l2 , A l3 ,..., A lt ) is ordered relative to the semantic order and boundaries of the terms.
To automatically prove the completeness of the database of rules, Hoare logic is used [9]. Define the Hoare triple: {Q}⋅S⋅{R}, where Q is the predicate of the precondition, S is the set of commands, R is the predicate of the postcondition. By the set of commands S, we will understand the set of production rules P p = <a⋅p,c p >: .
If the precondition Q is met, the command S renders true the postcondition R [10] true.
This statement is proved using the predicate of the weakest precondition WP(S, R) [11]: The WP predicate performs a substitution < > A C , To prove the truth of predicate (10), let's use the resolution method: Further, the rule of the resolution applies to the second and third disjuncts: , .
Considering (7), we obtain: Let's apply the law of distribution to the second disjunct and perform substitution S: As a result of applying the rule of resolutions to the first and second disjuncts, we obtain: {_}. The above proof shows the completeness of the postconditions based on the WP predicate.
To automatically check the rule database, we will use the Simplify software [12], which implements the resolution method to prove the truth of given predicates based on first-order logic. Formal calculus allows statements about variables, fixed functions, and predicates, which in turn extends the logic of propositions. Simplify never forms an infinite loop in the process of proof and believes that predicates whose truth cannot be proved are false [13].
Let's formulate the Hoare triple: Next, to prove correctness, we will formulate predicates using the directives of the Simplify language and conduct an automatic proof.
The Simplify axiom for the first conjunct of the precondition Q will be: After that, some body needs to translate Q and R into the Simplify language. Using the introduced axioms and predicates Q, S, R, automatic proof of the correctness of the knowledge base is organized.

4. Selecting metrics to assess the quality of a rule base
Since an expert system with a fuzzy base of rules is used to solve the problem, the result of the classification is approximate, so it is necessary to be able to assess the quality of the result obtained. To assess the quality of the classification result, carried out using a fuzzy base of rules, the following metrics are used in the work:

Checking the correctness of the rule base for solv ing the classification problem
The proposed approach was applied to the problem of classifying the species population of Arctic penguins [14]. The dataset contains data on 344 individuals of three species Chinstrap, Adelie, Gentoo. The attributes of individuals: bill_length_mm -the length of the beak; bill_depth_mm is the depth of the beak; flipper_length_mm is the length of the fin; body_mass_g is body weight. For the classification shown in Fig. 3, 4, a training and test sample of 300/44 (training/test) were formed. Fig. 1 depicts the result of the program for calculating the limit distribution diagram. Fig. 2 shows the result of checking the knowledge base for completeness using the weakest postcondition predicate and the Simplify program. Fig. 3, 4 show the results of the classification of the developed program before and after the training of a fuzzy knowledge base.
The dependence of the classification result on the size of the training sample before/after training is considered. To do this, a training and test sample of 200/144 (training/test) were formed. Fig. 5, a presents a matrix of contradictions before training; Fig. 5, b -after training the system. Tables 1, 2 give values of quality metrics before and after training, respectively. The contradiction matrices in Fig. 5, 6 are built by the developed program in Python.
To analyze the impact of the learning process on the classification result, the sample sizes were changed 250/94 (training/test). Fig. 6, a shows the matrix of contradictions before training; Fig. 6, b -after training the system. Tables 3, 4 give values of quality metrics before and after training, respectively.

Fig. 4. After training
The dependence of the classification result on the size of the training sample before/after training is considered. Samples 200/144 and 250/94 (training/test) were used.

Discussion of pre and posttraining classification results as a function of training sample size
Analysis of the limit distribution diagram (Fig. 1) showed that the Adelie and Chinstrap species are sufficiently related, and their classification can be difficult. This is especially noticeable for the attributes of body_mass_g and bill_depth_ mm - Fig. 1, g, i. Fig. 2 shows the result of checking the knowledge base for completeness using the predicate of the weakest postcondition. The «Valid» result shows the truth of the predicate Q => WP(S,R), and, consequently, the completeness of the knowledge base.
Applying the acquired knowledge base to training in Fig. 3 shows that the classes are not defined and the values in the results are mixed. There is no grouping of objects by class. But, after training in Fig. 4, you can see that the data are grouped, and each class is within the boundaries of its membership function. It should be noted that all 344 objects are present on the chart at the same time.
Next, the influence of the size of the training sample on the classification result and the quality of the expert system was considered. To do this, a training and test sample of 200/144 (training/test) was formed. Before studying, Fig. 5, a presents a matrix of contradictions and analysis of metrics in Table 1. According to the results, you can see that the accuracy is quite low, 34 %. After training, Fig. 5, b and the analysis of metrics in Table 2 demonstrate that the accuracy of the system has increased to 90 %, and the number of incorrect answers in the matrix of contradictions has significantly decreased.
Next, a training and test sample was formed in the amount of 250/94 (training/test). According to Fig. 6, a and Table 3, one can also see a low accuracy of 33 %, but, after training, Fig. 6, b, the accuracy increased to 93 % like the rest of the indicators in Table 4.
The analysis of Tables 1-4 reveals that increasing the volume of the training sample makes it possible to obtain an acceptable classification accuracy for the samples, as well as to adjust the vector of the consequents to solve the classification problem.
Our results differ from those in works [2][3][4][5][6][7] in that a method has been developed for automatically constructing a system of rules using the Cartesian product and the matrix representation of antecedents and consequents of rules, followed by automatic proof of the correctness of the rule system based on the method of resolutions using Hoare logic and the weak precondition predicate Q = >WP(S,R).
The developed approach will make it possible to find hidden dependences between a set of input parameters and output data of the model, automatically create a database of rules of the expert system and prove its correctness. This approach can be used to solve practical tasks of multiclass classification, control, decision-making, clustering, data mining.
The limitations of the application of this method include the fact that in the case of classification of objects whose features are strongly related, the necessary accuracy of classification is not achieved.
The disadvantage of this approach is the significant size of the rule base. To eliminate this problem, it is recommended to use the methods of reducing the knowledge base, which will make it possible to apply the proposed approach to the problems of classifying objects with a large number of attributes.

Conclusions
1. The paper reports the constructed production model of knowledge representation that combines the Mamdani and Takagi-Sugeno-Kang models and uses the function as a weighting factor for the rule's consequent. This has made it possible to determine the degree of influence of each rule on the output result of the production system. 2. A distinctive feature of the constructed model is the automatic formation of a database of rules based on the data of the domain model. An antecedent matrix is created using features of objects from some finite set using a Cartesian product. A training sample is used to form the consequent vector. Thanks to this, it is possible to create a database of rules and configure the model under an automatic mode.
3. An approach has been developed to check the correctness of production rules based on the resolution method using Hoare logic and the weak precondition predicate Q => WP(S,R). This approach makes it possible to automate the verification of the correctness of the rule base at the training stage.
4. To assess the quality of solving the classification problem, accuracy, precision, recall, f1-score metrics were used. High quality scores were obtained for the trained system (accuracy = 93 %, precision = 0.91, recall = 0.93, f1-score = 0.92) while, before training, the quality of the model was significantly lower (accuracy = 33 %, precision = 0.37, recall = 0.35, f1-score = 0.33). Before training, the accuracy of the model was insignificant, 33 %; after training, the accuracy of the model reaches 93 %. It is established that increasing the volume of training sample makes it possible to get an acceptable classification accuracy, as well as adjust the vector of consequents to solve the classification problem. Also, after training, the quality assessments of the model increase: accuracy, precision, recall, f1-score. 5. The proposed approach is used to solve the classification problem. The correctness of the automatically constructed fuzzy database of rules for solving the classification problem was checked. An assessment of the quality of the obtained fuzzy base of rules was carried out, as a result of which the accuracy of the model reaches 93 %. The analysis of the results of the computational experiment was carried out; it was established that the size of the training sample affects the classification result and the quality of the expert system.

Conflicts of interest
The authors declare that they have no conflict of interest in relation to this research, whether financial, personal, authorship or otherwise, that could affect the research and its results presented in this paper.

Financing
The study was conducted without financial support.

Data availability
All data are available in the main text of the manuscript.