Idea Number Three
...But thoughts about my research would not let me go. I had an idea: how can algorithms for processing highly fuzzy data be implemented in existing information systems?
Suppose we have a database where precise data is collected somehow (the collection method is not important right now). The data is structured and quite crisp, represented as time series. The question is: how can we process this data quickly using the principles of fuzzy logic?
Imagine the database contains the following tables:
temperatures (id, value, date, place) — a time series of ambient temperatures: identifier, temperature value, date, and place.
yields (id, value, date, place, culture) — harvested-yield data extended with crop information.
This is a fairly standard representation of data—precise and understandable. But here is the question: do we actually need that level of precision for comparison and analysis? I believe we do not. We do not need to compare 21.3°C to 126.723 tons of grain in order to identify patterns. It is enough to know that 21.3°C is a sufficient average temperature during the growing season to achieve a good harvest of 126.723 tons.
Notice that I used adjectives: "sufficient" for temperature and "good" for yield. Those are no longer exact values, but their human, subjective interpretation—which is exactly what fuzzy data represents. In a particular context (for example, wheat cultivation), such interpretations can be far more useful than absolute numbers.
Tomorrow has come. Let’s continue.
The idea is to add several objects to the database that automatically transform precise data into fuzzy representations using rules defined by context.
Let’s start with a contexts table (id, name, description), which defines the context of analysis (for example, crop production, wheat crop). Then, for the temperatures table, let’s create a temperaturesrules table (id, contextid, expression, parameters).
contexts describes the analysis context, for example, "optimal conditions for growing wheat."
temperaturesrules binds a membership function to a specific context. This table stores:
The algebraic expression of the membership function (expression).
The parameters of that function in JSON format (parameters).
What is a membership function?
A membership function defines the degree to which an element of a crisp set belongs to a fuzzy set. It takes values from 0 to 1:
0 — the element does not belong to the set at all.
1 — the element fully belongs to the set.
Values between 0 and 1 indicate partial membership.
---
Now let’s create an SQL function to compute membership:
CREATE OR REPLACE FUNCTION EvaluateMembership(
value NUMERIC, -- Input value
expression TEXT, -- Mathematical expression
parameters JSONB -- Function parameters in JSON format
) RETURNS NUMERIC AS $$
DECLARE
substituted_expression TEXT; -- Expression with substituted parameters
BEGIN
-- Replace parameters in the expression with values from JSON
substituted_expression := expression;
FOR key, val IN SELECT * FROM jsonb_each_text(parameters)
LOOP
substituted_expression := replace(substituted_expression, key, val);
END LOOP;
-- Execute the expression
RETURN EXECUTE format('SELECT %s::NUMERIC', substituted_expression);
END;
$$ LANGUAGE plpgsql;
This function takes three arguments:
value — the input value from the data table.
expression — the formula from the rules table.
parameters — the formula parameters that define the boundaries of the membership function.
As output, the function returns a value in the range from 0 to 1, indicating the degree to which an element belongs to the fuzzy set. It may be a triangular, trapezoidal, or Gaussian membership function—the exact type depends on the parameters provided.
What does such a system give you?
It makes data processing universal. You can compute membership for any context and any function, adapting the system to your tasks. The main thing to remember is that the result should always stay within the interval [0, 1].
Conclusion
Your hands are now untied: analyze, forecast, experiment with functions! Everything is ready for implementation.