mirror of
https://github.com/maciej-bendkowski/generic-boltzmann-brain.git
synced 2024-09-11 12:48:09 +03:00
Check for negative entries in system specification
This commit is contained in:
parent
e7fa5dccb8
commit
6c908da3f9
@ -29,6 +29,7 @@ import Data.Boltzmann.System (
|
|||||||
Types (Types, regTypes),
|
Types (Types, regTypes),
|
||||||
collectTypes,
|
collectTypes,
|
||||||
collectTypes',
|
collectTypes',
|
||||||
|
hasNonNegativeEntries,
|
||||||
hasProperConstructors,
|
hasProperConstructors,
|
||||||
hasProperFrequencies,
|
hasProperFrequencies,
|
||||||
paganiniSpecIO,
|
paganiniSpecIO,
|
||||||
@ -184,6 +185,7 @@ mkSystemCtx sys = do
|
|||||||
|
|
||||||
hasProperConstructors sys'
|
hasProperConstructors sys'
|
||||||
hasProperFrequencies sys'
|
hasProperFrequencies sys'
|
||||||
|
hasNonNegativeEntries sys'
|
||||||
|
|
||||||
types <- collectTypes sys'
|
types <- collectTypes sys'
|
||||||
distributions <- runIO $ do
|
distributions <- runIO $ do
|
||||||
|
@ -19,6 +19,7 @@ module Data.Boltzmann.System (
|
|||||||
paganiniSpecIO,
|
paganiniSpecIO,
|
||||||
hasProperConstructors,
|
hasProperConstructors,
|
||||||
hasProperFrequencies,
|
hasProperFrequencies,
|
||||||
|
hasNonNegativeEntries,
|
||||||
Constructable (..),
|
Constructable (..),
|
||||||
) where
|
) where
|
||||||
|
|
||||||
@ -230,6 +231,33 @@ hasProperFrequencies sys = do
|
|||||||
"Frequencies definied for non-system constructors: "
|
"Frequencies definied for non-system constructors: "
|
||||||
++ format additionalConstrs
|
++ format additionalConstrs
|
||||||
|
|
||||||
|
hasNonNegativeEntries :: System -> Q ()
|
||||||
|
hasNonNegativeEntries sys = do
|
||||||
|
unless (meanSize sys >= 0) $ do
|
||||||
|
fail "Negative mean target size"
|
||||||
|
|
||||||
|
let negativeWeights =
|
||||||
|
filter
|
||||||
|
(\(_, w) -> w < 0)
|
||||||
|
(unConstructorWeights $ weights sys)
|
||||||
|
|
||||||
|
unless (null negativeWeights) $ do
|
||||||
|
fail $
|
||||||
|
"Negative weight for constructors: "
|
||||||
|
++ format (Set.fromList $ map fst negativeWeights)
|
||||||
|
|
||||||
|
let negativeFrequencies =
|
||||||
|
filter
|
||||||
|
(\(_, w) -> w < 0)
|
||||||
|
(unConstructorFrequencies $ frequencies sys)
|
||||||
|
|
||||||
|
unless (null negativeFrequencies) $ do
|
||||||
|
fail $
|
||||||
|
"Negative frequencies for constructors: "
|
||||||
|
++ format (Set.fromList $ map fst negativeFrequencies)
|
||||||
|
|
||||||
|
pure ()
|
||||||
|
|
||||||
mkVariables :: Set Name -> Spec (Map Name Let)
|
mkVariables :: Set Name -> Spec (Map Name Let)
|
||||||
mkVariables sys = do
|
mkVariables sys = do
|
||||||
let n = Set.size sys
|
let n = Set.size sys
|
||||||
|
Loading…
Reference in New Issue
Block a user