urclib.fuzzylogic.combiner
Logic for combining crisp values from fuzzy logic analysis.
Module Contents
Classes
Utility for applying defuzzification operators and combining |
- class urclib.fuzzylogic.combiner.FLCombiner(combinestr='', default_defuzz='centroid', **kwargs)
Bases:
objectUtility for applying defuzzification operators and combining multiple decision spaces from fuzzy logic implications.
- Parameters:
combineStr (str, optional) – Default python equation for combining defuzzed values.Defaults to empty str.
defaultDefuzz (str, optional) – String identifier of operator used to defuzz an implication by default. Options are: - centroid: Use the centroid of the decision space. This is the default. - bisector: Use the bisector value of the decision space. - smallest_of_maximum: The smallest x-value of all values that correspond to the maximum y-value. - largest_of_maximum: The largest x-value of all values that correspond to the maximum y-value. - mean_of_maximum: The mean of all x-values that correspond to points at the maximum y-value.
- Keyword Arguments:
defuzzDict (dict) – Dictionary with a Fuzzy Logic set name as the key, and the defuzz operator to apply as the value. The valid defuzz values are identical to those listed for the defaultDefuzz argument.
- property found_implication_names
A list of names of the implications expected to be passed in during evaluation.
- Type:
list
- set_defuzz_for_implication(impname, opname)
Set the defuzz operator to use for a specific implication.
- Parameters:
impname (str) – The name of the fuzzy logic set to apply the defuzz operator to.
opname (str) – The key for the centroid operator. See the ‘defaultDefuzz’ in the class argument list.
- parselogic(evalstr, refresh=False)
Parse the logic from instructions on how to combine defuzzed values.
- Parameters:
evalstr (str) – The string of python logic to evaluate.
refresh (bool, optional) – If true, likely implication names will be extracted evalStr. This is useful for error checking. Defaults to False.
- evaluate(implications, envargs=None, defuzzargs=None)
Evaluate the defuzzification operations and combining logic.
- Parameters:
implications (dict) – Dictionary of implications to act upon.
envargs (dict,optional) – Additional arguments to pass to the execution environment.
defuzzargs (list,optional) – Additional arguments to pass on to defuzzification operations.
- Returns:
A number value representing the combined defuzzed values.
- Return type:
float
- Raises:
fuzzylogic.FuzzyNoValError – If an expected implication is not found in implications, or if the implication processing encountered a fuzzy logic-specific error.
- cleardefuzzforimplication(impl)
Clear the defuzzification operator applied to a specific implication.
- Parameters:
impl (str) – The name of the implication to clear.
- defuzzop_for_implication(impl, ret_default=False)
Retrieve the defuzzification operator for a specific implication.
- Parameters:
impl (str) – The name of the implication to query.
ret_default (bool, optional) – Only effects implications assigned to the default operator; Return the default defuzz operator if True, or None if False. Defaults to False.
- Returns:
The identifier of the defuzz operator of the implication. None: If the implication uses the default operator and retDefault is False.
- Return type:
str
- static parse_expected(evalstr)
Capture any likely variable names within a statement.
- Parameters:
evalstr (str) – The statement to evaluate.
- Returns:
list of strings representing suspected variable names in provided statement.
- Return type:
list
- static nodata_op(val, isval, isnotval=None)
Checks if a variable is a NO DATA value and returns the appropriate value.
- Parameters:
val (float) – The value to evaluate for NO DATA.
isval (float) – The value to return if
valis NO DATA.isnotval (float, optional) – The value to return if
valis not NO DATA
Returns:
- static maxop(lhs, rhs, *args, **kwargs)
Overload of built-in max to properly handle the presence of a nodata sentinel.
Notes
The kwargs will be ignored, relying instead on our function.
- Parameters:
lhs (object) – The first argument to check.
rhs (object) – The second argument to check.
*args – Additional values to compare.
**kwargs – ignored.
- Returns:
The greater of the two objects, incorporating knowledge of the sentinels, if any present.
- Return type:
object
- static minop(lhs, rhs, *args, **kwargs)
Overload of built-in min to properly handle the presence of a nodata sentinel.
Notes
The kwargs will be ignored, relying instead on our function.
- Parameters:
lhs (object) – The first argument to check.
rhs (object) – The second argument to check.
*args – Additional values to compare.
**kwargs – ignored.
- Returns:
The lesser of the two objects, incorporating knowledge of the sentinels, if any present.
- Return type:
object
- static sumop(*args)
Standard sum operator.
- Parameters:
*args – Values to sum together.
- Returns:
The total of all combined values of args.
- Return type:
number
- static prodop(*args)
Standard product operator.
- Parameters:
*args – The values to multiply together.
- Returns:
The product of all combined values in args.
- Return type:
number
- static gammaop(gammaval, *args)
Gamma operator mimicing the Fuzzy Logic equivalent.
- Parameters:
gammaval (number) – Value in the range of [0,1].
*args – The values to evaluate using the gamma value.
- Returns:
The results of the gamma operation.
- Raises:
ValueError – If gammaval is not in the range of [0,1].