Dummy

# Baysig documentation: Reference manual

Baysig is a modern statistical programming language combining functional programming with Bayesian statistical inference in the style of WinBUGS and related modeling languages. To users of functional languages such as Haskell or Standard ML, Baysig brings powerful statistical inference in arbitrarily complex statistical models while retaining the full uncertainty in inference and prediction. To users of BUGS, WinBUGS, Stan or JAGS, Baysig enhances their ability to compose complex models out of simple models and to describe computations that follow from statistical inference.

In addition to the Baysig language, we have built a web application called BayesHive that allows users with little to no programming experience to build statistical models in the Baysig language and run these models against their own or public data. The easiest way to learn Baysig is probably to build models in BayesHive and then look at and modify the generated Baysig code. Once you've done this, the Baysig documentation will show you how to build even more flexible models.

## Baysig documentation

We have written an informal quick tour of the Baysig language that we suggest you start with if you want to learn Baysig. This reference Manual covers many of the concepts in more detail. In addition, large amounts of example Baysig code can be found in the Baysig test suite.

This and the other help files are themselves written as Baysig documents. You can view the source on the GitHub repository for BayesHive and Baysig documentation.

## Literate documents

All Baysig programs are embedded within documents that interleave written language (e.g. in English) with Baysig code that defines functions and statistical models and with questions about the value of variables, probability distributions, and graphical plots.

The interpretation of a line in a Baysig document depends on the first one or two characters.

Line starts with What it is Example
> Code > f x = x+2
?> Question ?> f 5
anything else Text Hello world!

When the document is typeset, questions are replaced by their answers. This allows you to build a full report or any document describing a particular analysis within the Baysig environment.

Code is typeset with a red bar. Questions and answers are typeset with a green bar.

myString = "This is a string"

myString ⇒ "This is a string"

Documents are further described in the Documents help file.

Baysig is white-space sensitive like Python and Haskell. Several identifiers (let, case, prob, where) start a block of indented code that terminated only when a symbol that has less indentation than the first symbol of the indented code block.

# Baysig Core language

At the core of Baysig is a functional programming language that should feel very familiar to users of Haskell or Standard ML. But in fact much of the notation comes directly from mathematics. This is because in functional programming expressions have no side effects and therefore there is no need for syntax to describe anything else than essentially mathematical expressions.

## Numbers

Numbers in Baysig are subject to essentially the same arithmetic syntax as in most other programming languages. Standard arithmetic operators such as +, -, *, /, and functions such as sin, cos can be used directly as written in mathematical notation.

Operator What it is Precedence Example
+ Addition 6 2+2
- Substraction 6 1-5
* Multiplication 7 x*5
/ Division 7 4/2.3
- Unary minus -5
^ Exponentiation 8 2.5^1.01
Operator What it is Example
exp natural exponentiation exp 1
log natural logarithm log 3
sin, cos sine and cosine sin 4.3

When a number is assigned to a variable that variable can be used to represent the number itself in a calculation.

x = 5

y = 3+x

y ⇒ 8

However, since Baysig is a functional programming language, there is no way to change the value of a variable once it has been assigned.

You can write numbers that are very big or very small using the scientific notation. For example, 1e3 = 1000 and 2.1e-3 = 0.0021.

## Functions

Functions allow you to abstracts out common calculations based on arguments. Simple functions are written with a lightweight syntax that is nearly identical to that found in mathematics

f x = 2+cos(x)

The function is used by applying a value to it, which results in a value that can be calculated by substituting the function's argument name with the value to which the function is applied. It is possible to follow this process along by hand:

f 2.1 = 2+cos(2.1) = 2+ (-0.50485) = 1.49514

In Baysig, there is no need to enclose the functions arguments in parentheses, but you can do so if you like: f 2 = f(2).

Functions can also take multiple arguments:

f x y = x + y

f 5 6 => 11

When using functions with multiple arguments together with parentheses, it is important to wrap each argument in its own parentheses, like this: f(5)(6). Functions can also be used in conjunction with pairs (see below) to support a more traditional syntax for multiple arguments.

Functions can also be declared as infix operators. First, the new operator's precedence and associativity has to be declared on a separate line. For instance,

infixl 7 **

declares that ** is to be treated as an infix operator with:

• Left associativity (infixl rather than infixr). Thus a**b**c will be interpreted as (a**b)**c.

• Precedence level 7. Since this is higher than that of addition (+, level 6; see table above) but higher than exponentiation (^, level 8), a + b ** c is parsed as a + (b ** c) but a ^ b ** c is parsed as (a ^ b) ** c.

After the fixity declaration, you then need to define the function implementing the operator itself. This is done by surrounding the operator by arguments on the left-hand side, and giving the rule for the result on the right hand side:

x ** y = x + y + 5

This is done in the same way as function definition -- in fact, infix operators are just functions. We could equally have declared:

** = \x -> \y -> x + y + 5

Infix operators can take as arguments and return any type, not just numbers, just like any other function.

A useful operator defined in this way, which is used extensively in Baysig, is the dollar operator ($). This has a very simple defintion: infixr 0$

f $y = f x The dollar operator $ simply applies the argument to its right to the function on its left. This is only useful in that it prevents us from writing a lot of parentheses. For instance, if we want to calculate

$sin\left(1.1+2.2\right)$

we can write this with either parentheses:

sin(1.1+2.2)

or with the dollar operator

