File: classes.lisp

package info (click to toggle)
cl-rsm-fuzzy 1.3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 116 kB
  • ctags: 72
  • sloc: lisp: 824; makefile: 44; sh: 28
file content (164 lines) | stat: -rw-r--r-- 5,046 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
;;;; *************************************************************************
;;;; FILE IDENTIFICATION
;;;;
;;;; Name:          classes.lisp
;;;; Purpose:       Fuzzy Class Definitions.
;;;; Author:        R. Scott McIntire
;;;; Date Started:  Aug 2003
;;;;
;;;; $Id: classes.lisp,v 1.2 2003/09/10 22:19:24 rscottmcintire Exp $
;;;; *************************************************************************

(in-package rsm.fuzzy)

(eval-when (:compile-toplevel)
  (declaim (optimize (speed 3) (debug 0) (safety 1) (space 0))))


;;; A Named class.
(defclass named-fuzzy ()
  ((name :accessor fuzzy-name 
         :initform nil 
         :initarg :name)))


;;; Abstract Base classes used for Fuzzy Systems.
(defclass fuzzy-adj (named-fuzzy)
  ())

(defclass fuzzy-var (named-fuzzy)
  ())

(defclass fuzzy-rule (named-fuzzy)
  ())

(defclass fuzzy-adj-group (named-fuzzy)
  ())

(defclass fuzzy-system (named-fuzzy)
  ())


(defclass standard-fuzzy-system (fuzzy-system)
  ((var-hash :accessor var-hash 
             :initform (make-hash-table :test #'equal) 
             :initarg :var-hash)
   
   (adj-hash :accessor adj-hash 
             :initform (make-hash-table :test #'equal) 
             :initarg :adj-hash)
   
   (adj-group-hash :accessor adj-group-hash 
                   :initform (make-hash-table :test #'equal) 
                   :initarg :adj-group-hash))
  (:documentation
   "A Fuzzy System Class.
Contains all the adjectives, variables, and adjective groups for a 
fuzzy system."
   ))



(defclass standard-fuzzy-adj (fuzzy-adj) 
  ;; XY pairs that represent the piece-wise linear function defining
  ;; the fuzzy adjective.
  ((xy-pairs :accessor xy-pairs 
             :initform nil 
             :initarg :xy-pairs)
   
   ;; Beginning of function domain, determined from xy-pairs.
   (start :reader start 
          :initform nil 
          :initarg :start
          :type single-float)
   
   ;; End of function domain, determined from xy-pairs.
   (end :reader end 
        :initform nil 
        :initarg :end
        :type single-float))
  (:documentation
   "A Fuzzy Adjective Class.
 The Fuzzy adjective is essentially a named piece-wise linear function 
 with values between 0.0 and 1.0. This function is used with fuzzy 
 variables to get a \"measure\" of how much a fuzzy variable can be 
 thought of as belonging to an adjective.
 Example adjective: sym = 'small; xy-pairs = a list of x-y pairs that 
 determine the piecewise linear function.
 NOTE: 'start' and 'end' are determined by an after method on 
        initialize-instance.
 NOTE: The measure of a fuzzy variable whose numeric value is 
        after \"end\" or before \"start\" is zero."
   ))

(defclass standard-fuzzy-var (fuzzy-var) 
  ;; Value of fuzzy variable.
  ((value :accessor var-value 
          :initform nil 
          :initarg :value 
          :type single-float)
   
   ;; A fuzzy-adj-group 
   (adj-group :accessor adj-group 
              :initform nil 
              :initarg :adj-group)
   
   ;; A list of rules.
   (rules :accessor rules 
          :initform nil 
          :initarg :rules)
   
   ;; Rules hashed by name.
   (rule-hash :accessor rule-hash 
              :initform (make-hash-table :test #'equal) 
              :initarg :rule-hash ))
  
  (:documentation
   "A Fuzzy Variable Class.
 A named numeric value associated with a list of Fuzzy rules.
 The rules, in tern, describe relationships (which may conflict) with other 
 Fuzzy variables using Fuzzy adjectives.
 Example variable: sym = 'x; value = 2.1; rules = nil OR a list of rule 
 objects."
   ))

(defclass standard-fuzzy-rule (fuzzy-rule)   
  ;; The "if" part of rule.
  ((antecedent :accessor antecedent 
               :initform nil 
               :initarg :antecedent)
   
   ;; The "then" part of rule - a fuzzy-adj.
   (consequent :accessor consequent 
               :initform nil 
               :initarg :consequent 
               :type standard-fuzzy-adj)

   ;; The original rule as a form.
   (rule-form :accessor rule-form :initform nil
              :initarg :rule-form))
  (:documentation
   "A Fuzzy Rule Class.
 A Fuzzy rule is a named linguistic relation in the form of a logical 
 implication: antecedent -> consequent.
 Example Rule: sym = 'r1; antecedent = '(and (x is small) (y is blue)); 
               consequent = 'dry
               Rule 'r1 can only be interpreted in the context of a 
               Fuzzy variable.
               So, if 'z is a Fuzzy variable having 'r1 as a Fuzzy rule 
               then the interpretation is: 
               IF x is small AND y is blue THEN z is dry
               Given numeric values for x and y, Fuzzy arithmetic is 
               used with this rule to determine a numeric value of z."
))


(defclass standard-fuzzy-adj-group (fuzzy-adj-group)
  ((group-adjs :accessor group-adjs 
               :initform nil 
               :initarg :group-adjs))
  (:documentation
   "A Fuzzy Adjective Group Class."
   ))