Fuzzy Logic. What is wrong with my T1 Degree of Truth implementation:
List values;
Map<Double, Double> result = new HashMap<>();
for (Summarizer summarizer : summaryForm1.getSummarizers()) {
values = getValues(summaryForm1.getRecords(), summarizer.getLinguisticVariableName(), summarizer.getLabelType());
Map<Double, Double> summResult = summarizer.getFuzzySet().getFuzzySet(values);
for (Double value : summResult.keySet()) {
if (result.containsKey(value)) {
result.put(value, Math.min(result.get(value), summResult.get(value)));
} else {
result.put(value, summResult.get(value));
}
}
}
double sigma_count = 0;
for (Double value : result.values()) {
sigma_count += value;
}
sigma_count represents sum of degrees of membership
Assistant
Your implementation of the T1 Degree of Truth in Fuzzy Logic involves several steps and it looks largely functional. However, there are a few points that might need clarification or correction for optimal operation:
Handling of Fuzzy Set Intersection:
The operation where you calculate the minimum of corresponding degrees of membership across different fuzzy sets (Math.min(result.get(value), summResult.get(mddValue));) suggests an intersection of fuzzy sets. This part seems correct provided this is intended for handling conditions where multiple summarizers should all agree (an "AND" condition in fuzzy logic). If you need an "OR" operation, you should use Math.max instead of Math.min.
Norm Calculation for Continuous Values:
Your loop where you sum up the values of result.values() and then normalize this sum depending on whether the quantifier is relative or absolute seems slightly ambiguous. Typically, when dealing with fuzzy logic:
For relative quantifiers: The final calculation should involve the proportion of the sum of the truth values to the possible maximum sum (which might not necessarily be the size of the list, depending on how your fuzzy sets are defined and calculated).
For absolute quantifiers: The handling could vary depending on the specific case. If sigma_count represents an absolute count of items that meet a certain fuzzy criterion, then normalizing this by the size of records might not be the correct approach unless you strictly want to convert a count to a proportion.
Ambiguity in Quantifier Handling:
Both your conditional branches for relative and absolute quantifiers execute the same code. This might be correct but typically points to redundant code or an oversight. Ensure that the handling of absolute and relative quantifiers is indeed intended to be identical. If not, adjust accordingly.
Precision of Membership Values:
Make sure that getGradeOfMembership in your fuzzy set implementations behaves as expected, especially when dealing with boundary values of membership grades which depend on the kind of membership functions used (e.g., trapezoidal, Gaussian).
Map Handling:
Your use of a HashMap might introduce precision issues if Double values are used as keys due to their floating-point nature. Small inaccuracies in floating-point representation could lead to equality checks failing or unexpected behavior when retrieving values. Consider using a threshold for comparing double values or rounding to a fixed number of decimal places.
To improve your code:
Verify the logic behind using similar processing for both relative and absolute quantifiers.
Consider edge cases and how floating-point inaccuracies can affect the results.
Ensure that the way you compute the norm (sigma_count) aligns accurately with theoretical expectations of your application's fuzzy logic.
Here is a short refinement considering the probable intended logic for the quantifiers:
In the above snippet, getPotentialMaxSum() must be a method that calculates the maximum possible sum of membership values assuming maximal membership for all items. This makes sense if the sets have maximum densities that do not always equal the size of the record list.
Ultimately, your implementation will depend heavily on specific details like the nature of your fuzzy sets, membership functions, and the domain/problem-specific requirements for using absolute and relative quantifiers in your fuzzy logic setup.
Thank you for the clarification. Since sigma_count represents the sum of degrees of membership, the approach needs to adjust slightly depending on whether the quantifiers are used in a relative or an absolute setting. Your code currently uses the same calculation method for both relative and absolute quantifiers, so here's more specific advice on handling this differentiation properly:
Relative Quantifiers
For relative quantifiers, the degree of truth is generally calculated relative to the total number of records, as it aims to express a proportion of the total sample. This means that the sum of membership values (sigma_count) should be divided by the number of records to get the relative sum of membership:
For absolute quantifiers, the sum of membership should not necessarily be normalized by the number of records, because an absolute quantifier reflects a count or an aggregation that doesn't directly relate to the proportion of the total. Instead, sigma_count might be used directly, depending on your application:
java
else if (summaryForm1.getQuantifier().getLabelType() == LabelType.ABSOLUTE) {
return summaryForm1.getQuantifier().getFuzzySet().getGradeOfMembership(sigma_count);
}
Additional Considerations
Adjusting Input Values
Ensure that the input values that contribute to sigma_count, the sum of membership values, accurately reflect the intent of your linguistic variables and summarizers. If there is any transformation or scaling required on your data before applying fuzzy logic, make sure this is incorporated into your calculation.
Revisiting getGradeOfMembership
Verify that getGradeOfMembership handles inputs thoughtfully, particularly at the boundaries. Fuzzy membership functions sometimes have limits or thresholds beyond which the membership drastically changes. Your application needs to handle such situations correctly.
Precision and Scale
Given that you are working with Double values, remember to handle rounding or precision issues especially when values are intended to precisely match. As mentioned previously, small floating-point inaccuracies can result in unexpected behaviors. Consider using a specific precision or rounding off where necessary.
java
else if (summaryFormMethods are using appropriate comparisons and calculations, taking into account all these elements to ensure the results align with the theoretical intentions of your fuzzy logic system.
By refining these parts of your implementation, your system will not only be more robust but also adhere closer to the theoretical underpinnings of fuzzy logic as applied to your specific domain.