sin $1.1+2.2 On the other hand sin 1.1+2.2 would be interpreted as (sin 1.1)+2.2 because function application takes precedence over any infix operator application. lambda and top level function declarations. let. variable rules - not start with upper case. functions as first class entities. higher-order functions. shadowing. deceptively simple but very powerful. refer to existing literature. ## Types static type checking and type inference. type declarations parametric polymophism types table ## Strings Strings in Baysig are always enclosed in double quotes. x = "This is a String" soIsThis = "A" You can't really do much with strings in Baysig for the moment. You can compare two strings for equality, though. x = "Foo" y = "Bar" x==y => False x==x => True If you want a number 0 or 1 to be the outcome of an equality test, you have to convert the Boolean to a real numebr. boolToReal (x==y) => 0.0 boolToReal (x==x) => 1.0 There is a little helper function for that: x .==. y => 0.0 x .==. x => 1.0 ## Pairs Pairs hold two values of which may be of different types. A pair is created with a comma: myPair = (1,"Hello World!") You can retrieve these two elements with the functions fst and snd, respectively. fst myPair => 1 snd myPair => "Hello World!" If you want to store more than two elements in this way, you can use nested pairs ((1,(2,False))). However, this quickly becomes unwieldy and you may want to consider using records instead. ## Lists Lists are homogenous sequences of values of a given type. That is, a list can contain values of any type but they must all be of the same type. Literal lists can be created by separating values with commas and enclosing them in square brackets: [1,2,3] and ["Hello", "World"] are lists of integers and strings, respectively. The empty list can be constructed by []. There are several functions in Baysig to operate on lists: function name type description example length List a -> Int length length [1,2] => 2 head List a -> a first element head [1,2] => 1 take Int -> List a -> List a first n elements drop Int -> List a -> List a drop first n elements TODO: mutation vs persistence ## Records Records are inhomogeneous collections of values; each value in a record is given a name (the field name) which is used to reference it. Records are built using the following syntax: {name=>"Tom"; age => 35} The values corresponding to different fields can therefore have different types. The overall type of the record created above is {name=>String; age=>Int} Given a record value, inidividual field values can be accessed with the # operator used as record#field form, for instance: r : {height => Real; age=>Int} r = {height => 1.80; age=>42} h = r#height In Baysig, we often use lists of records for datasets that might come from a spreadsheet. This representation gives some flexibility when building statistical models in terms of controlling which aspects of a dataset are observed and which are not modelled. There are some special syntactic constructs to make it easy to work with lists of records. To transform a list of records, use with to define a transformation based on the individual record. The first argument to with is the list of records. The second argument is an expression that is evaluated in the context of each record where every field value can be accessed directly as a variable given by the field name, i.e. without using the # notation. The new list has the same length as the one that is being transformed. For example, if we have a dataset of that contains personal information about persons, it might be stored in a variable of the following type: people : [{name:String; age:Int;height:Real}] people = [{name=>"John"; age=>34; height=>1.85}, ...] heights : [Real] heights = with people height height_and_age : [(Real,Int)] height_and_age = with people (height, age) with can also be written as an infix operator. The following is an equivalent definition height_and_age = people <#> (height,age) You might remember <#> by it accessing record fields (#) inside a container (< >), which here is a list. Later, we will see that with and <#> work not only on lists but also on probability distributions. A related contruct is when and its infix operator equivalent <|>. This allows you to remove some items in a list of records while preserving its type. The first argument is again a list of records. The second argument is an expression, evaluated again in the context of each record being opened such that fields are directly accessible by their name. The final type of this expression must be a boolean (True/False) value. If this is true, the record is retained in the new list, otherwise it is rejected. Following the previous example, we can make a list of voting-age adults from our list of all persons: voters = when people (age>17) or equivalently voters = people <|> age > 17 With and when can be combined, which works best when they are used as infix operators height_of_voters : [Real] height_of_voters = people <|> age > 17 <#> height ## Pattern matching In functions, let- and case-expressions, in addition to individual variables, more complex patterns can be used to deconstruct complex data into simpler values. As an example, we will use a value v of type (Int, String): v = (4,"Hello World!") If we then define a function intended to operate on pair data, we can directly deconstruct the pair into its constituents, for instance: swap (x,y) = (y,x) or swap = \(x,y) -> (y,x) for swap v => ("Hello World!", 4) instead of swap thePair = (snd thePair, fst thePair) Pairs can contain variable names (as in the pair (x,y) which contains the variables x and y). Instead of variables, literal values can also appear. If the value the pair is being matched against does not match the literal value, and the pair is used in the argument to a function, a runtime error will occur f (3,x) = "match!" f v => runtime error  However, patterns can also be used in case expressions which allow multiple patterns to be tested against a value s = case v of (1,x) -> "one is the loneliest number" (2,y) -> "two can be as bad as one" (3,y) -> "three is a crowd" (x,y) -> "party time!" s => "three is a crowd" If we do not care about the value in a certain place in the pattern, we can use the pattern _ which matches anything. For instance in the above definition of s we did not really care about the values denoted by x and y. For instance, fst is defined as fst (x,_) = x Patterns can also be used to match against lists and user-defined data types. Finally, Baysig features an experimental record wildcard pattern {..} that matches a record and brings all the fields into scope. We previously defined a record r: r : {height => Real; age=>Int} r = {height => 1.80; age=>42}  we can now access fields by matching the record against the wildcard pattern h = (\{..}-> height) r The constructs with and when are defined in terms of the wildcard pattern. ## Differential equations Baysig has a special pattern that allows the introduction of ordinary differential equations. By adding a D in front a function definition, you are telling Baysig that the right-hand side defines the derivative of the function body. You also need to give an initial value for the function by assigning a value to the varialbe which has "_0" appended to the function name. For instance, to solve the differential equation $\frac{dy}{dx}=y+sin\left(t\right)$ $y\left(0\right)=1$ would be written in Baysig: y_0 = 1 D y t = y t + sin t Here, we used the shorthand form of function that puts the function argument on the left hand side. The following are also valid definitions of y: D y = \t-> y t + sin t  another differential equation with a simple right hand sinde might be defined as: D f = sin Baysig does not currently support higher-order differential equations. In addition to defining the function and its initial value, the variables dt and tmax also need to be in scope which will define the timestep and the duration of integration. For instance tmax = 2 dt = 0.001  The value of these variables are taken from the local scope in which the numerical integration is performed, so it can be reassigned locally: ysig = let dt = 0.01 tmax = 10.0 y_0 = 1 D y t = 1 - y t in y The result of defining a differential equation is a function that can be evaluated at any timepoint with standatd function application (e.g. y 0.5) up until tmax. If it is evaluated beyond this timepoint, the program may crash. ## Implicit arguments definition of wiener and d on rhs of SDE. ## Vectors Vectors are homogeneous collections of elements. To build a vector fillV : Int -> (Int -> a) -> Vector a v = fillV 5 \i-> 0 w = fillV 3 \i -> cos (unround i) You can pattern match against a vector:  <x,y,z> = fillV 3 \i -> sin (unround i) brings into scope variables x, y and z (but no vectors). Operations on vectors: function name type description example dim Vector a -> Int vector length dim v => 5 ! Vector a -> Int -> a index elements v ! 2 => 0 *^ Real -> Vector Real -> Vector Real multiply by scalar 5.1 *^ w ^+^ Vector Real -> Vector Real -> Vector Real add two vectors w ^+^ w ^*% Vector Real -> Matrix Real -> Vector Real Vector times Matrix %*^ Matrix Real -> Vector Real -> Matrix Real Matrix times Vector vcons a -> Vector a -> Vector a prepend an element vmap (a->b) -> Vector a -> Vector b apply a function to every element slice Int -> Int -> Vector a -> Vector a extract a subvector given starting index and length in some of these operators, the symbol ^ reminds you on which side of the operator the vector goes. ## Matrices To build a matrix: fillM : (Int,Int) -> ((Int,Int) -> a) -> Matrix a ident n = fillM (n,n) \(i,j) -> if i==j then 1 else 0 mymat = fillM (5,5) \(i,j) -> cos (unround i)+sin(unround j) Operations on matrices: function name type description example mdims Matrix a -> (Int,Int) matrix size mdims m => (5,5) !! Matrix a -> (Int,Int) -> a index elements ident 4 !! (2,2) => 1 *% Real -> Matrix Real -> Matrix Real multiply by scalar 5.1 *% mymat %+% Matrix Real -> Matrix Real -> Matrix Real add two vectors mymat %+% mymat %*% Matrix Real -> Matrix Real -> Matrix Real multiply two matrices mymat %*% mymat ^*% Vector Real -> Matrix Real -> Vector Real Vector times Matrix %*^ Matrix Real -> Vector Real -> Matrix Real Matrix times Vector svd Matrix Real -> List (Matrix Real) Singular value decomposition transM Matrix a -> Matrix a transpose transM mymat diag Vector a-> Matrix a create matrix from diagonal mmap (a->b) -> Matrix a -> Matrix b apply a function to every matrix element In some of these operators, the symbol % reminds you on which side of the operator the matrix goes. If you use matrix or vector arithmetic with inconsistent dimensions, Terrible Things happen. ## User-defined data types Maybe, Either, () Definition of List, Bool ## Portals pure functions and side effects # Probability distributions Probability distributions in Baysig are first-class entities - they can be build from simpler parts, assigned to variables and passed as arguments to functions. Probability distributions have type Prob a where the type variable a indicates the type of values that can be drawn from the distribution. For instance the standard normal distribution (unormal, with mean 0 and variance 1) has type Prob Real which means that value that represent real numbers (0.1, 3.141 etc) can be drawn from this distribution. The non-standard normal distribution normal has type Real -> Real -> Prob Real, because it takes two arguments, the parameters (mean and variance, respectively). The fundamental probability distribution in Baysig is unit with no parameters, from which numbers of type Real and between 0 and 1 are drawn. We cannot do very much with probability distributions yet, but at least we can plot samples from them: 0.3075378260825616 0.35028426450451006 0.6939502592882957 0.760742239365527 0.7553596256196871 0.9730891303562301 0.4525427707593289 0.7230890597503374 0.7998048760462098 0.3216404810831045 0.43633041098628433 0.4357998157934751 0.7705563411048046 0.28418760776617275 0.15282762030903893 0.8699506111140248 0.6771089913503054 0.9304247193342132 0.917962193935635 0.27919762634653544 0.6286977835997701 0.40252373004390946 0.7894441922636339 0.12588518395225637 0.386567853714006 0.8266792636892477 0.2035244596664618 0.8490478633551504 0.2556824009529507 0.6814479573353771 0.3057110559441408 0.730832068652574 0.3648275112185691 0.13505027469597997 0.3695715308118545 0.5924543972575232 0.07270444093102227 0.7808133547149629 0.6377516157547365 0.8977481715608733 0.6797923950198554 0.5599761224724297 0.6718086140863152 0.1414196633597416 0.8640327644217836 0.8666515058993016 0.5317653297753459 0.22562330267988687 0.12832525887720408 0.3502380215447019 0.08337842209343296 0.44444866931169497 0.5521166330557589 0.35568790402163003 0.42408855315858696 0.032236431499998185 0.8592339511632998 0.04007240572014647 0.9430483186019232 0.7470291742931654 0.36876280451397475 0.7462603947488265 0.6945739592645722 0.18250561859051362 0.32256624668896344 0.5029251336825371 0.07322132379590099 0.3073135924775418 0.7021965306955847 0.1113074650315818 0.7923474763036583 0.7928010159621017 0.7639659218871887 0.9449189209716672 0.6322467151638694 0.437530201728812 0.9339245129222806 0.33352948686423 0.47326154785073865 0.5378543174680914 0.7574043133662558 0.8370613201607627 0.6796751759666193 0.5057859524399475 0.9016457397727402 0.6147232662455 0.7852784289944168 0.17968963812563793 0.6286060604333426 0.32593267139185517 0.7551049978367763 0.5262183117508465 0.7068657241079178 0.19967198283403925 0.8903968559788533 0.22497962979250113 0.9324303050368163 0.41288585528100047 0.2253426253388968 0.5216252970326751 0.6654728841188999 0.27616334084332067 0.8007924581879733 0.24589451850529168 0.4756184219093105 0.4417053734515108 0.5769881830962813 0.17560484823202827 0.8669706389463904 0.13967781843144395 0.8721333138812644 0.5278909992258742 0.8076076833083312 0.21023808121919588 0.19549274844943842 0.1473436523571945 0.20510992203026776 0.5517075624204492 0.19419173714569576 0.4794516923091029 0.8179785061669486 0.47820402623112407 0.26720236574001666 0.02702122461679886 0.8133490080510613 0.6693104386025366 0.8396492139062959 0.8172105752903062 0.5586570565492514 0.1962734961873557 0.013062077810303791 0.6799539094045651 0.12561553393621358 0.33722597531444065 0.8821406732038922 0.09819425132549234 0.212461891633566 0.1653909299442058 0.9449386917857776 0.24021573789422768 0.5545454969523813 0.7659182012467455 0.6110633159082065 0.21672312710823563 0.31436097838784594 0.6252892540361009 0.012272194263588682 0.5605672357046435 0.9879190993932819 0.392265872189837 0.43723472753475295 0.19546372447988572 0.28649597179295866 0.0801244084909848 0.8395904544367433 0.8878807313479206 0.47641714906236554 0.904415295437075 0.6623609125759362 0.7131780597179146 0.4915534582667876 0.19845730164052391 0.30974183238803915 0.2984430813925441 0.8099990726471876 0.28745772021064947 0.1804115805263658 0.6068423619975435 0.7653104734526273 0.30800788367819226 0.6491833200327082 0.40284481374613124 0.4153173012694617 0.35805567106186775 0.9054265841621502 0.10123003136860906 0.14501263414160642 0.7816435002679106 0.9304209048697774 0.6367383638016736 0.40262546236687935 0.8757185346623227 0.635176882062847 0.35987971684892656 0.32889832074961123 0.6593571989003935 0.3659594350880849 0.7823612079448907 0.1811756368682663 0.7485585777900551 0.4966427722239501 0.4071214793732207 0.1803034563037342 0.9537222478431003 0.29707724817494796 0.7831631437370468 0.3052870559751259 0.9058152260039503 0.6948125338402605 0.9569952636857041 0.7937904709935631 0.6939965991056516 0.15572369218704377 0.7985075201835734 0.512141299786079 0.018629088303686373 0.2804509727937288 0.7146624416845531 0.9741025231718324 0.9169558412202066 0.9033659498447939 0.5096073587214591 0.5270935905927544 0.6511247671793972 0.6839272870411927 0.8672244148019758 0.04355178541586543 0.5773653680405965 0.4995439703342374 0.9740290136481703 0.27718022635140926 0.5012176294115414 0.3465957986997896 0.5570044968177109 0.7269023306963273 0.5807785712137769 0.5221689640363141 0.9898347305110271 0.3297781805344341 0.6181982575492464 0.4254239577393569 0.501068380079481 0.6954735083727803 0.29326785781729686 0.3714823360488476 0.305247381633438 0.7774469947389903 0.5098283038264672 0.13062738350839992 0.18863281146358532 0.4541836773171517 0.15084177235859486 0.9215976686500007 0.6301207616064047 0.6288386968962938 0.6102553020720964 0.667506608801779 0.8108176022793208 0.7212746645606297 0.5254506840197022 0.5883455361678138 0.6598960498021673 0.3089050199624396 0.07682697034367057 0.14003644537647172 0.7861548757148336 0.32280559775484857 0.060194912613414905 0.1011002415560885 0.5879808304803401 0.5994887702631505 0.5773989324405321 0.355459126260937 0.3187326382190764 0.6560476826634369 0.3576525464555371 0.6809131814355294 0.9087139516856321 0.92122107486269 0.6925361688929927 0.040763555569752016 0.2952261798305498 0.5898905009007758 0.15141584983826983 0.8397301889117179 0.4365401085085562 0.3947114251541699 0.3048412441985778 0.33013359534790127 0.706631680416556 0.42188643604095244 0.8460091645470842 0.6148860327934115 0.33638606228315876 0.21243813592298844 0.7864848342227015 0.6424977964820568 0.5415188785506223 0.1761446327846834 0.9019520506034494 0.7721197704719659 0.07258438972583608 0.8263885741649168 0.9959830997968053 0.12627225861099367 0.9690399253668822 0.8854303864961095 0.37113323141148624 0.6578633407265561 0.826371390099258 0.7676305400132273 0.3151526160806307 0.018755263886124654 0.07486419404737284 0.4215822891382459 0.5971945928403164 0.05306873192383645 0.14342260107943383 0.3765564880744918 0.8282078026859574 0.703706115648082 0.5144595556227629 0.840389668671505 0.2182730353014248 0.7521495061815133 0.7803918111092392 0.6522686829912171 0.3101521258498896 0.27959020023224646 0.30869163556692464 0.7595681936385967 0.32850383602280725 0.1492842657373483 0.9047993882337584 0.23072767798572957 0.171820673898752 0.4503282153630462 0.610171910750254 0.6736721828751434 0.8903081428469877 0.3966845312148064 0.4610921173498715 0.5926946037431934 0.9426402891852521 0.04343510978935172 0.23641145886769785 0.08641372692920588 0.7180211194134366 0.1586734543458264 0.5120979683734704 0.4840781866768557 0.1763502038494568 0.8401082832925274 0.12097680036001299 0.5249980689317449 0.4212900228847959 0.03316577268605255 0.5995232939253382 0.8844029581836431 0.00381740299142371 0.2309805686192076 0.8646979385206238 0.4014280369508611 0.7914385569261942 0.3407368625841888 0.4126105654082751 0.18084106016458038 0.38085293801986914 0.6619814128293613 0.8869254104529799 0.9868937525867703 0.898172866296529 0.20721222837623493 0.867635305707258 0.7583353474639205 0.8076164915244134 0.12241298126112972 0.1827041341882907 0.9536763958059429 0.9605781021436159 0.19620911595323334 0.9205094217137688 0.024452156160132063 0.29839813413526817 0.00045594922277516434 0.8573540832980895 0.14010019394105772 0.9969239495687475 0.7857375961695187 0.6128378688853322 0.6126543792459774 0.5837544809523398 0.12180339943659571 0.4121566881453983 0.3832975130954984 0.4242564803977163 0.14617133283665668 0.1897253306092986 0.4642848517895408 0.8388541286901697 0.19975315644400035 0.7884344816646619 0.3178357808659402 0.7561118008466697 0.5018258531349306 0.5594063986929614 0.783456719430037 0.9433535903094694 0.22294819220503517 0.6533366049764064 0.5006240586518832 0.5674848823266767 0.8179552577943437 0.3715234814145424 0.7048685128579075 0.4044665054894207 0.6616623945677799 0.6275891362753672 0.6223468435048933 0.8057659412281974 0.710393042469023 0.26058649301076925 0.2184069536669196 0.6761767982216964 0.9643202845389769 0.12771488798961855 0.6623392553679504 0.5694839566874978 0.5017474849013955 0.44624384107213555 0.24348982825025214 0.6741172665902686 0.2654571792263205 0.011342952496219182 0.4457184389340036 0.8648328135872336 0.9518881824221201 0.7924955200386457 0.38845933796569226 0.2888919437045446 0.46781100134081466 0.759533730745207 0.6855127917801759 0.07888458740871507 0.5471042044337616 0.05911958102582013 0.5345363259628733 0.7698585385852164 0.32715416986661827 0.7928211979551291 0.3932550790238322 0.10686919607847678 0.4592190970338925 0.1993295625316281 0.3794421947979001 0.9196427038217995 0.7218342341300645 0.46394330413638224 0.13924737976380797 0.223401136282692 0.9679502434953932 0.9901922515104973 0.4701378293033079 0.0604825208570069 0.4298724439995998 0.07223127341648361 0.2702322933520731 0.9663029867145938 0.5646243331871518 0.1770057487713652 0.12659210179154579 0.10782510510362338 0.5073064054612318 0.36702059008344556 0.04168255628125801 0.23865985829351932 0.7236559292589444 0.1621886692387491 0.3744489730741943 0.9378003321908881 0.3446840379258348 0.8914393174674919 0.2527469418134417 0.5415824108155404 0.486303820853658 0.9046780150161772 0.49169200227868093 0.3000896194251463 0.5330962169759665 0.6984677749449545 0.32412111510618613 0.3013326344781864 0.06361828163816088 0.003291307949296038 0.9373364311031384 0.2713696445038937 0.20150780030561327 0.0060786907575276425 0.859533977429274 0.6664876622768323 0.3214327747284977 0.9871979723654682 0.7438321627545711 0.6341759657101184 0.9025025449000538 0.9232395978000107 0.0021073445682663807 0.611982054219577 0.8972599892637833 0.4856719676139001 0.6638319738357868 0.7675286975613629 0.8950215072592305 0.656728726731783 0.866302302774578 0.21964583457905004 0.027403929510015048 0.7016882236818057 0.47343074681084385 0.11812830765688054 0.7105291375682059 0.8709046819412393 0.2914628673557804 0.5978053395165609 0.701779615064566 0.8958414271231372 0.9029279285815842 0.9428484181274772 0.7411377671503317 0.39594884714948686 0.5215485027342914 0.7844362686817619 0.10000076356809603 0.0583243176942515 0.3616465924684067 0.24645313742720829 0.4181995132049079 0.7659472929700155 0.035841527403295395 0.8906602288807417 0.9605184034352466 0.8971375701709505 0.8127048783499526 0.3439178455956089 0.11431213447691689 0.8308539243486835 0.2242590939216919 0.23016659408578802 0.372306518110518 0.46517118799154905 0.3496101022115001 0.47636438568038036 0.4593320371255586 0.7812164991118984 0.8281349544013233 0.7631994357246904 0.5751283554302362 0.1652872329962643 0.0540464923377257 0.4370449291162763 0.8602583720023415 0.5533326858545963 0.6137595599549263 0.5954441383004757 0.562859320445652 0.652243395255004 0.6801524969470111 0.8593658401769041 0.3952439842734588 0.718369038011499 0.6366549037947913 0.47516933071314577 0.32439878916470305 0.40869920524039755 0.4509264874390621 0.3093480128583843 0.5121092695072548 0.32493397531214496 0.8806460376085355 0.9568466073732932 0.5282298206650256 0.6622178749326193 0.6158546608909626 0.5162590526780717 0.9217133538149561 0.4794970954487792 0.005364828511459014 0.5070641402870101 0.22180030313828036 0.853208105045652 0.061628378942056646 0.40592675781946785 0.33382143623517396 0.4252428958251241 0.9834181200674311 0.5324288226041078 0.03708340763977808 0.6335418132677538 0.7891977899217042 0.20947010563906984 0.2486694290416011 0.20429465272563851 0.9867103002003185 0.5662136621694578 0.6522721130522602 0.4721321250479976 0.3076558053278494 0.5860141358771395 0.5993667493107185 0.24164787126743417 0.8093367926332486 0.5091220772613589 0.9962010835288561 0.4049207324639244 0.6266114147441953 0.8878980388138206 0.8018219272610316 0.8052304128197093 0.9923912885115461 0.6945372097414306 0.04891024973450933 0.35257755880071256 0.7251654697407888 0.6752483920835072 0.13007032990690096 0.6526925763237972 0.41533325831762824 0.40188021827532916 0.6640231052096986 0.9133315577435613 0.7290648361037171 0.06641195995416771 0.35258137652477745 0.8599642454320482 0.47798865392757317 0.4918030669195119 0.4296869650552252 0.2944946892779541 0.6833591311432792 0.5545997166900429 0.4864252126976906 0.7931881458017016 0.06247011433878683 0.2448251925513207 0.8939856318510104 0.02924989863048538 0.5966369441236921 0.8336533896703398 0.015634951185350063 0.3140254179746903 0.24681861867355617 0.9488923661291815 0.9260581559329429 0.15248119788069306 0.9715626642507414 0.19916593148353648 0.7337955701476419 0.02190213930371733 0.15944676663713686 0.9525582957902361 0.34617089790901423 0.21605522074179148 0.49638227966995496 0.7654566631571987 0.5212655047702756 0.8746598532597208 0.45725890771887706 0.4538826128593373 0.6670491005450135 0.642328825928813 0.5202202721313155 0.26180908392691266 0.24949224508588488 0.9450660976453372 0.08187380644536434 0.9655978223228822 0.767421725617587 0.7876966974669362 0.8893213609441466 0.668106194973948 0.7836867735683188 0.6613764694569112 0.6420099739083113 0.8461904110960174 0.40217674416540583 0.8396480308937952 0.9911203649805673 0.688839812457757 0.9355926364510303 0.295990553287787 0.33000762116396976 0.5762847339679219 0.9188499736876343 0.6023510882170757 0.2602556981752291 0.552161800337993 0.24050827865500662 0.12702618076629615 0.580310807465648 0.40695059029547276 0.8807330601570972 0.5058762499843436 0.13114384611396673 0.10432500068664667 0.7741251501194493 0.09233109771561136 0.5431479172648741 0.9455574389886012 0.06411167701336361 0.8553637310060123 0.9228917858383832 0.11155713817839444 0.03807570180810888 0.2765611552811603 0.4269099799978803 0.9717184845292285 0.828743991402151 0.5417098313434305 0.322132263174777 0.9548163525654972 0.3341144482451758 0.9774751181196131 0.8410593208021157 0.7019978367495345 0.9966902355655772 0.07253245731641829 0.61887080073796 0.931716645819069 0.7737162357135016 0.4670623774796404 0.37943119331715425 0.20394759653228045 0.537331611275983 0.5576960483001768 0.025206520693657575 0.8350693482987278 0.19516767891942702 0.3591732043677879 0.2767157566912276 0.4583471390554558 0.6521266483823133 0.8618909502080387 0.09461399030280625 0.8465674291007611 0.524321840965264 0.6795056028476697 0.22916364232757214 0.8346115955697865 0.5231207261148656 0.3478309189313629 0.3333285635647663 0.7068100461519347 0.6937496214392012 0.650652148213855 0.0377264763316434 0.2714801424349379 0.30418147852276023 0.1742627073950746 0.2337558107063537 0.9483443773231339 0.8696262365834848 0.859334707693042 0.7058830414213899 0.8078226404748444 0.2786057710830601 0.5667550858498447 0.5636637696446068 0.8907872289164893 0.7026883309480474 0.6647409653907504 0.13220327536859625 0.8503652407905006 0.1999739518389045 0.9650007297669073 0.13255735792512013 0.9922914113831454 0.5983985072463748 0.7416058738579987 0.6424772817740397 0.9168010079108181 0.8248510350996747 0.2554926151073288 0.07870799281604308 0.8841230107667211 0.6465329790130567 0.7593965690488453 0.07156157867786511 0.038620776738650345 0.4181827514940367 0.03969068523489187 0.1788527884471353 0.12996500873238898 0.1074106276751055 0.8731381322427508 0.3667424636349879 0.5830842297484828 0.6882327927016264 0.06036202145283157 0.5569899754032935 0.8210567859516146 0.811414228009855 0.9070299383967719 0.910113046623327 0.34236538790687115 0.7527151863911923 0.6118493968648485 0.5937448517870495 0.7729762284487897 0.8024568596860526 0.42880402305834087 0.7778790317889953 0.8256375114027498 0.4529305534560537 0.6365677003368194 0.852586134535397 0.12165687515438928 0.10378372834617824 0.047559025009991374 0.5972878720139357 0.11059260790017261 0.8875604823435564 0.1604019187298608 0.722562461328358 0.06244461658933308 0.04735561740755933 0.015311284227136356 0.581435038377865 0.31247623109083533 0.03791222722220985 0.3459321962077944 0.060295023503782 0.8590809194974324 0.46303043921082987 0.8156831315289446 0.25634643511295935 0.618521963157347 0.8480063168909415 0.6971622269361192 0.8225271668803242 0.5921671131141872 0.43019728023330617 0.4333044871299771 0.44080056609604523 0.5373311891540259 0.15209498842062777 0.5554563164607287 0.7679659809842626 0.9726154990430492 0.008338698187921824 0.39254700960417904 0.006886906923467039 0.17095216181384218 0.9395208977953347 0.9316334053714838 0.10923184643248837 0.4331650890952826 0.8779208331550287 0.2658012749780438 0.642722023334988 0.985294473819736 0.11907295093850069 0.4472897773253009 0.3869292967456694 0.6086049693656631 0.8996728192781268 0.004710520851591258 0.19404469877342803 0.38264597029952474 0.5258145075118669 0.7847458070108541 0.168935542732695 0.7710604448269728 0.828175513033796 0.47524599625618336 0.5764934212380306 0.01905866759341645 0.917767200599836 0.6311721440011571 0.22507318650024785 0.43368188557999254 0.24541816027961164 0.4356366164133969 0.3801627118094272 0.6162827763744357 0.5243857243387927 0.1765122176558972 0.17939276461941023 0.6843772767308115 0.8766513855375003 0.4803175503575051 0.33251487261907076 0.6967735147794647 0.09619641119991346 0.27781855298155417 0.2852384041261949 0.7329846987810416 0.6737272077411709 0.3061587448013385 0.0351362843148262 0.3570469260115751 0.6618287972318542 0.7873976141650689 0.8805133977161053 0.47411718929049496 0.0029144228908499757 0.33421919246535264 0.8458073883889726 0.8272202123951214 0.48880969371851757 0.5577023712819681 0.8504030250130228 0.1970901624758472 0.9130022537226329 0.5965470142188825 0.1387362338459902 0.3762263512183508 0.5199965458642684 0.4518315576603244 0.8460321062817313 0.7644188815644987 0.7731058829867062 0.9829357687809821 0.4467446919173805 0.7163893754399356 0.6463200127813779 0.34283928138735686 0.7408333003383207 0.1519187160655667 0.45452217582020027 0.9130637259020152 0.28119017586139733 0.18116114525617127 0.5089872573756118 0.2823471630183857 0.2531965545502483 0.6907039593650736 0.7565629488687411 0.3784590252624962 0.8357082237107 0.9608816597519633 0.36403153426107754 0.2631120065374095 0.7521669971179606 0.6680645024562405 0.47514160896538327 0.7620212318752941 0.05127538159752157 0.008899089416698341 0.5749519894772563 0.7518243321105429 0.3308749721224594 0.5316876448997501 0.8241737971138614 0.021753608021362128 0.19669055920017198 0.8065545751728478 0.2968711183166297 0.4881296033244882 0.6477955360076846 0.47958877251473925 0.6088883969022167 0.9407630294889125 0.92101542184153 0.3240309207057652 0.09394316889670286 0.5023584702290498 0.5018614089353619 0.48320998542085525 0.24183721426917176 0.8387168561664217 0.9723276977828536 0.6198980283504114 0.6580708836340511 0.9708074752639065 0.679219992756662 0.7981381245884435 0.09464256886733756 0.08700128227635316 0.8110772924989176 0.04219310335866015 0.4193973435134155 0.669598873860575 0.7941158015267262 0.8415410455413025 0.11937935466863665 0.31575024740671515 0.2037208865405342 0.7906555903122424 0.5965541537377411 0.20770337740138717 0.15462679140144653 0.1293494620195938 0.40671679456874654 0.7008969112534301 0.926889301726336 0.37345832571700643 0.6881217788178757 0.938846959485404 0.5798819429659942 0.42758776792967407 0.35649098277941604 0.10938706484376151 0.11380628033396935 0.4268364788561213 0.4514455037311291 0.47525672998168894 0.9132893483418248 0.030153234030621413 0.4852939326049047 0.9094344458797561 0.7605207324401757 0.6866358319964809 0.9696730156358502 0.6557892737108724 0.2868258995671817 0.6347272155421616 0.45225583516346657 0.003297091928147034 0.605267569330816 0.08106197535085072 0.05276676734275342 0.45775407190848005 0.9270658641883791 0.19128723679838872 0.8480508776493489 0.7558364848969124 0.9269424192437302 0.4678917679628105 0.7147935688762911 0.41561158616459265 0.8633488360474233 0.14378655053297676 0.5014908198503523 0.7226351422077593 0.86222276903275 0.04060320254429318 0.52476508392132 0.10469063210875974 0.3666944474369973 0.37799110621632803 0.01562615111834047 0.35554721633800007 0.7617704707108834 0.578149026860052 0.6752103482548172 0.7567544185455782 0.4413820217459886 0.1902493546228505 0.5652795705397798 0.5324033816653312 0.7046024428458424 0.16006995275618274 0.7240363202812234 0.08916281398599102 0.2958773254174453 0.911041813649014 0.6758244800557905 0.9405824122812092 0.5900903352513188 0.19026466300484368 0.4594707098927979 0.2696840533217611 0.8493622354812367 0.32441279299659953 0.637986882272639 0.03903645883291877 0.31581895968779433 0.4097730343718485 0.05151084648713256 0.6676392489270399 0.459956107069728 0.6177150692366331 0.7516865375804916 0.6752663896594351 0.1307225087961933 0.20037711835475105 0.16338803855781164 0.31229586068361437 0.3679711626302384 0.6192246208943484 0.19871670873805805 0.3084228249053524 0.2093821161448448 0.21029321621411787 0.6871349412685108 0.41582433679509545 0.052167559753211114 0.733247446299821 0.530536262442017 0.525544412556464 0.19354826449266363 0.15537230324823695 0.5816759410271598 0.2354958453763965 0.04623829784017017 0.8968630565555913 0.09354063893983622 0.1374077906686365 0.38469740454682555 0.8969853291979492 0.6532630188514625 0.8718739961906974 0.3198720345552713 0.6007732303349239 0.5896585599029573 0.34688563303716613 0.6179535970133622 0.1851338597911256 0.9700604604953109 0.01166069531153438 0.20911299791399227 0.4412021388861356 0.7456141220744732 0.5175460804061839 0.9992223624138213 0.8572977173275542 0.2599185240128819 0.5761227222569573 0.823082820936824 0.6482102527861041 0.8437134695341143 0.7813981333238534 0.5086495779707677 0.23594238754267394 0.07722823998826282 0.7955011550326602 0.4499313336447653 0.3079701048107748 0.6297270137885881 0.7127961429564273 0.06411760325173792 0.673494771046912 0.6900644057174363 0.4600587739749017 0.18929148353386938 0.22434140677199266 0.8045735046743819 0.5000720185926352 0.5848322221042663 0.7500854918617023 0.13188606829659225 0.483873754852422 0.17507971757442684 0.27092525788371574 0.7977420619683671 0.3240426828442241 0.18758349753627168 0.37089057415046045 0.7183309369064707 0.23862838517842544 0.43361588950120283 0.10636854965853704 0.6605234508543563 0.6564529332463753 0.6261539754053005 0.2868916681704325 0.34184825894000204 0.261474937028595 0.46989959489319 0.642590983687572 0.10865366065610518 0.711612974692046 0.8477912228200098 0.11053476345504978 0.4870531753373922 0.477355718025322 0.5233263269819614 0.7265034959946068 0.5629410207185291 0.8267986257157285 0.32412094141452596 0.24069261137412223 0.21080730324862695 0.15903202704131417 0.6199109481228308 0.218337245103516 0.8289413549539031 0.5081129820337782 0.3307229176468036 0.849898099631513 0.6901233907998827 0.12160268521905009 0.2645514163338932 0.0028537036857692764 0.06664179057503161 0.7958405769420417 0.5449705604801351 0.6869816970282657 0.6252423686965467 0.19710736935890916 0.3247492658730478 0.5294504320550362 0.9218200277355081 0.5927446204220748 0.9670564846524634 0.19641307955524256 0.9919490485899032 0.29338290456062716 0.5636514987711915 0.764035264673651 0.4681242246805048 0.914804693757278 0.9145292436970699 0.0914214560974905 0.0519126700358262 0.7480286645582013 0.16510258246332002 0.49324002128402705 0.05251710234501332 0.30642576522809123 0.5352858327178485 0.7245817372399805 0.3001868148101929 0.0795898828840791 0.9059711084482193 0.9249715041194511 0.2589923504877352 0.44757013010037366 0.7790976841419697 0.41887952723048616 0.4103029012704042 0.9771516760758012 0.3954595156003394 0.6758952654609213 0.38356317099732423 0.49346307979278803 0.25459367834371366 0.7944026872968307 0.16455265394517982 0.5946313833339678 0.8155117469875868 0.017313085034795356 0.250174136657774 0.43782680794546075 0.9798391621978579 0.9071011328853437 0.6842596015623443 0.42555113193242605 0.08122656449704119 0.17354591218138718 0.4193789308004498 0.2385828225497582 0.52127109829366 0.5408696554463519 0.42492311783715225 0.5644758200655868 0.7594967439676394 0.4333328188940261 0.4443295200924225 0.05635108567223677 0.030530765892595697 0.1314427610792785 0.4841218889886797 0.7060835225754611 0.6148180476424326 0.9392348693076602 0.3278488699178791 0.8632078265918437 0.97485360782008 0.04564750381876889 0.4421512336568328 0.8347602565388103 0.671329227665283 0.8305879334990373 0.412447929944016 0.1100477697583958 0.25399125047353827 0.7460426224270004 0.40647367979550586 0.5760028663966812 0.24914890207563267 0.1263473797883716 0.18451600363117548 0.48819808743153653 0.2494457429855703 0.011822456729557005 0.15368468131722993 0.7787910957771332 0.5341384298014776 0.022441123617450036 0.25539107114434967 0.18485532891583986 0.44086494353619987 0.5586262297720244 0.024664804345151597 0.14715326441152796 0.19194223759508278 0.042859933581869104 0.6744816407269058 0.5032096401562937 0.5674926800577651 0.18279702569888837 0.27820786002050335 0.9761636061538391 0.5029393032898519 0.11763969299328507 0.6697900571557205 0.4112208095405299 0.17112784929832625 0.1951877326227696 0.3726938111643991 0.9251046986144745 0.5531194730552658 0.22930750512269035 0.4210694158498825 0.12278067882237506 0.9519039993062391 0.6438731524729806 0.21737662917407616 0.6545451992784034 0.1722259608032708 0.22393347980080486 0.4120213660439526 0.8130578326091771 0.6691750559651235 0.7471146003220032 0.082225899929699 0.0034526616808615304 0.5521782081462858 0.06747849776118027 0.5315318243884323 0.6061375529053942 0.1947517449024021 0.14399230483546674 0.5232373118687508 0.6383333701263958 0.6523872845928155 0.6079254307802593 0.2887606889216138 0.46334157871625886 0.9312123104304104 0.12750844008464096 0.5277882131114109 0.7639197231652028 0.493679553850945 0.06478201157059102 0.5459462426476986 0.48115394042831705 0.4483798727040132 0.39051299341733403 0.4058032907559078 0.9286722680387721 0.9391210635516609 0.5554078823317327 0.9734438583192984 0.3417144800400628 0.7162399633592553 0.44850177305017175 0.6515009223137751 0.3316949383196642 0.763503493686091 0.6716691515575324 0.35655303587125453 0.28904741846235643 0.7981471360656776 0.7997649898286362 0.46572033187042 0.2110291650078793 0.17252884739370292 0.27433089219833046 0.050586456444716654 0.8633965754097785 0.08964479041510373 0.9314046571802824 0.6972873156651126 0.5472923544112808 0.7347069265634536 0.6461205206918811 0.8364771836987877 0.7666693617977829 0.6702546676784416 0.6144302316509258 0.3678474240861478 0.7050170902407302 0.8439781830748493 0.03561479482697667 0.4347695788449537 0.8662140022186129 0.4210289135624256 0.9350440425181398 0.6371991025836204 0.8648908328881699 0.5237757895430027 0.29540029617385016 0.5271974672859528 0.9363636972700161 0.5670924611778679 0.5005952065113455 0.3800221424037642 0.4873202400019672 0.516993748144478 0.7607465537173549 0.4460434686499749 0.6638832294065233 0.27289356600327735 0.05463229493578717 0.7333551688895922 0.6516308809285124 0.2413272471729031 0.82822227171348 0.09685186694768534 0.06381644659298855 0.41668280014225345 0.2995514774926825 0.030940234202644842 0.5930748729950457 0.32441474644570023 0.8941421012613322 0.33618883400601074 0.9024289487633922 0.004977162928547981 0.9510267909967869 0.7894473669094609 0.9629108498252255 0.9049691818433276 0.3451553639828124 0.9236257423003265 0.853901806486282 0.5106053288352222 0.5174056902801165 0.28973877855803326 0.7080603355327761 0.20704802689306626 0.5131260334777473 0.40625042035389936 0.0903431701218577 0.7751640341652474 0.4246561134757139 0.4373579571110564 0.2599121432890911 0.19022578727226375 0.28742541519166565 0.5016623357081931 0.09317120865294039 0.3147062250214411 0.10673859298851773 0.4095234015047372 0.6298748170095204 0.10684996147333876 0.06973068999818775 0.8868116403200691 0.33607763385774514 0.9797475172625266 0.6751916798938047 0.8689355675291586 0.6324742100277158 0.2082703884710256 0.22186368010515897 0.7463839705442973 0.6617967872092958 0.09792072933584468 0.6541715016714696 0.9485693303748428 0.11528097002657153 0.818044264525651 0.8972057720872587 0.07025577129569271 0.8379195839720591 0.3359914159718881 0.09070253257888894 0.00923967780760482 0.7699676206731162 0.45957651651920206 0.600108032487358 0.3451220393984397 0.3813979458951852 0.26296512998243915 0.6499958966509429 0.21130858669320787 0.28508462879925145 0.6878476537968609 0.146328439038789 0.9644247835884859 0.33026788880356306 0.3868808544676008 0.017337023051766917 0.5389505074217334 0.7995099138467363 0.8734810582533202 0.5610712292979172 0.0994758517712997 0.731404793386209 0.5378119585890816 0.07384739934323528 0.17241435432164331 0.4433777682584193 0.10464417238362231 0.08317025356999837 0.21876435662125338 0.6389457554647107 0.003283920698632468 0.8072673305420361 0.10328430195881154 0.14309319065490114 0.07987522498701588 0.3349632735678375 0.24871829879673157 0.8116070241228693 0.0311740795222982 0.08070629208365136 0.14720178375653964 0.1449746741319482 0.950829777622323 0.9987523711749242 0.8895732857961145 0.4626146814466023 0.6364599507386935 0.8603035499947852 0.7804661129555819 0.2883469912429217 0.5825743357610363 0.16743452571505554 0.7039744422547459 0.7214222559056762 0.6577497761831036 0.6963095794656103 0.5947881759132231 0.6594467853800037 0.33473929817200154 0.934378795543308 0.46260336005655195 0.9736716395648363 0.5481179967867486 0.7299307823949333 0.1799612089944913 0.9508172487725544 0.5698243718524054 0.2293363812447843 0.9742278770949291 0.8718126113228064 0.8888446772212266 0.05377711473353606 0.5824175587814342 0.503881243174868 0.24862240144252368 0.7462967931633575 0.4504077060731146 0.6679785085534626 0.07468653565148975 0.3455122100062464 0.957011311304991 0.6247765537409057 0.27221194358361234 0.3611686968619862 0.07848928078973882 0.6454514776462343 0.6840672501558595 0.06346576941745956 0.8917757034981101 0.8184150950560382 0.26187693659725525 0.8969041935393829 0.9934665267340528 0.1271601224148553 0.1092434411657144 0.47491588827104214 0.0617817356395027 0.06487745676768884 0.8077522459923644 0.6497806905884717 0.7965777557800938 0.9068829472891248 0.4197646438655827 0.20376080325892215 0.3889877575889667 0.868396125703211 0.24555425444747186 0.8822101801359584 0.43364450927675807 0.981149793132476 0.479811269203157 0.3318766847559895 0.9538089888994137 0.3387018456912371 0.7223098226176364 0.2753112093255183 0.42743568458301845 0.7024184974614573 0.2537104488009844 0.8508306406091038 0.5272055737504748 0.522409198694492 0.5660204762979458 0.24484874686339142 0.17540240641110633 0.7489464724783196 0.7177010783268374 0.9313595399566367 0.23059223760631686 0.2381786814048371 0.8054726938264148 0.2925886852416649 0.4082864875458848 0.005132864929068104 0.26945713098846774 0.14373093707108192 0.2971186140312624 0.45531916000305656 0.8891907850953729 0.31483778038873284 0.021670675608718458 0.9996519808190996 0.3572931735211269 0.6791169805636437 0.009879301770096481 0.9415559910567375 0.42834979049590177 0.9398915525385857 0.8801699599437811 0.0724121642001933 0.1882015886223413 0.41488572126601025 0.31400960085774066 0.8512304871928018 0.36831703581109576 0.6400942184590023 0.3705017046002908 0.7597735574840973 0.43064331878690126 0.8563047216404939 0.3740736128236338 0.9348993412998736 0.3148961992270537 0.22670860640395168 0.9070539958558637 0.5741874255645525 0.3164682810465964 0.20493597937862762 0.35913969258757766 0.794848564964451 0.8722592261322446 0.4441636797143527 0.19086703453000334 0.6381139181643058 0.4522984652901763 0.4412982490475518 0.1961485429657969 0.11873549714655045 0.7773700195311964 0.47235122892827525 0.6113068309173236 0.39144064681405216 0.8112282957442171 0.5690229911285041 0.26151299738826067 0.5599266089405693 0.9260241917627919 0.6636313280704504 0.10451890833315414 0.41891238103129724 0.5806603812567565 0.9208196983488323 0.04821986659621351 0.4240727434922179 0.986713547023645 0.529590046156568 0.01515761204416808 0.21046622195524775 0.7727795103035819 0.046667986560302785 0.46406473556162436 0.7830138438807367 0.19711545300602806 0.4017729897521839 0.07741933899871524 0.019767182418091032 0.5730763412018018 0.21838983828630062 0.034876697239204474 0.2529939658131902 0.9166767708763194 0.725462237774735 0.9144320708965957 0.9271145143842126 0.31620670420029356 0.38982678144002025 0.42512526861976957 0.6101738891122336 0.9819874211638205 0.24900991149456472 0.562253896743584 0.9886408243301885 0.34754400871404073 0.7627166197082765 0.6715377673207638 0.9401390906283956 0.387965130011543 0.09635328154460371 0.09373695172689318 0.17702973638126387 0.2844096574197546 0.2953743825888667 0.1358621577117271 0.4912992363076888 0.30642304297220496 0.09420071428040991 0.46104790467327644 0.5273899362719129 0.907596584387961 0.8570510332605454 0.27528001025209203 0.607684127895088 0.1834733400455381 0.4507366410574728 0.3418845230112515 0.035657795387240544 0.9104453162081645 0.7438959187697377 0.9777986977663353 0.31732045656939045 0.27633188694630095 0.5759133700225301 0.2057425277786661 0.699425781075709 0.6080051729474228 0.15585701241061486 0.4805412449595847 0.848612945957252 0.5879774509435467 0.8438260501352665 0.603783781082319 0.06158660260531739 0.7209607713671775 0.29861971300528845 0.8153335186222879 0.7376023777149623 0.3243889706964579 0.5411249551785003 0.13723724385193484 0.9081146702887757 0.22167863026766074 0.8967075419837394 0.48216044541498654 0.1994952802079486 0.7395343179208074 0.33489788168456824 0.6211741572760917 0.39819461326072797 0.44952218920214154 0.859757082969825 0.18981783236139868 0.3131495395938748 0.2584560169508811 0.96754249906343 0.6112505597088603 0.1455753338862153 0.031210820197875338 0.9005831668387594 0.9692769702452414 0.02082036226541278 0.16855543809210774 0.9247155524615002 0.19120069364812242 0.40879763392936386 0.2638577419016179 0.8773241301247208 0.17677686553839056 0.03306669509808223 0.5924123780784226 0.6858542151017707 0.6884894484394438 0.23133472405172295 0.6140389201729649 0.7066489913749157 0.7369357877729776 0.8104579860368879 0.6246650348474889 0.8025572092278295 0.17449085115792481 0.1380451044854813 0.7940233512301984 0.2771256862387819 0.1425052925810463 0.3347424828295462 0.10609521696020272 0.6113230557207304 0.4618492216015815 0.06073880034050411 0.7423253708384757 0.23530929541106085 0.5665619295478244 0.7735094862928403 0.11373338618169851 0.7688170230874831 0.7979333649384635 0.9898004140681123 0.8154571700877178 0.6505562508596471 0.6055181279325668 0.6879779763258942 0.1947739890764407 0.6091257148909209 0.7538443710081848 0.5438661832697378 0.8365837370130661 0.8741475662389182 0.6625477929279552 0.5840030292943127 0.3978768071154777 0.949695658858329 0.09256499542215955 0.6054757348274523 0.040860350718922064 0.2276940353279221 0.9717642629919024 0.9937567233559109 0.9853786246351383 0.925142510776674 0.3136580056309835 0.3160099604437151 0.5026893328183073 0.8457670802822725 0.213487491061326 0.014023908882873111 0.4278422182956343 0.40583034427972287 0.6806022158545912 0.039765753326883015 0.6993831688769588 0.14739233771045515 0.2724318840243928 0.4247023215109255 0.18540350980716838 0.6530387414742818 0.17054640179745537 0.8725348240399116 0.8659603190296237 0.29491712462504327 0.9035775516889005 0.958095722822029 0.11516258775143945 0.5380268184323858 0.47134294814228617 0.9430912216061473 0.5290430722592965 0.341575480844261 0.7365398324878281 0.039621442099945024 0.3216249680429755 0.03826217377517889 0.7277520661539753 0.2303766413196867 0.5383725887020986 0.18159324563611143 0.96276603312296 0.4262855221578585 0.9102807808458527 0.7936881288871375 0.39758475599754245 0.8557413580957198 0.5643902273300081 0.5207057968994383 0.9006398019615188 0.0685042948621568 0.1483274810361507 0.909447681603359 0.5538095006611686 0.20795554579420844 0.923523299378232 0.4838147020162583 0.9092071712736989 0.9063335456667313 0.2486599949767487 0.04623138114023753 0.2984420026881718 0.4443868870018951 0.9449418992607254 0.5773029617446714 0.3950176805711858 0.40366504024799565 0.15839420868046447 0.27863459062730767 0.8471571590861205 0.4763287174227481 0.04133339390189699 0.5310383132963996 0.17300775069114932 0.9997359821572285 0.28863798158444415 0.8834911177129231 0.28404344974179835 0.3072203247126239 0.641009659189966 0.48233073402250437 0.7953399263311504 0.4425452736771072 0.04844789417657254 0.2689944639031297 0.7214272475618467 0.9026983643189768 0.12474843606463364 0.27193391282854923 0.013824866389349304 0.06162310253400893 0.9533533982358299 0.6083243167047213 0.9284036620353358 0.9554249248363601 0.45741554337027845 0.42237835899516435 0.9429683030915839 0.1895480603420986 0.9445925445632526 0.8875095075665762 0.1667474366647069 0.6549871570093062 0.880761548849 0.18689857171543375 0.42535127220334285 0.042893302404064054 0.6148531589691651 0.9797378277824581 0.8797429359703658 0.12854992694420506 0.12813786024417212 0.33057571978554495 0.6364664823367415 0.21434341096653217 0.07894651314219146 0.06682914101212033 0.20634085689818973 0.7900881962361951 0.5915723141728836 0.7169376350280218 0.9094837538221581 0.6256901714079292 0.22590772463611972 0.6448280717350607 0.477717351512452 0.27136701514743433 0.4084244925548379 0.7320430813664671 0.9914494364036828 0.8867938457724623 0.23590153554359022 0.5535213538802977 0.5730634503003823 0.8922849707054638 0.6780779430824514 0.7997319064568104 0.20290750316411899 0.9548198147571691 0.9542807871369368 0.8252734853479251 0.011999371464364084 0.22445395384553213 0.6918926215013239 0.878955709254126 0.07037122782095596 0.5304238986061942 0.12028267004533733 0.9346566477172674 0.2566138052513389 0.8436668323920264 0.17764103067518236 0.9771421041752077 0.6728957345878929 0.5954091669049602 0.5893249657445878 0.5379128576111777 0.24089176399654053 0.5272708673792125 0.73241555614686 0.3952185100399001 0.6939434110405723 0.2562839401085591 0.42063791314620474 0.7139026137799729 0.6307673227579257 0.18024735459597951 0.932405243611989 0.01618538704146291 0.3220924034998967 0.3594274070019432 0.7216163474883922 0.43820778151001033 0.37638540365183387 0.5097393748605948 0.23190822201592573 0.019145827744888568 0.9746082248107084 0.06757155039058335 0.37392696583967816 0.562872699825762 0.8776317469025104 0.6156571934967435 0.6571603970735241 0.8284942216306213 0.006684528432480182 0.39930908344669946 0.43440005891826006 0.2962011849266014 0.0999749282142089 0.35051668862591423 0.0503737016232623 0.7027438107651528 0.0006060213783304257 0.009592660239337166 0.08371201136235892 0.6266837361330827 0.0879276972468774 0.5266132269815107 0.7158217711178171 0.3033237360192751 0.7419080393719273 0.7220486047961863 0.49210017232506076 0.8922406858513692 0.7728152258258348 0.6486077990030422 distPlot unit That may not look very uniform but these outputs are approximated at the latest possible point, i.e. when that data is shown to the user in the plot. In calculations and statistical inference, the unit really is uniform. One simple way to manipulate probability distributions is the function fmap, which applies a function to values drawn from the distribution. Thus the distribution fmap (\x -> x+1.5) unit yields values between 1.5 and 2.5 (because we add 1.5 to the values drawn fron unit). You can look at distribution in a few more ways, apart from plotting them. If you just ask for a probability distribution on a line in a document using ?>, Baysig will try to summarise it in the output. For real-valued probability distributions, that means printing the mean plus/minus the standard deviation: fmap (\x -> x+1.5) unit ⇒ 2.00 ± 0.30 The bernoulli distribution is already defined in Baysig's standard library. But if it were not, we could already define it using unit and fmap: myBernoulli p = fmap (\x-> x < p) unit  Defining distributions in this way is a lot of fun (except for the gamma distribution, which is no fun at all). If we "ask" for a Boolean probability distribution, Baysig gives you the proportion that is True (based on a finite number of samples): myBernoulli 0.3 ⇒ 29% Sometimes we need something more powerful than fmap to build new distributions. Sometimes you want to sequence draws, such that one value is sampled, then another, and then perhaps the two samples are combined. We can use the "prob" and "~" notation for that. For instance, in the definition of unormal based on the Box-Muller transform: unormal = prob u1 ~ unit u2 ~ unit n = sqrt (-2 * log u1) * cos(2 * pi * u2) return n  Four things are happening in this code snippet: 1. the "prob" keyword introduces a block for sequential sampling. This block starts on the next symbol (here u1) and continues until there next appears a symbol with less indentation then u1. 2. two values (u1 and u2) are drawn independently from the unit distribution 3. a new value n is calculated in a deterministic way from an equation. This equation is allowed to reference the values drawn from the previous distribution. In the same way, further draws from probability distributions can reference values previously drawn or calculated. 4. The "prob" block must end in a probability distribution which defines that value of overall distribution (here unormal). The function return takes an expression (here n) that is deterministic, given all the values that have been drawn, and gives a probability distribtion that always returns that value. Statisticians will recognize the "prob/~" notation as being very similar to the hierarchical statistical notation, but a bit more formal and less ambiguous. Functional programmers will recognize this as the construction of a monad. This notation also allows us to build some simple utility functions to help build more complex probability distributions. The function repeat can be used to repeatedly draw from independently from identical distributions. If p is a probability distribution of type Prob a, then repeat 10 p is a probability distribution over lists of type a, each of which having 10 elements. For instance, repeat 20 unormal has type Prob (List Real). Distribution Name Parameters Value type uniform uniform lo : Real hi : Real Real improper uniform improper_uniform none Real improper uniform positive improper_uniform_positive none Real list choice oneOf xs : List a a choice 1..n oneTo n : Int Int unit normal unormal none Real normal normal mean : Real variance : Real Real binomial binomial n : Int p : Real Int bernoulli bernoulli p : Real Bool bernoulli01 bernoulli p : Real Real exponential exponential lambda : Real Real poisson poisson rate : Real Int beta beta a : Real b : Real Real gamma gamma k : Real theta : Real Real inverse gamma invGamma a : Real b : Real Real multivariate normal multiNormal mean : Vector Real cov : Matrix Real Vector Real wiener process wiener none Real -> Real ## Stochastic differential equations Baysig also supports stochastic differential equations (SDEs). These are introduced by drawing a sample from the wiener process distribution, defining an initial condition and then introducing the SDE itself. ### Wiener process distribution The function wiener defines a probability distribution over functions which are realisations of the Wiener process. You can sample from this process within the prob and ~ notation. For instance, we may be interested in the distribution of the values of the wiener process at a timepoint 1.0 (dimensionless) wienersAtOne = prob w ~ wiener return (w 1.0)  wienersAtOne ⇒ -0.00 ± 0.98 This prints the mean plus/minus the standard deviation of the distribution based on a numerical approximation (the theoretical value should be mean 0, standard deviation 1). ### Defining stochastic differential equations A stochastic diffferential equation is then introduced based on the wiener process realisation. As with ordinary differential equations, the initial value need to be defined first by assigning a value (either with equality = or by sampling from a probability distribution with ~) to the name of the function to be integrated with "_0" appended. Then, the pattern d preceeds the function definition on the left hand side and the operator d is used to access the differential of the wiener process realisation on the right hand side sdeAtOne = prob s_0 ~ gamma 1 1 w ~ wiener d s t = - s t + d w t return (s 1.0)  wienersAtOne ⇒ -0.02 ± 0.92 Note that unlike in the mathematical notation, the deterministic part of the SDE (in the above, - s t) is not multiplied by an infinitesimal timestep (typically written as dt). ## Types in differential equations Readers with a background in typed programming may at this point be puzzled by how the definitions of differential equations fit in with the type system. In ordinary differenial equations, the differential operator D on the left-hand side implies that its argument must have type Real -> Real and that the value the pattern D f matches against must also have type Real -> Real. Conceptually, the D operators is itself a function operating on functions, with D having type (Real -> Real) -> (Real -> Real). On the right-hand side of this defintion, the function being defined is in scope, and its value can be read by applying a time value to it. In stochastic differential equations, the d operator on the left-hand side has the same conceptual type as the D operator for ordinary differential equations. On the right hand side, d also has type (Real -> Real) -> (Real -> Real) and acts as a function rather than a pattern. Thus, in the definition of a SDE: d s = \t -> a + b * d w t the wiener process realisation w is a function of type Real -> Real. The application of w to d also has the combined type Real -> Real, and finally this is applied to a timevalue t of type Real giving an overall type of d w t of a single Real number. ## Sampling sampling repeat # Statistical inference Baysig is desinged to enable statistical inference in complex models and to enable the exploitation of the result of statistical estimation. Estimation in Baysig is invoked with a single call to a procedure based on (1) a probabilistic model written as a probability distribution and (2) a value representing the observed data. The outcome of statistical estimation is a probability distribution over the parameters in the statistical model, where each parameter is represented as a field in a record. This resulting probability distribution is a representation of what Bayesians call the posterior. The complete call takes this form posterior <* estimate model observed_data estimate is not a function, because it needs to "look inside" the definition of the model. It is therefore called using <* instead of =. The resultant type of running estimate, here assigned to the posterior, is a probability distribution over the unobserved parameters in the model given the date. We explain this in detail below. ## Statistical models Statistical models passed to the estimate procedure have type Prob a and several parameters that are sampled using the ~ notation in the definition of the model, typically with the prob notation. For instance, a model for univariate linear regression may be written as: univariateLinearRegression = prob slope ~ normal 0 1 offset ~ normal 0 1 variance ~ gamma 1 1 repeat 20$ prob
x ~ uniform 0 1
y ~ normal (offset + slope * x) variance
return (x,y)

