{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# OPTIONS_GHC -Wall #-}
module ConCat.Regress where
import Data.Key (Zip(..))
import ConCat.Misc ((:*))
import ConCat.AltCat (Ok)
import qualified ConCat.Free.VectorSpace as V
import ConCat.Free.VectorSpace hiding ((^+^),distSqr)
import ConCat.Free.LinearRow
sqErrF :: forall s a g. (Num s, Foldable g, Zip g)
=> (a -> g s) -> a :* g s -> s
sqErrF :: forall s a (g :: * -> *).
(Num s, Foldable g, Zip g) =>
(a -> g s) -> (a :* g s) -> s
sqErrF a -> g s
h (a
x,g s
y) = a -> g s
h a
x g s -> g s -> s
forall s (f :: * -> *).
(Zip f, Foldable f, Num s) =>
f s -> f s -> s
`V.distSqr` g s
y
{-# INLINE sqErrF #-}
sqErr :: forall s a b. Ok (L s) b => (a -> b) -> a :* b -> s
sqErr :: forall s a b. Ok (L s) b => (a -> b) -> (a :* b) -> s
sqErr a -> b
h (a
x,b
y) = a -> b
h a
x b -> b -> s
forall s a.
(HasV s a, Zip (V s a), Foldable (V s a), Num s) =>
a -> a -> s
`distSqr` b
y
{-# INLINE sqErr #-}
distSqr :: forall s a. (HasV s a, Zip (V s a), Foldable (V s a), Num s)
=> a -> a -> s
distSqr :: forall s a.
(HasV s a, Zip (V s a), Foldable (V s a), Num s) =>
a -> a -> s
distSqr a
a a
b = V s a s -> V s a s -> s
forall s (f :: * -> *).
(Zip f, Foldable f, Num s) =>
f s -> f s -> s
V.distSqr (a -> V s a s
forall s a. HasV s a => a -> V s a s
toV a
a) (a -> V s a s
forall s a. HasV s a => a -> V s a s
toV a
b)
{-# INLINE distSqr #-}