diff options
author | Alberto Ruiz <aruiz@um.es> | 2016-10-19 18:30:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-19 18:30:56 +0200 |
commit | b32b37472559f202995e894f9a627871737d4619 (patch) | |
tree | ceeee656f08e71b4ad0a577a9099cd6242f873a9 /packages | |
parent | ade49c7eca844303a85a709642905a84665698c5 (diff) | |
parent | d1dcad5765bcb166a8890d67da9f631632f43149 (diff) |
Merge pull request #208 from mstksg/static
[Static] constrained meanCov to require at least one input vector, added matrix inverse to Domain
Diffstat (limited to 'packages')
-rw-r--r-- | packages/base/src/Numeric/LinearAlgebra/Static.hs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/packages/base/src/Numeric/LinearAlgebra/Static.hs b/packages/base/src/Numeric/LinearAlgebra/Static.hs index 296f8c7..8175ff5 100644 --- a/packages/base/src/Numeric/LinearAlgebra/Static.hs +++ b/packages/base/src/Numeric/LinearAlgebra/Static.hs | |||
@@ -79,7 +79,7 @@ import Internal.Static | |||
79 | import Control.Arrow((***)) | 79 | import Control.Arrow((***)) |
80 | import Text.Printf | 80 | import Text.Printf |
81 | import Data.Type.Equality ((:~:)(Refl)) | 81 | import Data.Type.Equality ((:~:)(Refl)) |
82 | import Data.Bifunctor (first) | 82 | import qualified Data.Bifunctor as BF (first) |
83 | 83 | ||
84 | ud1 :: R n -> Vector ℝ | 84 | ud1 :: R n -> Vector ℝ |
85 | ud1 (R (Dim v)) = v | 85 | ud1 (R (Dim v)) = v |
@@ -517,7 +517,7 @@ uniformSample s (extract -> mins) (extract -> maxs) = | |||
517 | (zip (LA.toList mins) (LA.toList maxs)) | 517 | (zip (LA.toList mins) (LA.toList maxs)) |
518 | 518 | ||
519 | meanCov | 519 | meanCov |
520 | :: forall m n . (KnownNat m, KnownNat n) | 520 | :: forall m n . (KnownNat m, KnownNat n, 1 <= m) |
521 | => L m n | 521 | => L m n |
522 | -> (R n, Sym n) | 522 | -> (R n, Sym n) |
523 | meanCov (extract -> vs) = mkR *** (Sym . mkL . LA.unSym) $ LA.meanCov vs | 523 | meanCov (extract -> vs) = mkR *** (Sym . mkL . LA.unSym) $ LA.meanCov vs |
@@ -539,6 +539,7 @@ class Domain field vec mat | mat -> vec field, vec -> mat field, field -> mat ve | |||
539 | invlndet :: forall n. KnownNat n => mat n n -> (mat n n, (field, field)) | 539 | invlndet :: forall n. KnownNat n => mat n n -> (mat n n, (field, field)) |
540 | expm :: forall n. KnownNat n => mat n n -> mat n n | 540 | expm :: forall n. KnownNat n => mat n n -> mat n n |
541 | sqrtm :: forall n. KnownNat n => mat n n -> mat n n | 541 | sqrtm :: forall n. KnownNat n => mat n n -> mat n n |
542 | inv :: forall n. KnownNat n => mat n n -> mat n n | ||
542 | 543 | ||
543 | 544 | ||
544 | instance Domain ℝ R L | 545 | instance Domain ℝ R L |
@@ -556,6 +557,7 @@ instance Domain ℝ R L | |||
556 | invlndet = invlndetL | 557 | invlndet = invlndetL |
557 | expm = expmL | 558 | expm = expmL |
558 | sqrtm = sqrtmL | 559 | sqrtm = sqrtmL |
560 | inv = invL | ||
559 | 561 | ||
560 | instance Domain ℂ C M | 562 | instance Domain ℂ C M |
561 | where | 563 | where |
@@ -572,6 +574,7 @@ instance Domain ℂ C M | |||
572 | invlndet = invlndetM | 574 | invlndet = invlndetM |
573 | expm = expmM | 575 | expm = expmM |
574 | sqrtm = sqrtmM | 576 | sqrtm = sqrtmM |
577 | inv = invM | ||
575 | 578 | ||
576 | -------------------------------------------------------------------------------- | 579 | -------------------------------------------------------------------------------- |
577 | 580 | ||
@@ -627,7 +630,7 @@ detL :: KnownNat n => Sq n -> ℝ | |||
627 | detL = LA.det . unwrap | 630 | detL = LA.det . unwrap |
628 | 631 | ||
629 | invlndetL :: KnownNat n => Sq n -> (L n n, (ℝ, ℝ)) | 632 | invlndetL :: KnownNat n => Sq n -> (L n n, (ℝ, ℝ)) |
630 | invlndetL = first mkL . LA.invlndet . unwrap | 633 | invlndetL = BF.first mkL . LA.invlndet . unwrap |
631 | 634 | ||
632 | expmL :: KnownNat n => Sq n -> Sq n | 635 | expmL :: KnownNat n => Sq n -> Sq n |
633 | expmL = overMatL' LA.expm | 636 | expmL = overMatL' LA.expm |
@@ -635,6 +638,9 @@ expmL = overMatL' LA.expm | |||
635 | sqrtmL :: KnownNat n => Sq n -> Sq n | 638 | sqrtmL :: KnownNat n => Sq n -> Sq n |
636 | sqrtmL = overMatL' LA.sqrtm | 639 | sqrtmL = overMatL' LA.sqrtm |
637 | 640 | ||
641 | invL :: KnownNat n => Sq n -> Sq n | ||
642 | invL = overMatL' LA.inv | ||
643 | |||
638 | -------------------------------------------------------------------------------- | 644 | -------------------------------------------------------------------------------- |
639 | 645 | ||
640 | mulC :: forall m k n. (KnownNat m, KnownNat k, KnownNat n) => M m k -> M k n -> M m n | 646 | mulC :: forall m k n. (KnownNat m, KnownNat k, KnownNat n) => M m k -> M k n -> M m n |
@@ -689,7 +695,7 @@ detM :: KnownNat n => M n n -> ℂ | |||
689 | detM = LA.det . unwrap | 695 | detM = LA.det . unwrap |
690 | 696 | ||
691 | invlndetM :: KnownNat n => M n n -> (M n n, (ℂ, ℂ)) | 697 | invlndetM :: KnownNat n => M n n -> (M n n, (ℂ, ℂ)) |
692 | invlndetM = first mkM . LA.invlndet . unwrap | 698 | invlndetM = BF.first mkM . LA.invlndet . unwrap |
693 | 699 | ||
694 | expmM :: KnownNat n => M n n -> M n n | 700 | expmM :: KnownNat n => M n n -> M n n |
695 | expmM = overMatM' LA.expm | 701 | expmM = overMatM' LA.expm |
@@ -697,6 +703,8 @@ expmM = overMatM' LA.expm | |||
697 | sqrtmM :: KnownNat n => M n n -> M n n | 703 | sqrtmM :: KnownNat n => M n n -> M n n |
698 | sqrtmM = overMatM' LA.sqrtm | 704 | sqrtmM = overMatM' LA.sqrtm |
699 | 705 | ||
706 | invM :: KnownNat n => M n n -> M n n | ||
707 | invM = overMatM' LA.inv | ||
700 | 708 | ||
701 | -------------------------------------------------------------------------------- | 709 | -------------------------------------------------------------------------------- |
702 | 710 | ||