Since the Prob monad just keeps track of a seed for pseudo-random number generation this definition is equivalent to the following pseudocode in an imperative programming language:

procedure univariateLinearRegression
slope     :=  genNormal(0,1)
offset    :=  genNormal(0,1)
variance  :=  genGamma(1,1)

for i := 1 to 20
x[i] := genUniform(0,1)
y[i] := genNormal(offset + slope * x,variance)
end

return [x,y]
end

In the next section we will see that the defintion univariateLinearRegression also has a second interpretation that enables it to be used in statistical inference.

### Priors

The distributions from which the model parameters (here slope, offset and variance) are drawn (normal 0 1, normal 0 1 and gamma 1 1) are known in Bayesian statistics as the prior and must have type Prob a where a is the type of the parameter. The priors are therefore an intrinsic part of the model itself rather than being a different aspect.

Sometimes, it may be desirable to use an improper prior, which does not represent a valid probability distribution but can nevertheless be used for inference. Baysig has these improper distributions built in:

• improper_uniform: a prior that is flat everywhere, i.e. completely insensitive to the parameter value

• improper_uniform_positive: a prior that is flat for any positive value.

Because these are not valid probability distributions, you cannot sample (generate data) from such a model. The model can only be used to estimate parameters. You may later update the model and you can sample from it.

