Skip to content

Commit 89ce26a

Browse files
committed
Uploaded v1.1
1 parent 2a2501b commit 89ce26a

16 files changed

Lines changed: 193 additions & 1677 deletions

File tree

HLearn-algebra/HLearn-algebra.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bug-reports: http://github.com/mikeizbicki/HLearn/issues
1515
Library
1616
Build-Depends:
1717
base >= 3 && < 5,
18-
ConstraintKinds >= 0.1.0,
18+
ConstraintKinds >= 1.1.0,
1919
vector-heterogenous >= 0.1.1,
2020
template-haskell,
2121

@@ -57,9 +57,9 @@ Library
5757
BangPatterns
5858
TypeOperators
5959
GeneralizedNewtypeDeriving
60-
DataKinds
60+
--DataKinds
6161
TypeFamilies
62-
PolyKinds
62+
--PolyKinds
6363
StandaloneDeriving
6464
GADTs
6565
KindSignatures

HLearn-algebra/src/HLearn/Algebra/Models/HomTrainer.hs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ module HLearn.Algebra.Models.HomTrainer
1010
HomTrainer (..)
1111
, WeightedHomTrainer (..)
1212
, NumDP(..)
13+
14+
-- * useful functions
15+
, sub1dp
16+
, subBatch
17+
, sub1dpW
18+
, subBatchW
1319

1420
)
1521
where
@@ -88,6 +94,8 @@ class (Monoid model) => HomTrainer model where
8894
-------------------------------------------------------------------------------
8995
-- WeightedHomTrainer
9096

97+
type WeightedDatapoint model = (Ring model, Datapoint model)
98+
9199
class (Module model, HomTrainer model) =>
92100
WeightedHomTrainer model
93101
where
@@ -99,12 +107,32 @@ class (Module model, HomTrainer model) =>
99107
container (Ring model,Datapoint model) -> model
100108
trainW = batch train1dpW
101109

102-
add1dpW :: model -> (Ring model,Datapoint model) -> model
110+
add1dpW :: model -> WeightedDatapoint model -> model
103111
add1dpW = online $ unbatch $ offline addBatchW
104112

105113
addBatchW :: (Foldable container, Functor container) =>
106-
model -> container (Ring model,Datapoint model) -> model
114+
model -> container (WeightedDatapoint model) -> model
107115
addBatchW = online trainW
108116

109117
instance (Module model, HomTrainer model) => WeightedHomTrainer model
110-
118+
119+
-------------------------------------------------------------------------------
120+
-- helper functions
121+
122+
-- | subtracts a single data point from the model
123+
sub1dp :: (Group model, HomTrainer model) => model -> Datapoint model -> model
124+
sub1dp m dp = m <> inverse (train1dp dp)
125+
126+
-- | subtracts a multiple data point from the model
127+
subBatch :: (Group model, HomTrainer model, Foldable container, Functor container) =>
128+
model -> container (Datapoint model) -> model
129+
subBatch m dpL = m <> inverse (train dpL)
130+
131+
-- | subtracts a single weighted data point from the model
132+
sub1dpW :: (Group model, WeightedHomTrainer model) => model -> WeightedDatapoint model -> model
133+
sub1dpW m dp = m <> inverse (train1dpW dp)
134+
135+
-- | subtracts multiple weighted data points from the model
136+
subBatchW :: (Group model, WeightedHomTrainer model, Foldable container, Functor container) =>
137+
model -> container (WeightedDatapoint model) -> model
138+
subBatchW m dpL = m <> inverse (trainW dpL)

HLearn-algebra/src/HLearn/Algebra/Structures/Free/Bagging.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE DataKinds #-}
2+
13
module HLearn.Algebra.Structures.Free.Bagging
24
( Bagging
35
, Bagging'
@@ -57,4 +59,4 @@ instance
5759
where
5860
n = fromIntegral $ fromSing (sing :: Sing n)
5961
seed = fromIntegral $ fromSing (sing :: Sing seed)
60-
(offset,g) = random $ mkStdGen $ hash dp + seed
62+
(offset,g) = random $ mkStdGen $ hash dp + seed

HLearn-algebra/src/HLearn/Algebra/Structures/Free/FreeHomTrainer.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE EmptyDataDecls #-}
2+
{-# LANGUAGE PolyKinds #-}
23

34
module HLearn.Algebra.Structures.Free.FreeHomTrainer
45
( FreeHomTrainer (..)
@@ -71,4 +72,4 @@ instance
7172

7273
train1dp dp = FreeHomTrainer'
7374
{ modelL = FreeModule $ Map.singleton (lame_train dp) 1
74-
}
75+
}

HLearn-algebra/src/HLearn/Algebra/Types/Indexing.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE DataKinds #-}
12
module HLearn.Algebra.Types.Indexing
23
(
34
Index(..)

HLearn-algebra/src/HLearn/Algebra/Types/Nat1.hs

Lines changed: 1 addition & 1600 deletions
Large diffs are not rendered by default.

HLearn-algebra/src/HLearn/Algebra/Types/Nat1Generator.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ data Nat1 = Zero | Succ Nat1
44

55
decl :: String
66
decl = concat $ map (\x -> x++"\n")
7-
[ "-- | This module was automatically generated by Nat1Generator.hs"
7+
[ "{-# LANGUAGE DataKinds #-}"
8+
, "-- | This module was automatically generated by Nat1Generator.hs"
89
, "module HLearn.Algebra.Types.Nat1 where"
910
, "import GHC.TypeLits"
1011
, "data Nat1Box (n::Nat1) = Nat1Box"
@@ -26,7 +27,7 @@ string_FromNat1 :: Int -> String
2627
string_FromNat1 i = "type instance FromNat1 ("++show (int2Nat1 i)++") = "++show i
2728

2829
numNat :: Int
29-
numNat = 1000
30+
numNat = 200
3031

3132
main = do
3233
putStrLn decl

HLearn-distributions/HLearn-distributions.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ Library
8585
BangPatterns
8686
TypeOperators
8787
GeneralizedNewtypeDeriving
88-
DataKinds
88+
--DataKinds
8989
TypeFamilies
90-
PolyKinds
90+
--PolyKinds
9191
StandaloneDeriving
9292
GADTs
9393
KindSignatures

HLearn-distributions/src/HLearn/Models/Distributions/Multivariate/Internal/CatContainer.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE DataKinds #-}
12
-- | The categorical distribution is used for discrete data. It is also sometimes called the discrete distribution or the multinomial distribution. For more, see the wikipedia entry: <https://en.wikipedia.org/wiki/CatContainer_distribution>
23
module HLearn.Models.Distributions.Multivariate.Internal.CatContainer
34
{- (
@@ -217,4 +218,4 @@ ds= [ "test":::'g':::"foo":::HNil
217218
, "toot":::'f':::"foo":::HNil
218219
]
219220

220-
test = train ds :: CatContainer String (CatContainer Char (CatContainer String (Unital Double) Double) Double) Double
221+
test = train ds :: CatContainer String (CatContainer Char (CatContainer String (Unital Double) Double) Double) Double

HLearn-distributions/src/HLearn/Models/Distributions/Multivariate/Internal/Container.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE PolyKinds #-}
13
module HLearn.Models.Distributions.Multivariate.Internal.Container
24
( Container
35
, MultiContainer

0 commit comments

Comments
 (0)