fuzzy_associative_memory 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +10 -0
- data/README.md +2 -0
- data/bin/hvac_system_example.rb +4 -0
- data/bin/weapon_choice_example.rb +6 -0
- data/lib/fuzzy_associative_memory/linguistic_variable.rb +75 -0
- metadata +4 -9
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Changelog for fuzzy-associative-memory
|
2
|
+
|
3
|
+
## 1.1, 26 July 2013
|
4
|
+
* Fuzzy Linguistic Variables are hard to visualize, especially when they get complex. To remedy that, you can now instruct an FLV to shell out to your installed Gnuplot and plot itself. The images are saved in your system's tmpdir.
|
5
|
+
|
6
|
+
## 1.0.1, 28 June 2013
|
7
|
+
* Based on good feedback, revised the initializer for `Rule` to put the `natural_language` parameter at the end and make it optional. I realize this is a disruptive alteration to the API and I apologize for the code adjustments this will necessitate. (I had to pay the penance of refactoring a lot of my own code, if that helps.)
|
8
|
+
|
9
|
+
## 1.0.0, 26 June 2013
|
10
|
+
* Initial Gem release
|
data/README.md
CHANGED
@@ -44,6 +44,8 @@ To do (in descending importance, roughly):
|
|
44
44
|
* Other shapes for fuzzy sets
|
45
45
|
* Hedges ('very' and 'fairly')
|
46
46
|
* Additional examples
|
47
|
+
|
48
|
+
Watch the [changelog](http://github.com/cpowell/fuzzy-associative-memory/blob/master/CHANGELOG.md) for news.
|
47
49
|
|
48
50
|
## Gem installation
|
49
51
|
|
data/bin/hvac_system_example.rb
CHANGED
@@ -31,6 +31,8 @@ warm = FuzzyAssociativeMemory::Triangle.new(65, 75, 85) # 20 deg wide
|
|
31
31
|
hot = FuzzyAssociativeMemory::Trapezoid.new(80, 90, 90, 90) # 20 deg wide
|
32
32
|
|
33
33
|
temperature_in.sets = [cold, cool, just_right, warm, hot]
|
34
|
+
# Comment out if you don't have Gnuplot installed:
|
35
|
+
temperature_in.gnuplot
|
34
36
|
|
35
37
|
# The output side -- the consequent -- expressed as a number of fuzzy sets,
|
36
38
|
# with each set representing a natural-language description. The 'resultant
|
@@ -44,6 +46,8 @@ fast = FuzzyAssociativeMemory::Triangle.new(50, 70, 90) # 40 CFM wide
|
|
44
46
|
blast = FuzzyAssociativeMemory::Triangle.new(70, 100, 130) # 60 CFM wide
|
45
47
|
|
46
48
|
fan_speed.sets = [stop, slow, medium, fast, blast]
|
49
|
+
# Comment out if you don't have Gnuplot installed:
|
50
|
+
fan_speed.gnuplot
|
47
51
|
|
48
52
|
# Natural-language marriage of the inputs to the outputs, e.g.
|
49
53
|
# "If the temperature is cool, the fan motor speed should be slow."
|
@@ -34,6 +34,8 @@ tgt_medium = FuzzyAssociativeMemory::Triangle.new(25, 150, 300)
|
|
34
34
|
tgt_far = FuzzyAssociativeMemory::Trapezoid.new(150, 300, 500, 650)
|
35
35
|
|
36
36
|
target_dist.sets = [tgt_close, tgt_medium, tgt_far]
|
37
|
+
# Comment out if you don't have Gnuplot installed:
|
38
|
+
target_dist.gnuplot
|
37
39
|
|
38
40
|
# Now for the second input (or antecedent): the amount of ammo left for this
|
39
41
|
# particular weapon.
|
@@ -44,6 +46,8 @@ rkt_ammo_okay = FuzzyAssociativeMemory::Triangle.new(0, 10, 30)
|
|
44
46
|
rkt_ammo_loads = FuzzyAssociativeMemory::Trapezoid.new(10, 30, 40, 40)
|
45
47
|
|
46
48
|
rocket_ammo_status.sets = [rkt_ammo_low, rkt_ammo_okay, rkt_ammo_loads]
|
49
|
+
# Comment out if you don't have Gnuplot installed:
|
50
|
+
rocket_ammo_status.gnuplot
|
47
51
|
|
48
52
|
# The output side -- the consequent -- expressed as a number of fuzzy sets,
|
49
53
|
# with each set representing a natural-language description. The 'resultant
|
@@ -55,6 +59,8 @@ desirable = FuzzyAssociativeMemory::Triangle.new(30, 50, 70)
|
|
55
59
|
very_desirable = FuzzyAssociativeMemory::Trapezoid.new(50, 80, 100, 100)
|
56
60
|
|
57
61
|
desirability.sets = [undesirable, desirable, very_desirable]
|
62
|
+
# Comment out if you don't have Gnuplot installed:
|
63
|
+
desirability.gnuplot
|
58
64
|
|
59
65
|
# Natural-language marriage of the inputs to the outputs, e.g.
|
60
66
|
# "If the temperature is cool, the fan motor speed should be slow."
|
@@ -6,6 +6,8 @@
|
|
6
6
|
# You can redistribute and/or modify this software only in accordance with
|
7
7
|
# the terms found in the "LICENSE" file included with the library.
|
8
8
|
#
|
9
|
+
require 'tempfile'
|
10
|
+
|
9
11
|
class FuzzyAssociativeMemory::LinguisticVariable
|
10
12
|
attr_accessor :sets
|
11
13
|
attr_reader :name
|
@@ -19,6 +21,79 @@ class FuzzyAssociativeMemory::LinguisticVariable
|
|
19
21
|
@sets << set
|
20
22
|
end
|
21
23
|
|
24
|
+
def gnuplot
|
25
|
+
return if @sets.empty?
|
26
|
+
|
27
|
+
datafile = Tempfile.new('fam_')
|
28
|
+
begin
|
29
|
+
@sets.each_with_index do |s, i|
|
30
|
+
if s.is_a? FuzzyAssociativeMemory::Triangle
|
31
|
+
datafile.puts "Set#{i} #{s.left} 0"
|
32
|
+
datafile.puts "Set#{i} #{s.center} 1"
|
33
|
+
datafile.puts "Set#{i} #{s.right} 0"
|
34
|
+
end
|
35
|
+
|
36
|
+
if s.is_a? FuzzyAssociativeMemory::Trapezoid
|
37
|
+
datafile.puts "Set#{i} #{s.left} 0"
|
38
|
+
datafile.puts "Set#{i} #{s.top_left} 1"
|
39
|
+
datafile.puts "Set#{i} #{s.top_right} 1"
|
40
|
+
datafile.puts "Set#{i} #{s.right} 0"
|
41
|
+
end
|
42
|
+
|
43
|
+
datafile.puts "\n\n"
|
44
|
+
end
|
45
|
+
datafile.close
|
46
|
+
|
47
|
+
min = @sets[0].left
|
48
|
+
max = @sets[0].right
|
49
|
+
@sets.each do |s|
|
50
|
+
min = s.left if s.left < min
|
51
|
+
max = s.right if s.right > max
|
52
|
+
end
|
53
|
+
|
54
|
+
fn = "#{Dir.tmpdir}/plot of #{name}.svg"
|
55
|
+
|
56
|
+
# set term dumb
|
57
|
+
commands = %Q(
|
58
|
+
set terminal svg
|
59
|
+
set autoscale
|
60
|
+
set xlabel 'value'
|
61
|
+
set ylabel 'membership'
|
62
|
+
set xtic auto
|
63
|
+
set ytic auto
|
64
|
+
set output "#{fn}"
|
65
|
+
set title "Fuzzy sets for #{name}"
|
66
|
+
set mytics 4
|
67
|
+
set mxtics 4
|
68
|
+
set size ratio 0.35
|
69
|
+
set grid x y
|
70
|
+
set xr [#{min}:#{max}]
|
71
|
+
)
|
72
|
+
|
73
|
+
# plot "#{datafile.path}" using 2:3 notitle with linespoints lw 2
|
74
|
+
|
75
|
+
plotarr=[]
|
76
|
+
@sets.size.times do |i|
|
77
|
+
plotarr[i] = %Q("#{datafile.path}" index #{i} using 2:3 notitle with linespoints pt 5 lw 2)
|
78
|
+
end
|
79
|
+
|
80
|
+
commands += " plot " + plotarr.join(', ') + "\n"
|
81
|
+
# puts commands
|
82
|
+
|
83
|
+
IO.popen("gnuplot", "w") do |io|
|
84
|
+
io.puts commands
|
85
|
+
end
|
86
|
+
puts "Plot saved in #{fn}"
|
87
|
+
|
88
|
+
rescue StandardError => e
|
89
|
+
puts "Unable to run Gnuplot because #{e.message}"
|
90
|
+
ensure
|
91
|
+
datafile.close
|
92
|
+
datafile.unlink
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
22
97
|
def [](n)
|
23
98
|
@sets[n]
|
24
99
|
end
|
metadata
CHANGED
@@ -2,23 +2,17 @@
|
|
2
2
|
name: fuzzy_associative_memory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0
|
5
|
+
version: 1.1.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Chris Powell
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: |2
|
15
|
-
A Fuzzy Associative Memory (FAM for short) is a Fuzzy Logic tool for decision making. Fuzzy logic FAMs have a wide range of practical applications:
|
16
|
-
|
17
|
-
* Control systems, such as governing a fan to keep a room at the "just right" temperature
|
18
|
-
* Game AI, such as imbuing bots with human-like decision-making behavior
|
19
|
-
* Prediction systems, linking causes with effects
|
20
|
-
|
21
|
-
A Fuzzy Associative Memory uses Fuzzy Sets to establish a set of rules that are linguistic in nature. The linguistic rules, and the fuzzy sets they contain, are defined by a human "expert" (presumably, you). That is to say, the rules codify intelligence and map this knowledge from the human domain to the digital.
|
15
|
+
A Fuzzy Associative Memory (FAM for short) is a Fuzzy Logic tool for decision making. Fuzzy logic FAMs have a wide range of practical applications: Control systems, such as governing a fan to keep a room at the "just right" temperature; Game AI, such as imbuing bots with human-like decision-making behavior; Prediction systems, linking causes with effects. A FAM uses Fuzzy Sets to establish a set of rules that are linguistic in nature. The linguistic rules, and the fuzzy sets they contain, are defined by a human "expert" (presumably, you). The rules therefore codify intelligence and map this knowledge from the human domain to the digital.
|
22
16
|
email: cpowell@prylis.com
|
23
17
|
executables: []
|
24
18
|
extensions: []
|
@@ -33,6 +27,7 @@ files:
|
|
33
27
|
- lib/fuzzy_associative_memory/triangle.rb
|
34
28
|
- bin/hvac_system_example.rb
|
35
29
|
- bin/weapon_choice_example.rb
|
30
|
+
- CHANGELOG.md
|
36
31
|
- LICENSE
|
37
32
|
- Rakefile
|
38
33
|
- README.md
|