One way in which Baysig differs from BUGS-like languages is that because we are explicitly specifying data-generating mechanism we must give a distribution for the observed independent variables (x in the above example). This is the case even if the independent variables in the data to be analysed have been controlled in a systematic fashion. However, the distribution from which these observed variables are drawn (uniform 0 1) above does not affect the estimation unless that distribution is itself parametrised by other parameters (e.g. uniform lo hi where lo and hi then themselves will be estimated.)

The probability distribution any can be used as an improper distribution for observed data in this case. It has the same defintion as improper_uniform, but has the special effect that estimate will remember the observed values after an update such that replicated data datasets sampled in this way will have the same independent variable values.

The previous example can then be written using improper priors in this way:

improperLinearRegression = prob
slope    ~  improper_uniform
offset   ~  improper_uniform
variance ~  improper_uniform_positive
repeat 20 $prob x ~ any y ~ normal (offset + slope * x) variance return (x,y) We stress that improperLinearRegression is not necessarily better than univariateLinearRegression; the general advice in Bayesian statistics textbooks is that if you have prior knowledge, you should use it. ### Repetitions and loops A value drawn from a probability distribution of type Prob a in the ~ within a prob block denotes a single value of type a. For instance, in myValueModel = prob mean ~ improper_uniform var ~ gamma 1 1 x ~ normal mean var return x the type of the overall model is Prob Real and the variable x within the prob-block has type Real because is is drawn from a probability distribution of type Prob Real, namely normal mean var. Models for several values must explicitly use a looping construct to describe how the different values are related to each other and whether parameters are identical for all values or each value rely on different parameter draws. The simplest looping construct is repeat, which takes two arguments: an integer representing the number of repetitions, and a probability distribution which is to be repeated (the base distribution). If the base distribution has type a, then the overall type of repeat n base has type Prob (List a), i.e. a probability distribution over lists of values of type a. For instance, repeat 20 (normal 0 1) is a probability distribution over lists of real numbers; each list drawn from this distribution has 20 elements. In statistical jargon, we would say that repeat implies that the elements are independent and indentically distributed, often abbreviated to iid. The base distribution passed to repeat can itself contain draws from further parameters, and repetitions can be nested to create hierarchical models. In all of these cases, it is simple to determine whether parameters are shared across loop repetitions: if the parameter is drawn inside the loop, the parameter is not shared and can have different values across repetitions. If the parameter is drawn outside (i.e. before a repeat, then the parameter is just drawn once and the same value is used across repetitions. For instance, in the following hierarchical model: myNestedModel = prob x ~ normal 0 1 repeat 10$ prob
y ~ normal x 1
repeat 20 $prob z ~ normal y 1 return z the variable x is drawn once, the draw of y is repeated across the outermost loop (the repeat 10 line) but shared across the innermost loop (the repeat 20 line) for each repetition of the outermost loop. TODO: unfold TODO: stochastic differential equations in models Models do not have to have loops or timeseries constructs. myValueModel, defined above as a statistical model for a single value, is an entirely valid statistical model. There is no need as such for repetition in Baysig or elsewhere in Bayesian statistics. ### Return value The last line of the model defines the overall type of the model. This last line must be either a return statement or must be a valid probability distribution. For instance, the following valid model: modelA = prob x ~ normal 0 1 y ~ normal x 1 return y is equivalent to: modelB = prob x ~ normal 0 1 normal x 1 The type of the expression passed to return determines the overall type of the model, such that modelA and modelB both have type Prob Real because normal m v has type Prob Real. However, if the return is called within a repeat then the type of value passed to return gets lifted into a List, possibly multiple times for nested repetitions. For instance, univariateLinearRegression has type Prob (List (Real, Real)) and myNestedModel has type Prob (List (List Real)) ### Monads and statistical models The syntax and the semantics of the statistical models in Baysig are derived from the monadic properties of probability distributions. While it is not necessary to understand what a monad is to use Baysig, it helps when building complex models. A monad is a data type m for which we can define operations:  return : a -> t a and  >>= : m a -> (a -> m b) -> m b Notice that m here must be a higher-order type that takes a type parameter to form a concrete type. Types like Real and String cannot be monads — only types like List and Maybe can be monads, because they need an additional type to form the type of a concrete value (a value cannot have a type List, but it can have a type List Real). The type Prob forms a monad, which means that the operations return and >>= are available for probability distributions. return turns a single value into a probability distribution. When sampled, this probability distribution always yields the value that was passed to return. return 3.14 ⇒ 3.14000000 ± 0.00000026 TODO >>= In addition to the existence of these operations, for a type formaing a monad has to saitsfy certain laws. TODO We can now see how the useful function fmap can be defined in terms of return and >>=: fmap f p = p >>= (return . f) = p >>= (\x-> return (f x)) = prob x ~ p return (f x) ## Calling estimate The estimate procedure allows you to go beyond simulating data from models. Instead, it calculates the likely values of the model parameters given observed data. That it, estimate calculates the probability distribution over model parameters given the observed data. estimate must be called at the top level and cannot be called inside let statements or function definitions. The syntax for using esitmate is: parameter_pat <* estimate model_expr observed_data_expr where • parameter_pat is the pattern that will be bound to the probability distribution over the unobserved parameters in the model • model_expr is the expression of the model which must have type Prob a for some type a. • observed_data_expr is the expression for the observed data. None of these have to be primitive variable names. You can compose the model or the observed data using function calls, e.g. myModel distx disty = prob x ~ distx y ~ disty return (x,y) pars <* esitmate (myModel (normal 0 1) (gamma 1 1)) (3.1, 2.3)  In many cases, the type of the data should be identical to the type of the model (wrapped in Prob). However, the type-checking rule for estimate is slightly more relaxed: model_expr must have type Prob t0 and observed_data_expr must have type t1 where t0 and t1 are structurally similar: • a type t is structurally similar to itself • List x is structurally similar to List y if and only if x is structurally similar to y • Two record types are structurally similar if and only if their common fields are all structurally similar This can be used to control what is observed in the model such that a general model can written without knowing exactly which components are observed. TODO: example: stochastic volatility estimate can be used to estimate parameters from new probability distributions that you write yourself. Any elementary probability distribution used must, howver, be associated with a valid log-domain probability density function (PDF). Baysig uses a simple naming convention to associate probability distributions with PDFs. If you introduce a new probability distribution, for instance named myDist, you must also define its PDF in the variable myDistLogPdf. TODO: Example ## Limitations ### Model must have a probability density function. Not every model that can be written use the prob notation or is of a valid type of the form Prob a for some type a can be used in statistical inference with estimate. The limitations in the models that can be used with estimate come from two sources: the first is that models must be associated with a valid probability density function (pdf) for estimate to be able to apply Bayes theorem to it. This is not the case for all models of type Prob a in Baysig. For instance, here is a model that is not assocatiated with a valid probability density function (see below for the reason why this is so): notBayesianModel = prob x ~ normal 0 1 return$ x^2

