mirror of
https://github.com/maciej-bendkowski/generic-boltzmann-brain.git
synced 2024-08-17 08:30:30 +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),
|
||||
collectTypes,
|
||||
collectTypes',
|
||||
hasNonNegativeEntries,
|
||||
hasProperConstructors,
|
||||
hasProperFrequencies,
|
||||
paganiniSpecIO,
|
||||
@ -184,6 +185,7 @@ mkSystemCtx sys = do
|
||||
|
||||
hasProperConstructors sys'
|
||||
hasProperFrequencies sys'
|
||||
hasNonNegativeEntries sys'
|
||||
|
||||
types <- collectTypes sys'
|
||||
distributions <- runIO $ do
|
||||
|
@ -19,6 +19,7 @@ module Data.Boltzmann.System (
|
||||
paganiniSpecIO,
|
||||
hasProperConstructors,
|
||||
hasProperFrequencies,
|
||||
hasNonNegativeEntries,
|
||||
Constructable (..),
|
||||
) where
|
||||
|
||||
@ -230,6 +231,33 @@ hasProperFrequencies sys = do
|
||||
"Frequencies definied for non-system constructors: "
|
||||
++ 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 sys = do
|
||||
let n = Set.size sys
|
||||
|
Loading…
Reference in New Issue
Block a user