The need for fuzzy logic
arises in many areas, including artificial intelligence
, control
and decision-making
. Fuzziness is an integral part of the real world, so fuzzy logic is actively used to develop intelligent systems
capable of processing and analyzing fuzzy information. The main problem of this topic is its inaccessibility. The fact is that the theory of fuzzy sets is studied at the senior courses of universities, and the materials presented in the public domain include terms, formulas and designations that are incomprehensible to schoolchildren. This project is aimed at popularizing fuzzy logic by writing an application for Android OS
, as well as developing a real prototype of the Maxwell pendulum
(the task is to keep the pendulum within the specified boundaries) to demonstrate the operation of a controller running on fuzzy rules.
Next, the functionality that allows the user to study the proposed topic will be described.
"Fuzzy logic is the art of finding beauty in uncertainty" — Lotfi A. Zadeh
To solve this problem, the theory of fuzzy sets is used, since it avoids a large number of calculations in fuzzy modeling problems.
The rule base
consists of several fuzzy rules in which each gasified value of the pendulum position and velocity corresponds to a fuzzy number. The rule base may look like this:
-
x is the position of the pendulum;
-
v is the speed of the pendulum;
-
w – conclusion.
In the author 's code , the rule looks like this:
x1 = Trapezoid([0.09,0.14,0.156,0.175,1]).trapezoid();
v1 = Trapezoid([0.280,0.351,0.466,0.616,1]).trapezoid();
w1 = Trapezoid([6.00,9.550,13.550,16.350,1]).trapezoid().
In the example above, there is a Trapezoid
class that has a trapezoid()
method that fuzzifies a number.
Fuzzification
is the process of translating input data into fuzzy data by finding the degree of belonging of a measurement to a fuzzy set. As input data, we get the position
of the model (x) and the velocity
(v). The trapezoidal membership function is given by four numbers and calculated according to the expression:
Oprimization algorithm | Description |
---|---|
basin hopping |
A global optimization method used to solve optimization problems that have a complex energy surface. |
genetic algorithm |
An optimization method that uses ideas from evolutionary biology and genetics to solve problems. |
particle swarm algorithm |
An optimization method that simulates the behavior of a flock of particles in space to find optimal solutions in multidimensional problems. |
This function gets the position
, speed
and acceleration
from a given time, returns new values
by certain transformations.
def f(x, v, w):
a = (m * r * r * (g - w)) / (0.5 * (m * R * R + maxis * r * r) + (m + maxis) * r * r)
if (x == R and v < 0) or (x == l and v > 0):
v = -v * (1 - k)
xnew = x + v * dt + 0.5 * dt ** 2 * a
vnew = v + a * dt
if xnew > l:
xnew = l
if xnew < R:
xnew = R
return xnew, vnew
The full version of the documentation you can find here.
- Сontrol of the pendulum using the built-in accelerometer with the ability to change the parameters of the model.
- Drawing up your rule base using the presented global optimization algorithms in the application (all has a description).
- Control of the physical model of the Maxwell pendulum.
- The imposition of rules on the mathematical model of the Maxwell pendulum.
- More information about the functionality and work of the physical model you can find here.
- Java (JDK 11)
- Python 3.10.12
- Android Studio Dolphin (2021.3.1)
- MPAndroidChart
- SciPy (1.10.1)
- Matplotlib (3.6.3)
- MySQL
Project FuzzyContApp is distributed under the MIT license.