This model is not associated with a well-defined pdf, because it is not in general possible to calculate the pdf resulting from a non-linear transformations of values drawn from probability distributions. One way to "rescue" this model is to allow a further noise distribution after the non-linear transformation, for instance

bayesianModel = prob
sigma ~ gamma 1 1
x ~ normal 0 1
normal (x^2) sigma

This may or may not be sufficiently close to the model you had in mind.

This limitation of using estimate can be summarized in this rule:

A model passed to estimate must end in a draw or simple combination of draws

According to this rule, a model can end directly in a draw from a probability distribution for which the log-pdf function is defined. For instance, in

model = prob
x ~ uniform 0 1
sigma ~ gamma 1 1
normal x sigma

the last line is itself a probability distribution, so it is OK to use this model in estimate.

If the last line is not itself a probability distribution, it must a combination of draws from such distributions. In the simplest case, you can reference a variable denoting a draw from a probability distribution:

model = prob
x ~ uniform 0 1
sigma ~ gamma 1 1
y ~ normal x sigma
return y

Pairs and records that reference variables which are draws from probability distributions are also simple combinations that can be used in the last line of models passed to estimate. For instance,

model = prob
x ~ uniform 0 1
sigma ~ gamma 1 1
y1 ~ normal x sigma
y2 ~ normal x sigma
return (y1,y2)
model = prob
x ~ uniform 0 1
sigma ~ gamma 1 1
y1 ~ normal x sigma
y2 ~ normal x sigma
return {a=>y1; b=>y2}

