
def test_formula_transform():
    """
    Check if variables can be added/multiplied/transformed.
    The result should be a formula that can be plugged into a model.
    """
    from mle import var, par

    x = var('x')
    a = par('a')
    b = par('b')

    formula = a * x**2 + b

def test_simple_fit():
    """
    Check if generating/fitting Gaussian data works
    """
    from mle import Normal, var, par
    import theano.tensor as T
    import numpy as np

    x = var('x')
    mu = par('mu')
    sigma = par('sigma')

    dist = Normal(x, mu, sigma)
    np.random.seed(42)
    data = dist.sample(1e6, {'mu': 0, 'sigma': 1})
    results = dist.fit({'x': data}, {'mu': 1, 'sigma': 2}, method='L-BFGS-B')

def test_linear_regression():
    """
    Check if fitting a linear model works
    """
    from mle import Normal, var, par
    import theano.tensor as T
    import numpy as np

    x = var('x')
    y = var('y')

    a = par('a')
    b = par('b')
    sigma = par('sigma')

    dist = Normal(y, a * x + b, sigma)
    np.random.seed(42)

    xs = linspace(0, 1, 20)
    ys = dist.sample(20, {'x': xs, 'a': 1, 'b': 0, 'sigma': 0.5})

    results = dist.fit({'x': xs, 'y': ys}, {'a': 2, 'b': 1, 'sigma': 1})



@@ -110,33 +110,22 @@
 sult
- should be a formula that
+ing expression
  can
@@ -179,21 +179,21 @@
 import v
-ar, p
+ec, v
 ar%0A%0A    
@@ -189,34 +189,34 @@
 , var%0A%0A    x = v
-ar
+ec
 ('x')%0A    a = pa
@@ -205,33 +205,33 @@
 ec('x')%0A    a = 
-p
+v
 ar('a')%0A    b = 
@@ -222,33 +222,33 @@
 ar('a')%0A    b = 
-p
+v
 ar('b')%0A%0A    for
@@ -281,156 +281,1028 @@
 est_
-simple_fit():%0A    %22%22%22%0A    Check if generating/fitting Gaussian data works%0A    %22%22%22%0A    from mle import Normal, var, par%0A    import theano.tensor as T
+const():%0A    %22%22%22%0A    Check if parameters can be set to be constant.%0A    %22%22%22%0A    from mle import var, vec, Normal%0A    import numpy as np%0A    x = vec('x', observed=True)%0A    mu = var('mu', const=True)%0A    sigma = var('sigma')%0A%0A    model = Normal(x, mu, sigma)%0A    np.random.seed(42)%0A    data = model.sample(200, %7B'mu': 0, 'sigma': 1%7D)%0A%0A    results = model.fit(data, %7B'mu': 1, 'sigma'%7D)%0A    assert(results.x%5B'mu'%5D == 1)%0A%0A@raises(ValueError)%0Adef test_error_on_illegal_bound():%0A    %22%22%22%0A    Check if exception is raised when user specifies illegal bound.%0A    Some distributions automatically apply certain bounds.%0A    Example: sigma %3E 0 for the Normal distribution.%0A    If a user-specified bound conflicts with that, an exception should be thrown.%0A    %22%22%22%0A    from mle import vec, var%0A%0A    x = vec('x', observed=True)%0A    mu = var('mu')%0A    sigma = var('sigma', lower=-1)%0A%0A    Normal(x, mu, sigma)%0A%0Adef test_simple_fit():%0A    %22%22%22%0A    Check if generating/fitting Gaussian data works%0A    %22%22%22%0A    from mle import Normal, vec, var
 %0A   
@@ -1327,30 +1327,45 @@
 p%0A%0A    x = v
-ar
+ec
 ('x'
+, observed=True
 )%0A    mu = p
@@ -1363,17 +1363,17 @@
    mu = 
-p
+v
 ar('mu')
@@ -1377,33 +1377,33 @@
 u')%0A    sigma = 
-p
+v
 ar('sigma')%0A%0A   
@@ -1532,19 +1532,12 @@
 fit(
-%7B'x': 
 data
-%7D
 , %7B'
@@ -1660,83 +1660,237 @@
 orks
+.
 %0A    
-%22%22%22%0A    from mle import Normal, var, par%0A    import theano.tensor as T
+This requires several things to work properly:%0A        - Passing expressions to distributions%0A        - Generating with certain fixed observed values%0A        - Fitting in general%0A    %22%22%22%0A    from mle import Normal, vec, var
 %0A   
@@ -1923,14 +1923,29 @@
  = v
-ar
+ec
 ('x'
+, observed=True
 )%0A  
@@ -1955,14 +1955,29 @@
  = v
-ar
+ec
 ('y'
+, observed=True
 )%0A%0A 
@@ -2130,18 +2130,20 @@
 20)%0A    
-ys
+data
  = dist.
@@ -2191,24 +2191,44 @@
 ma': 0.5%7D)%0A%0A
+    data%5B'x'%5D = xs%0A%0A
     results 
@@ -2242,26 +2242,12 @@
 fit(
-%7B'x': xs, 'y': ys%7D
+data
 , %7B'

Add some new API ideas to tests