vector-space-map-0.2.0: vector-space operations for finite maps using Data.Map

Safe HaskellNone
LanguageHaskell98

Data.Map.Vector

Synopsis

Documentation

data MapVector k v Source

Note: <*> in the Applicative instance operates under intersection. i.e.:

>>> (MapVector $ Map.fromList [("x", id)]) <*> (MapVector $ Map.fromList [("y", 3)])
MapVector (fromList [])

Use the Applicative instance for elementwise operations:

>>> liftA2 (*) (MapVector $ Map.fromList [("x", 2), ("y", 3)]) (MapVector $ Map.fromList [("x", 5),("y", 7)])
MapVector (fromList [("x",10),("y",21)])
>>> liftA2 (*) (MapVector $ Map.fromList [("x", 2), ("y", 3)]) (MapVector $ Map.fromList [("y", 7)])
MapVector (fromList [("y",21)])

*^ in the VectorSpace instance multiplies by the scalar of v. Nesting MapVectors preserves the scalar type, e.g. Scalar (MapVector k (MapVector k' v)) = Scalar v.

>>> 2 *^ (ConstantMap $ MapVector $ Map.fromList [("x", 3 :: Int), ("y", 5)])
ConstantMap (MapVector (fromList [("x",6),("y",10)]))

Finally, <.> in InnerSpace is the dot-product operator. Again, it operates under intersection.

>>> (MapVector $ Map.fromList [("x", 2 :: Int), ("y", 3)]) <.> (MapVector $ Map.fromList [("x", 5),("y", 7)])
31
>>> (pure . MapVector $ Map.fromList [("x", 2 :: Int), ("y", 3)]) <.> (MapVector $ Map.fromList [("a", pure (5::Int))])
25

Addition with ^+^ operates under union.

Constructors

MapVector (Map k v) 
ConstantMap v

An infinite-dimensional vector with the same value on all dimensions

Instances