are both acceptable models.

In models that use unfold, it is very common that only a portion of the state space is observed. You can use map in the last line of a model to control this:

--- NOTE: CURRENTLY BROKEN - still true?

model = prob
v ~ gamma 1 1
x0 ~ normal 0 0.1
y0 ~ normal 0 0.1
ys ~ unfold 100 (x0,y0) $\(xp,yp) -> prob x ~ normal xp v y ~ normal yp v return (x,y) return$ map fst ys

Here, only the x's in the two-dimensional state space model are observed.

Finally, you can end the model in a repeat. The same rules about ending in a draw or a simple combination of draws apply within repeat loops. For instance,

regress = prob
offset  ~  normal 0 1.0
sigma   ~  gamma 1 1
slope   ~  normal 0.0 1.0
repeat 50  $prob w ~ uniform 0.0 1.0 y ~ normal (offset+slope*w) sigma return$ { foo=>w;bar=>y }

can also be used within estimate.

### No new recursive functions

The second source of limitations is that the implementation of the estimate procedure is still incomplete and does not support as many cases as we'd like. We are actively working on removing these limitations.

Please do not call any recursive functions

We would like to remove this limitation, but it is not clear how feasible it is to do this while maintaining reasonably high performance inference.

### All parameters must be real, vectors or matrices

We do not support integer, boolean or string-valued parameters. We would like to remove this limitation, but it is a lot of work.

### All data must come through estimate

Please do not reference lists, vectors or matrices that are defined in global scope. All observed data should be returned by the model and pass through the second argument to estimate. Numbers, functions or probability distributions are OK.

We will remove this limitation ASAP.

### No local functions

You cannot define or use local function in you model.

badModel = prob
y ~ normal 0 1
f x = 2+1
normal (f y) 1

f x = 2+1

goodModel = prob
y ~ normal 0 1
normal (f y) 1

We will remove this limitation ASAP.

### Prototype implementation

Finally, estimate is prototype software and it will not be hard to find additional cases where it breaks. Please report all bugs to info@bayeshive.com.

## Update

syntax example

use for generating data from model with vague priors

use for posterior predictive

## Fast-forwarding dynamical models

example

what it does under the hood.