module Numeric.MaxEnt.General (
Constraint,
general
) where
import Numeric.Optimization.Algorithms.HagerZhang05
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Storable as S
import Numeric.AD
import GHC.IO (unsafePerformIO)
import Data.Traversable
import Numeric.AD.Types
import Numeric.AD.Internal.Tower
import Numeric.AD.Internal.Classes
import Data.List (transpose)
import Control.Applicative
import Numeric.AD.Lagrangian
entropy :: Floating a => [a] -> a
entropy xs = negate . sum . map (\x -> x * log x) $ xs
general :: Double
-> Int
-> [Constraint Double]
-> Either (Result, Statistics) (S.Vector Double)
general tolerance count constraints =
fst <$> maximize tolerance entropy ((sum <=> 1.0) : constraints) count