Class: FuzzyVariable
- Inherits:
-
Object
- Object
- FuzzyVariable
- Includes:
- Norm
- Defined in:
- lib/rfuzzy/fuzzy_variable.rb
Overview
Represents fuzzy value belonging to a specific domain. Calculates the adherence on demand.
Constant Summary
Constants included from Norm
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#*(float) ⇒ Object
returns new FuzzyVariable with value multiplied by float
.*(float)
. -
#initialize(val, &block) ⇒ FuzzyVariable
constructor
Constructor.
-
#is(lex_var, method = :auto) ⇒ Object
Calculates the adherence of variable.
-
#is_not(lex_var, method = :auto) ⇒ Object
Calculates negation of variables adherence.
- #to_f ⇒ Object
Methods included from Norm
norm_method, #s_norm_max_min, #s_norm_prob, #t_norm_max_min, #t_norm_prob
Constructor Details
#initialize(val, &block) ⇒ FuzzyVariable
Constructor. Usage .new(Float value)
9 10 11 12 13 14 |
# File 'lib/rfuzzy/fuzzy_variable.rb', line 9 def initialize(val, &block) @value = val.to_f if block_given? yield self end end |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
5 6 7 |
# File 'lib/rfuzzy/fuzzy_variable.rb', line 5 def domain @domain end |
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/rfuzzy/fuzzy_variable.rb', line 5 def value @value end |
Instance Method Details
#*(float) ⇒ Object
returns new FuzzyVariable with value multiplied by float .*(float)
22 23 24 |
# File 'lib/rfuzzy/fuzzy_variable.rb', line 22 def *(float) return FuzzyVariable.new(@value*float.to_f, @domain) end |
#is(lex_var, method = :auto) ⇒ Object
Calculates the adherence of variable. Usage: .is(String lex_var, Symbol method)
<tt>.is(String lex_var)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rfuzzy/fuzzy_variable.rb', line 29 def is(lex_var, method = :auto) if(method == :auto) unless @@norm_method.nil? method = @@norm_method else raise ArgumentError, "Specify method, or call Norm::norm_method" end end if @domain.adherence_functions.has_key? lex_var return Adherence.new(@domain.adherence_functions[lex_var].at(@value)) else raise ArgumentError, "Specified adjective '#{lex_var}' does not belong to variable's domain" end end |
#is_not(lex_var, method = :auto) ⇒ Object
Calculates negation of variables adherence. Usage - same as .is
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rfuzzy/fuzzy_variable.rb', line 45 def is_not(lex_var, method = :auto) if(method == :auto) unless @@norm_method.nil? method = @@norm_method else raise ArgumentError, "Specify method, or call Norm::norm_method" end end if @domain.adherence_functions.has_key? lex_var return Adherence.new(1-@domain.adherence_functions[lex_var].at(@value)) else raise ArgumentError, "Specified adjective does not belong to variable's domain" end end |
#to_f ⇒ Object
16 17 18 |
# File 'lib/rfuzzy/fuzzy_variable.rb', line 16 def to_f return @value end |