Skip to content

Commit

Permalink
Test for objective likelihood param transform
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewIOM committed Apr 17, 2024
1 parent 6e802d3 commit a6ba5d8
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/Bristlecone.Tests/Bristlecone.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,40 @@ module ``Objective creation`` =
// testProperty "Throws when time-series are not the same length" <| fun x ->
// false

testPropertyWithConfig Config.config "Likelihood functions use 'real' parameter values"
<| fun shouldTransform (data: float list) (b1: NormalFloat) (b2: NormalFloat) ->

// Returns the parameter value
let fakeLikelihood : Bristlecone.ModelSystem.LikelihoodFn =
fun paramAccessor data ->
paramAccessor.Get "a"

if b1.Get = b2.Get || b1.Get = 0. || b2.Get = 0.
then ()
else
let b1 = if b1.Get < 0. then b1.Get * -1. else b1.Get
let b2 = if b2.Get < 0. then b2.Get * -1. else b2.Get

let mode =
if shouldTransform then Language.notNegative
else Language.noConstraints

let model =
Language.Model.empty
|> Language.Model.addEquation "x" (Language.Parameter "a")
|> Language.Model.estimateParameter "a" mode (min b1 b2) (max b1 b2)
|> Language.Model.useLikelihoodFunction fakeLikelihood
|> Language.Model.compile

let testObjective =
Objective.create model (fun _ -> Map.empty) (fun _ _ _ -> [| 2.0 |]) ([ (ShortCode.create "x").Value, data |> List.toArray ] |> Map.ofList)

Expect.floatClose
Accuracy.high
(testObjective [| (if shouldTransform then Parameter.transformOut mode b1 else b1) |])
b1
"The likelihood function did not retrieve the 'real' parameter value"

]

module ``Fit`` =
Expand Down

0 comments on commit a6ba5d8

Please sign in to comment.