diff options
-rw-r--r-- | lib/Numeric/Container.hs | 16 | ||||
-rw-r--r-- | lib/Numeric/LinearAlgebra/Real.hs | 31 |
2 files changed, 20 insertions, 27 deletions
diff --git a/lib/Numeric/Container.hs b/lib/Numeric/Container.hs index eded19c..661e5b4 100644 --- a/lib/Numeric/Container.hs +++ b/lib/Numeric/Container.hs | |||
@@ -36,7 +36,7 @@ module Numeric.Container ( | |||
36 | -- * Matrix product | 36 | -- * Matrix product |
37 | Product(..), | 37 | Product(..), |
38 | optimiseMult, | 38 | optimiseMult, |
39 | mXm,mXv,vXm,(<.>),Mul(..),(<\>), | 39 | mXm,mXv,vXm,(<.>),Mul(..),LSDiv(..), |
40 | outer, kronecker, | 40 | outer, kronecker, |
41 | -- * Random numbers | 41 | -- * Random numbers |
42 | RandDist(..), | 42 | RandDist(..), |
@@ -120,9 +120,15 @@ instance Mul Vector Matrix Vector where | |||
120 | 120 | ||
121 | -------------------------------------------------------- | 121 | -------------------------------------------------------- |
122 | 122 | ||
123 | -- | least squares solution of a linear system, similar to the \\ operator of Matlab\/Octave (based on linearSolveSVD). | 123 | class LSDiv b c | b -> c, c->b where |
124 | (<\>) :: (Field a) => Matrix a -> Vector a -> Vector a | 124 | infixl 7 <\> |
125 | infixl 7 <\> | 125 | -- | least squares solution of a linear system, similar to the \\ operator of Matlab\/Octave (based on linearSolveSVD) |
126 | m <\> v = flatten (linearSolveSVD m (reshape 1 v)) | 126 | (<\>) :: Field t => Matrix t -> b t -> c t |
127 | |||
128 | instance LSDiv Vector Vector where | ||
129 | m <\> v = flatten (linearSolveSVD m (reshape 1 v)) | ||
130 | |||
131 | instance LSDiv Matrix Matrix where | ||
132 | (<\>) = linearSolveSVD | ||
127 | 133 | ||
128 | -------------------------------------------------------- | 134 | -------------------------------------------------------- |
diff --git a/lib/Numeric/LinearAlgebra/Real.hs b/lib/Numeric/LinearAlgebra/Real.hs index 6cba045..08a218c 100644 --- a/lib/Numeric/LinearAlgebra/Real.hs +++ b/lib/Numeric/LinearAlgebra/Real.hs | |||
@@ -13,7 +13,7 @@ Additional functions for real arrays. | |||
13 | ----------------------------------------------------------------------------- | 13 | ----------------------------------------------------------------------------- |
14 | 14 | ||
15 | module Numeric.LinearAlgebra.Real( | 15 | module Numeric.LinearAlgebra.Real( |
16 | (<>), (*>), (<*), (<\>), (\>), | 16 | (<>), (<\>), |
17 | vector, | 17 | vector, |
18 | linspace, | 18 | linspace, |
19 | eye, | 19 | eye, |
@@ -22,7 +22,8 @@ module Numeric.LinearAlgebra.Real( | |||
22 | row, | 22 | row, |
23 | col, | 23 | col, |
24 | (#),(&), (//), blocks, | 24 | (#),(&), (//), blocks, |
25 | rand, randn | 25 | rand, randn, |
26 | module Numeric.LinearAlgebra | ||
26 | ) where | 27 | ) where |
27 | 28 | ||
28 | import Numeric.LinearAlgebra hiding ((<>), (<\>), linspace) | 29 | import Numeric.LinearAlgebra hiding ((<>), (<\>), linspace) |
@@ -34,30 +35,16 @@ linspace = LA.linspace | |||
34 | 35 | ||
35 | 36 | ||
36 | infixl 7 <> | 37 | infixl 7 <> |
37 | -- | Matrix product ('multiply') | 38 | -- | Matrix product |
38 | (<>) :: Field t => Matrix t -> Matrix t -> Matrix t | 39 | (<>) ::Mul a b c => a Double -> b Double -> c Double |
39 | (<>) = multiply | 40 | (<>) = (LA.<>) |
40 | 41 | ||
41 | infixl 7 *> | ||
42 | -- | matrix x vector | ||
43 | (*>) :: Field t => Matrix t -> Vector t -> Vector t | ||
44 | m *> v = flatten $ m <> (asColumn v) | ||
45 | 42 | ||
46 | infixl 7 <* | ||
47 | -- | vector x matrix | ||
48 | (<*) :: Field t => Vector t -> Matrix t -> Vector t | ||
49 | v <* m = flatten $ (asRow v) <> m | ||
50 | |||
51 | |||
52 | -- | Least squares solution of a linear system for several right-hand sides, similar to the \\ operator of Matlab\/Octave. (\<\\\>) = 'linearSolveSVD'. | ||
53 | (<\>) :: (Field a) => Matrix a -> Matrix a -> Matrix a | ||
54 | infixl 7 <\> | 43 | infixl 7 <\> |
55 | (<\>) = linearSolveSVD | 44 | -- | Least squares solution of a linear system |
45 | (<\>) ::LSDiv b c => Matrix Double -> b Double -> c Double | ||
46 | (<\>) = (LA.<\>) | ||
56 | 47 | ||
57 | -- | Least squares solution of a linear system for a single right-hand side. See '(\<\\\>)'. | ||
58 | (\>) :: (Field a) => Matrix a -> Vector a -> Vector a | ||
59 | infixl 7 \> | ||
60 | m \> v = flatten (m <\> reshape 1 v) | ||
61 | 48 | ||
62 | -- | Pseudorandom matrix with uniform elements between 0 and 1. | 49 | -- | Pseudorandom matrix with uniform elements between 0 and 1. |
63 | randm :: RandDist | 50 | randm :: RandDist |