Bristlecone


Bristlecone

Bristlecone is a library for conducting model-fitting and model-selection analyses on time-series data. The library was designed for models in ecology / biology.

The Bristlecone library can be installed from NuGet:
$ dotnet add package Bristlecone

Example

This example demonstrates the layout of a model when defined in Bristlecone.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
#r "Bristlecone.dll"
open Bristlecone
open Bristlecone.ModelSystem

let hypothesis =

  let vonBertalanffy' eta beta kappa mass =
      eta * mass ** beta - kappa * mass

  let vonBertalanffy p t x environment =
      vonBertalanffy' 
        (p |> Pool.getEstimate "eta") 
        (p |> Pool.getEstimate "beta") 
        (p |> Pool.getEstimate "kappa") x

  // B. Define model system
  { Equations  = [ code "x", vonBertalanffy ] |> Map.ofList
    Likelihood = ModelLibrary.Likelihood.sumOfSquares ["x"]
    Measures   = [] |> Map.ofList
    Parameters = [ code "eta",    parameter Unconstrained   0.001 1.00
                   code "beta",   parameter Unconstrained   0.001 1.00
                   code "kappa",  parameter Unconstrained   0.001 1.00 ] |> Map.ofList }

let engine =
  Bristlecone.mkContinuous
  |> Bristlecone.withTunedMCMC []
  |> Bristlecone.testModel hypothesis

In the above snippet, a von Bertalanffy growth model is defined as a hypothesis to test. We then create an EstimationEngine, which defines the methodology for model-fitting. In Bristlecone, an EstimationEngine is created and customised using the F# forward pipe operator (for R users this may be familiar; this concept was adapted into the dplyr %>% operator). The call to testModel generates random test data, and assesses whether the model-fitting method can accurately estimate known parameters.

Samples & documentation

The API reference is automatically generated from Markdown comments in the library implementation.

  • Tutorial covers the basic components and workflow of Bristlecone.

  • API Reference contains automatically generated documentation for all types, modules and functions in the library. This includes additional brief samples on using most of the functions.

Contributing and copyright

The project is hosted on GitHub where you can report issues, fork the project and submit pull requests. If you're adding a new public API, please also consider adding samples that can be turned into a documentation. You might also want to read the library design notes to understand how it works.

The library is available under an MIT license, which allows modification and redistribution for both commercial and non-commercial purposes. For more information see the License file in the GitHub repository.

namespace Bristlecone
Multiple items
module Bristlecone

from Bristlecone

--------------------
namespace Bristlecone
module ModelSystem

from Bristlecone
val hypothesis : ModelSystem
val vonBertalanffy' : (float -> float -> float -> float -> float)
val eta : float
val beta : float
val kappa : float
val mass : float
val vonBertalanffy : (ParameterPool -> 'a -> float -> 'b -> float)
val p : ParameterPool
val t : 'a
val x : float
val environment : 'b
module Pool

from Bristlecone.Parameter
val getEstimate : key:string -> pool:ParameterPool -> float
val code : (string -> ShortCode)
Multiple items
module Map

from Bristlecone

--------------------
module Map

from Microsoft.FSharp.Collections

--------------------
type Map<'Key,'Value (requires comparison)> =
  interface IReadOnlyDictionary<'Key,'Value>
  interface IReadOnlyCollection<KeyValuePair<'Key,'Value>>
  interface IEnumerable
  interface IComparable
  interface IEnumerable<KeyValuePair<'Key,'Value>>
  interface ICollection<KeyValuePair<'Key,'Value>>
  interface IDictionary<'Key,'Value>
  new : elements:seq<'Key * 'Value> -> Map<'Key,'Value>
  member Add : key:'Key * value:'Value -> Map<'Key,'Value>
  member ContainsKey : key:'Key -> bool
  ...

--------------------
new : elements:seq<'Key * 'Value> -> Map<'Key,'Value>
val ofList : elements:('Key * 'T) list -> Map<'Key,'T> (requires comparison)
type Likelihood = ParameterPool -> CodedMap<PredictedSeries> -> float
module ModelLibrary
module Likelihood

from ModelLibrary
val sumOfSquares : keys:string list -> 'a -> data:CodedMap<PredictedSeries> -> float
val parameter : (Constraint -> float -> float -> Parameter)
union case Constraint.Unconstrained: Constraint
val engine : obj
val mkContinuous : EstimationEngine.EstimationEngine<float,float>
val withTunedMCMC : tuning:seq<Optimisation.MonteCarlo.TuneStep<float>> -> engine:EstimationEngine.EstimationEngine<float,'a> -> EstimationEngine.EstimationEngine<float,'a>
val testModel : engine:EstimationEngine.EstimationEngine<float,float> -> timeSeriesLength:int -> startingConditions:Map<ShortCode,float> -> iterations:Optimisation.EndCondition<float> -> generationRules:(ShortCode * (seq<float> -> bool)) list -> addNoise:(Map<ShortCode,Parameter> -> Map<ShortCode,TimeSeries<float>> -> CodedMap<TimeSeries<float>>) -> model:ModelSystem -> EstimationResult * CodedMap<TimeSeries<float>> * Map<ShortCode,Parameter>
F# Project
Fork me on GitHub