-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Context Algebra -- -- Context Algebra to identify typical exemplars of a concept influenced -- by a context. A executable model is included in the package -- NearContextAlgebra also available here @package ContextAlgebra @version 0.2.0.1 -- | models a Lattice for a context type, the top of the lattice is -- represented by One and inherits a list of all subcontexts, the bottom -- of the lattice is represented by Zero. To inherit the contextlattice -- to a new data type the data type has to instanciate: Enumerable c, Eq -- c, Ord c, Show c module ContextLattice -- | data type to represent a lattice structure, the actual context is the -- type variable c data Context c -- | constructor represents the One element of the lattice, all contexts -- are included in this constructor, for this constructor the model -- includes all contexts One :: [Context c] -> Context c -- | constructor for one context Ctx :: [c] -> Context c -- | constructor represents the bottom element of the lattice, without any -- context Zero :: Context c -- | takes a context and returns all finer getFinerContexts :: (Eq c, Enumerable c, Enumerable (Context c)) => Context c -> [Context c] -- | extracts a context list of contexts from the element, needed for the -- One wrapper constructor extractContext :: Context c -> [[c]] -- | test for commutativity -- --
--   >>> (Ctx [Walking]) `propCommutative` One [Ctx [Walking],Ctx [Driving],Ctx [Walking,Driving],Ctx [Uphill],Ctx [Walking,Uphill],Ctx [Driving,Uphill],Ctx [Walking,Driving,Uphill]] = (Ctx [Walking]) `meet` One [Ctx [Walking],Ctx [Driving],Ctx [Walking,Driving],Ctx [Uphill],Ctx [Walking,Uphill],Ctx [Driving,Uphill],Ctx [Walking,Driving,Uphill]] == One [Ctx [Walking],Ctx [Driving],Ctx [Walking,Driving],Ctx [Uphill],Ctx [Walking,Uphill],Ctx [Driving,Uphill],Ctx [Walking,Driving,Uphill]] `meet` (Ctx [Walking])
--   true
--   
propCommutative :: (Eq c, Enumerable c, Enumerable (Context c)) => Context c -> Context c -> Bool -- | test for idempotency -- --
--   >>> propIdempotent (Ctx [Walking]) = (Ctx [Walking]) `meet` (Ctx [Walking]) == (Ctx [Walking])
--   true
--   
propIdempotent :: (Eq c, Enumerable c, Enumerable (Context c)) => Context c -> Bool -- | test for associativity -- --
--   >>> propAssociative (Ctx [Walking]) (Ctx [Driving]) (Ctx [Uphill]) =  (Ctx [Walking]) `meet` ((Ctx [Driving]) `meet` (Ctx [Uphill])) == ((Ctx [Walking]) `meet` (Ctx [Driving])) `meet` (Ctx [Uphill])
--   true
--   
propAssociative :: (Eq c, Enumerable c, Enumerable (Context c)) => Context c -> Context c -> Context c -> Bool instance GHC.Classes.Ord c => GHC.Classes.Ord (ContextLattice.Context c) instance GHC.Classes.Eq c => GHC.Classes.Eq (ContextLattice.Context c) instance GHC.Show.Show c => GHC.Show.Show (ContextLattice.Context c) instance (Algebra.Enumerable.Enumerable c, GHC.Classes.Eq c, Algebra.Enumerable.Enumerable (ContextLattice.Context c)) => Algebra.Lattice.MeetSemiLattice (ContextLattice.Context c) -- | This module implements the necessary functions to model a concept -- influenced by several contexts. The concept is represented by several -- exemplars. For each influencing context the exemplars have different -- observation frequency. The connection from exemplars and context is -- modeled by the data type Experience. Each Experience can be made -- several times where the amount is hold by a Multiset. module ConceptModel -- | Each experience is formed by a exemplar of type e and a context c this -- exemplar was observed at. data Experience c e -- | constructor; establishes an experience from a context and an exemplar Exp :: c -> e -> Experience c e -- | All experiences are hold in a multiset type Concept c e = MultiSet (Experience c e) -- | type synonym for better readability type Probability = Float -- | the class defines the necessary functions needed for the context -- algebra class (Ord c, Ord e, Show c, Show e) => ConceptContextModel c e where createConceptForContext context exemplars amounts = unions $ zipWith manyfoldExperiences experiencesOnce amounts where experiencesOnce = map (Exp context) exemplars manyfoldExperiences exp amount = insertMany exp amount empty amountExperiences = size unionsConceptsForDiffContexts = unions filterConceptWithContext context concept = unions . map (\ fctx -> (filter (\ (Exp c1 _) -> c1 == fctx) concept)) $ allfinerContexts where allfinerContexts = getFinerContexts context typicalityofExemplarInContext (Exp context exemplar) concept = if amountContext == 0 then 0 else amountExemplar / amountContext where observationAmounttForContext = amountExperiences experiencesForContext exemplarOservationAmountForContext = amountExperiences $ filterExemplars exemplar experiencesForContext experiencesForContext = filterConceptWithContext context concept amountExemplar = fromIntegral exemplarOservationAmountForContext amountContext = fromIntegral observationAmounttForContext typicalityForExemplarsInContext context exemplar concept = map (\ e -> (e, typicalityofExemplarInContext (Exp context e) concept)) exemplars where exemplars = enumFromTo minBound $ maxBound `asTypeOf` exemplar typicalExemplarInContext context exemplar concept = maximumBy (compare `on` snd) $ typicalityForExemplarsInContext context exemplar concept filterExemplars exemplar = filter (\ (Exp _ actualExemplar) -> exemplar == actualExemplar) printConcept concept = putStrLn $ showTreeWith True True concept addExperience = insert forgetExperience = delete -- | combines the observation amount of exemplars for one context createConceptForContext :: (ConceptContextModel c e, Show c, Ord c, Show e, Ord e) => (Context c) -> [e] -> [Int] -> Concept (Context c) e -- | calculates the amount of experiences that are present for the concept amountExperiences :: ConceptContextModel c e => Concept (Context c) e -> Int -- | unions the experiences stored for one concept for different contexts unionsConceptsForDiffContexts :: (ConceptContextModel c e, Ord e, Ord c) => [Concept (Context c) e] -> Concept (Context c) e -- | filters a concept for a context, gets a concept for a finer context, -- the context c has to be more finer than the context that are included -- in the concept filterConceptWithContext :: (ConceptContextModel c e, Enumerable c, Enumerable (Context c), Ord e, Eq c, Ord c) => Context c -> Concept (Context c) e -> Concept (Context c) e -- | returns the typicality distribution for each exemplar in the context -- c, the type e is only used as type parameter typicalityForExemplarsInContext :: (ConceptContextModel c e, Ord c, Ord e, Enum e, Bounded e, Enumerable c, Enumerable (Context c)) => Context c -> e -> Concept (Context c) e -> [(e, Probability)] -- | returns the typical exemplar of a concept for the context typicalExemplarInContext :: (ConceptContextModel c e, Ord c, Ord e, Enum e, Bounded e, Enumerable c, Enumerable (Context c)) => Context c -> e -> Concept (Context c) e -> (e, Probability) -- | converts the experiences of the concept to a IO() printConcept :: (ConceptContextModel c e, Show e, Show c) => Concept c e -> IO () instance (GHC.Classes.Eq c, GHC.Classes.Eq e) => GHC.Classes.Eq (ConceptModel.Experience c e) instance (GHC.Show.Show c, GHC.Show.Show e) => GHC.Show.Show (ConceptModel.Experience c e) instance (GHC.Classes.Ord c, GHC.Classes.Ord e) => GHC.Classes.Ord (ConceptModel.Experience c e)