cmaes 0.2.2.1 → 0.2.3
raw patch · 2 files changed
+44/−36 lines, 2 filesdep +QuickCheckdep −doctest-propdep ~doctestnew-uploaderPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: QuickCheck
Dependencies removed: doctest-prop
Dependency ranges changed: doctest
API changes (from Hackage documentation)
- Numeric.Optimization.Algorithms.CMAES: cmaesWrapperPath :: Config tgt -> Maybe FilePath
- Numeric.Optimization.Algorithms.CMAES: embedding :: Config tgt -> [Double] -> tgt
- Numeric.Optimization.Algorithms.CMAES: funcIO :: Config tgt -> tgt -> IO Double
- Numeric.Optimization.Algorithms.CMAES: initXs :: Config tgt -> [Double]
- Numeric.Optimization.Algorithms.CMAES: noiseEps :: Config tgt -> Maybe Double
- Numeric.Optimization.Algorithms.CMAES: noiseHandling :: Config tgt -> Bool
- Numeric.Optimization.Algorithms.CMAES: noiseReEvals :: Config tgt -> Maybe Int
- Numeric.Optimization.Algorithms.CMAES: otherArgs :: Config tgt -> [(String, String)]
- Numeric.Optimization.Algorithms.CMAES: projection :: Config tgt -> tgt -> [Double]
- Numeric.Optimization.Algorithms.CMAES: pythonPath :: Config tgt -> Maybe FilePath
- Numeric.Optimization.Algorithms.CMAES: scaling :: Config tgt -> Maybe [Double]
- Numeric.Optimization.Algorithms.CMAES: sigma0 :: Config tgt -> Double
- Numeric.Optimization.Algorithms.CMAES: tolFacUpX :: Config tgt -> Maybe Double
- Numeric.Optimization.Algorithms.CMAES: tolFun :: Config tgt -> Maybe Double
- Numeric.Optimization.Algorithms.CMAES: tolStagnation :: Config tgt -> Maybe Int
- Numeric.Optimization.Algorithms.CMAES: tolUpSigma :: Config tgt -> Maybe Double
- Numeric.Optimization.Algorithms.CMAES: tolX :: Config tgt -> Maybe Double
- Numeric.Optimization.Algorithms.CMAES: typicalXs :: Config tgt -> Maybe [Double]
- Numeric.Optimization.Algorithms.CMAES: verbose :: Config tgt -> Bool
+ Numeric.Optimization.Algorithms.CMAES: [cmaesWrapperPath] :: Config tgt -> Maybe FilePath
+ Numeric.Optimization.Algorithms.CMAES: [embedding] :: Config tgt -> [Double] -> tgt
+ Numeric.Optimization.Algorithms.CMAES: [funcIO] :: Config tgt -> tgt -> IO Double
+ Numeric.Optimization.Algorithms.CMAES: [initXs] :: Config tgt -> [Double]
+ Numeric.Optimization.Algorithms.CMAES: [noiseEps] :: Config tgt -> Maybe Double
+ Numeric.Optimization.Algorithms.CMAES: [noiseHandling] :: Config tgt -> Bool
+ Numeric.Optimization.Algorithms.CMAES: [noiseReEvals] :: Config tgt -> Maybe Int
+ Numeric.Optimization.Algorithms.CMAES: [otherArgs] :: Config tgt -> [(String, String)]
+ Numeric.Optimization.Algorithms.CMAES: [projection] :: Config tgt -> tgt -> [Double]
+ Numeric.Optimization.Algorithms.CMAES: [pythonPath] :: Config tgt -> Maybe FilePath
+ Numeric.Optimization.Algorithms.CMAES: [scaling] :: Config tgt -> Maybe [Double]
+ Numeric.Optimization.Algorithms.CMAES: [sigma0] :: Config tgt -> Double
+ Numeric.Optimization.Algorithms.CMAES: [tolFacUpX] :: Config tgt -> Maybe Double
+ Numeric.Optimization.Algorithms.CMAES: [tolFun] :: Config tgt -> Maybe Double
+ Numeric.Optimization.Algorithms.CMAES: [tolStagnation] :: Config tgt -> Maybe Int
+ Numeric.Optimization.Algorithms.CMAES: [tolUpSigma] :: Config tgt -> Maybe Double
+ Numeric.Optimization.Algorithms.CMAES: [tolX] :: Config tgt -> Maybe Double
+ Numeric.Optimization.Algorithms.CMAES: [typicalXs] :: Config tgt -> Maybe [Double]
+ Numeric.Optimization.Algorithms.CMAES: [verbose] :: Config tgt -> Bool
- Numeric.Optimization.Algorithms.CMAES: run :: Config tgt -> IO tgt
+ Numeric.Optimization.Algorithms.CMAES: run :: forall tgt. Config tgt -> IO tgt
Files
- Numeric/Optimization/Algorithms/CMAES.hs +35/−30
- cmaes.cabal +9/−6
Numeric/Optimization/Algorithms/CMAES.hs view
@@ -1,4 +1,5 @@-{-# LANGUAGE FlexibleContexts, PackageImports, RankNTypes, RecordWildCards,ScopedTypeVariables #-}+{-# LANGUAGE PackageImports, RankNTypes, RecordWildCards,+ ScopedTypeVariables, FlexibleContexts #-} {-# OPTIONS -Wall #-} @@ -14,11 +15,11 @@ Let's optimize the following function /f(xs)/. @xs@ is a list of Double and @f@ has its minimum at @xs !! i = sqrt(i)@. ->>> import Test.DocTest.Prop >>> let f = sum . zipWith (\i x -> (x*abs x - i)**2) [0..] :: [Double] -> Double >>> let initXs = replicate 10 0 :: [Double] >>> bestXs <- run $ minimize f initXs->>> assert $ f bestXs < 1e-10+>>> f bestXs < 1e-10+True If your optimization is not working well, try: @@ -32,7 +33,8 @@ >>> let f2 xs = (/1e100) $ sum $ zipWith (\i x -> (x*abs x - i)**2) [0..] xs >>> bestXs <- run $ (minimize f2 $ replicate 10 0) {tolFun = Just 1e-111}->>> assert $ f2 bestXs < 1e-110+>>> f2 bestXs < 1e-110+True An example for scaling the input values: @@ -40,7 +42,8 @@ >>> let xs30 = replicate 10 0 :: [Double] >>> let m3 = (minimize f3 xs30) {scaling = Just (repeat 1e50)} >>> xs31 <- run $ m3->>> assert $ f3 xs31 / f3 xs30 < 1e-10+>>> f3 xs31 / f3 xs30 < 1e-10+True Use `minimizeT` to optimize functions on traversable structures. @@ -48,9 +51,10 @@ >>> let f4 = V.sum . V.imap (\i x -> (x*abs x - fromIntegral i)**2) >>> :t f4-f4 :: V.Vector Double -> Double+f4 :: Floating c => V.Vector c -> c >>> bestVx <- run $ minimizeT f4 $ V.replicate 10 0->>> assert $ f4 bestVx < 1e-10+>>> f4 bestVx < 1e-10+True Or use `minimizeG` to optimize functions of any type that is Data and that contains `Double`s. Here is an example that deal with@@ -69,12 +73,14 @@ >>> :t f5 f5 :: Triangle -> Double >>> bestTriangle <- run $ (minimizeG f5 triangle0){tolFun = Just 1e-20}->>> assert $ f5 bestTriangle < 1e-10+>>> f5 bestTriangle < 1e-10+True Then the angle BAC should be orthogonal. >>> let (Triangle (Pt ax ay) (Pt bx by) (Pt cx cy)) = bestTriangle->>> assert $ abs ((bx-ax)*(cx-ax) + (by-ay)*(cy-ay)) < 1e-10+>>> abs ((bx-ax)*(cx-ax) + (by-ay)*(cy-ay)) < 1e-10+True When optimizing noisy functions, set `noiseHandling` = @True@ (and@@ -85,7 +91,7 @@ >>> let f6Pure = sum . zipWith (\i x -> (x*abs x - i)**2) [0..] >>> let f6 xs = fmap (f6Pure xs +) noise >>> :t f6-f6 :: [Double] -> IO Double+f6 :: (Floating b, Enum b, Random b) => [b] -> IO b >>> xs60 <- run $ (minimizeIO f6 $ replicate 10 0) {noiseHandling = False} >>> xs61 <- run $ (minimizeIO f6 $ replicate 10 0) {noiseHandling = True,noiseReEvals=Just 10} >>> -- assert $ f6Pure xs61 < f6Pure xs60@@ -105,7 +111,7 @@ )where -import Control.Applicative ((<|>), (<$>))+import Control.Applicative ((<|>)) import Control.Monad hiding (forM_, mapM) import qualified "mtl" Control.Monad.State as State import Data.Data@@ -296,17 +302,17 @@ sendLine hin key sendLine hin val let loop = do- str <- recvLine hout- let ws = words str- case ws!!0 of- "a" -> do- return $ embedding $ map read $ drop 1 ws- "q" -> do- ans <- funcIO . embedding $ map read $ drop 1 ws- sendLine hin $ show ans- loop- _ -> do- fail "ohmy god"+ str <- recvLine hout+ let ws = words str+ case ws!!0 of+ "a" -> do+ return $ embedding $ map read $ drop 1 ws+ "q" -> do+ ans <- funcIO . embedding $ map read $ drop 1 ws+ sendLine hin $ show ans+ loop+ _ -> do+ fail "ohmy god" r <- loop _ <- waitForProcess hproc return r@@ -360,9 +366,11 @@ zipTWith op xs0 ys0 = State.evalState (mapM zipper xs0) (toList ys0) where zipper x = do- (y:ys) <- State.get- State.put ys- return (op x y)+ zs <- State.get+ case zs of+ [] -> error "zipTWith: empty state"+ y:ys -> do State.put ys+ return (op x y) {-| @@ -383,14 +391,11 @@ Putting back the obtained values should not change the data. ->>> import Test.DocTest.Prop->>> type Complicated = ([[Double]],(),(([(Double,String)]),[Double]))->>> prop ((\x -> putDoubles (getDoubles x) x == x) :: Complicated -> Bool)+prop> ((\x -> putDoubles (getDoubles x) x == x) :: ([[Double]],(),(([(Double,String)]),[Double])) -> Bool) You can get the original list back after putting it. ->>> let make3 xs = take 3 $ xs ++ [0..]->>> prop ((\xs' y -> let xs = make3 xs' in getDoubles (putDoubles xs y)==xs) :: [Double] -> (Double,Double,Double) -> Bool)+prop> ((\(xs', y) -> let xs = take 3 (xs' ++ [0..]) in getDoubles (putDoubles xs y)==xs) :: ([Double], (Double,Double,Double)) -> Bool)
cmaes.cabal view
@@ -1,5 +1,5 @@ name: cmaes-version: 0.2.2.1+version: 0.2.3 synopsis: CMA-ES wrapper in Haskell description: @@ -20,10 +20,10 @@ license: OtherLicense license-file: LICENSE author: Takayuki Muranushi-maintainer: muranushi@gmail.com+maintainer: Dominic Steinitz category: Numerical, Optimization, Algorithms build-type: Simple-cabal-version: >=1.8+cabal-version: >=1.18 Extra-Source-Files: LICENSE.GPL2, LICENSE.GPL3, LICENSE.MIT@@ -39,20 +39,23 @@ , strict >= 0.3.2 , syb + default-language: Haskell2010+ Test-Suite test Main-Is: doctest.hs hs-source-dirs: test/ Type: exitcode-stdio-1.0 Build-Depends: base == 4.* , cmaes- , doctest >=0.8- , doctest-prop >=0.2+ , doctest >=0.15 && <0.18 , mtl , process+ , QuickCheck , random , syb , vector+ default-language: Haskell2010 source-repository head type: git- location: git://github.com/nushio3/cmaes.git+ location: git://github.com/idontgetoutmuch/cmaes.git