huzzy 0.1.5.0 → 0.1.5.5
raw patch · 7 files changed
+42/−27 lines, 7 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Huzzy.Base.Sets: instance Num (MF a)
+ Huzzy.TypeOne.Sets: instance Num (T1Set a)
Files
- huzzy.cabal +3/−3
- src/Huzzy/Analysis/Graph.hs +0/−10
- src/Huzzy/Base/Sets.hs +15/−5
- src/Huzzy/Base/Systems.hs +11/−6
- src/Huzzy/TypeOne/Sets.hs +11/−0
- src/Huzzy/TypeOne/Systems.hs +2/−2
- src/Huzzy/TypeTwo/ZSlices/Systems.hs +0/−1
huzzy.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: huzzy-version: 0.1.5.0+version: 0.1.5.5 synopsis: Fuzzy logic library with support for T1, IT2, GT2. description: Library for creating fuzzy sets and systems.@@ -31,8 +31,8 @@ Huzzy.TypeTwo.ZSlices.Sets, Huzzy.TypeTwo.ZSlices.Systems, Huzzy.TypeTwo.Interval.Sets,- Huzzy.TypeTwo.Interval.Systems,- Huzzy.Analysis.Graph+ Huzzy.TypeTwo.Interval.Systems+ --other-modules: -- other-extensions:
− src/Huzzy/Analysis/Graph.hs
@@ -1,10 +0,0 @@-module Huzzy.Analysis.Graph where--import Graphics.EasyPlot-import Huzzy.Base.Sets-import Huzzy.TypeOne.Sets-import Huzzy.TypeTwo.Interval.Sets-import Huzzy.TypeTwo.ZSlices.Sets----plotContT1 :: [a] -> T1Set a -> IO Bool---plotContT1
src/Huzzy/Base/Sets.hs view
@@ -30,6 +30,8 @@ -- | FuzOp is used to denote functions expecting operators on fuzzy sets. type FuzOp a = a -> a -> a +infixr 3 ?&&+infixr 2 ?|| -- | Standard operations on fuzzy sets. -- Instantiated for each kind of fuzzy set. -- If you want to overload with a t-norm, instantiate against a newtype or instantiated set.@@ -68,6 +70,14 @@ (a ,b) ?|| (c, d) = (a ?|| c, b ?|| d) fnot (a, b) = (fnot a, fnot b) +instance Num (MF a) where+ (MF f) + (MF g) = MF (\x -> f x + g x)+ (MF f) * (MF g) = MF (\x -> f x * g x)+ (MF f) - (MF g) = MF (\x -> f x - g x)+ abs (MF f) = MF (\x -> abs (f x))+ signum (MF f) = MF (\x -> signum (f x))+ fromInteger n = MF (\x -> fromInteger n)+ -- | Specifically for fuzzy sets, as opposed to fuzzy values. -- Support is all elements of domain for which membership is non-zero. -- Hedge is a modifier of fuzzy sets.@@ -91,9 +101,6 @@ is :: b -> a -> d -} -tNo :: Fuzzy a => FuzOp a -> a -> a -> a-tNo op = op- -- | Produces the dual t-conorm from a t-norm tCo :: (Num a, Fuzzy a) => FuzOp a -> a -> a -> a tCo tNo a b = (-) 1 $ tNo (1 - a) (1 - b)@@ -192,13 +199,16 @@ gaus sig c = MF (\x -> gaus' sig c x) gaus' :: Double -> Double -> MF' Double-gaus' sig c x = let e = exp 1 in e**((-0.5*(x-c/sig))**2)+gaus' sig c x = let e = exp 1 in e**(top/bottom)+ where+ top = negate $ (x-c)**2+ bottom = 2*(sig**2) bell :: Double -> Double -> Double -> MF Double bell a b c = MF (\x -> bell' a b c x) bell' :: Double -> Double -> Double -> MF' Double-bell' a b c x = 1/(1+abs ((x-c/a)**2*b))+bell' a b c x = 1/(1+abs (((x-c)/a)**(2*b))) sig :: Double -> Double -> MF Double sig a c = MF (\x -> sig' a c x)
src/Huzzy/Base/Systems.hs view
@@ -5,6 +5,9 @@ import Huzzy.Base.Sets +infix 0 =*>+infix 0 =|>+ -- | Allows overloading of functions used in rule definition. class Fuzzy a => FRule a where -- | Firing strength@@ -18,20 +21,20 @@ instance FRule Double where type Antecedent Double = Double- (=*>) a b = a * b- (=|>) a b = a `min` b+ (=*>) a b = a * b+ (=|>) a b = a `min` b weight a b = a * b instance FRule b => FRule (a -> b) where type Antecedent (a -> b) = Antecedent b- (=*>) a b = \x -> a =*> b x- (=|>) a b = \x -> a =|> b x+ (=*>) a b = \x -> a =*> b x+ (=|>) a b = \x -> a =|> b x weight a b = \x -> a x `weight` b instance FRule (MF a) where type Antecedent (MF a) = Double- (=*>) a (MF f) = MF (\x -> a =*> f x)- (=|>) a (MF f) = MF (\x -> a =|> f x)+ (=*>) a (MF f) = MF (\x -> a =*> f x)+ (=|>) a (MF f) = MF (\x -> a =|> f x) weight (MF f) b = MF (\x -> f x `weight` b) -- | Overloaded defuzzification functions.@@ -39,3 +42,5 @@ type Result a centroid :: a -> Result a +ruleBase :: Fuzzy a => (a -> a -> a) -> [a] -> a+ruleBase = foldr1
src/Huzzy/TypeOne/Sets.hs view
@@ -62,6 +62,16 @@ (MF f) = mf s -} +instance Num (T1Set a) where+ a + b = a { mf = (mf a) + (mf b)}+ a * b = a { mf = (mf a) * (mf b)}+ a - b = a { mf = (mf a) * (mf b)}+ abs a = a { mf = abs (mf a)}+ signum a = a {mf = signum (mf a)}+ fromInteger n = T1S { mf = MF $ \x -> fromInteger n+ , dom = [] }++ -- | Smart constructor for continuous membership functions. Warning, fine resolutions will make this a very slow construction. contT1 :: (Num a, Enum a) => a -> a -> a -> MF a -> T1Set a contT1 minB maxB res (MF mf) = case check of@@ -103,3 +113,4 @@ l = maximum as li = fromJust $ elemIndex l as r = maximum (snd $ splitAt li as)+
src/Huzzy/TypeOne/Systems.hs view
@@ -11,8 +11,8 @@ instance FRule (T1Set a) where -- | Firing strength of Type-1 rules is just membership grade. type Antecedent (T1Set a) = Double- (=*>) a t1s = t1s { mf = a =*> (mf t1s)}- (=|>) a t1s = t1s { mf = a =|> (mf t1s)}+ (=*>) a t1s = t1s { mf = a =*> (mf t1s)}+ (=|>) a t1s = t1s { mf = a =|> (mf t1s)} weight t1s b = t1s {mf = (mf t1s) `weight` b} instance Defuzzifier (T1Set Double) where
src/Huzzy/TypeTwo/ZSlices/Systems.hs view
@@ -28,5 +28,4 @@ (ldom, rdom) = unzip $ support (head its) (ls, us) = unzip $ map centroid its zs = zLevelAxis (length its)- -- todo dirty hack to ensure max is returned disPairs = sortBy (flip compare `on` snd ) $ zip ls zs ++ zip us zs