Created
          April 11, 2017 11:56 
        
      - 
      
- 
        Save dsuess/ad46faa1a7b461ba4b1aa9f96185584c to your computer and use it in GitHub Desktop. 
    Haar Distribution in PyMC3
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def HaarDistribution(name, dim, model=None): | |
| def transform(x): | |
| pi = np.pi | |
| def component(i): | |
| result = T.cos(pi * x[i]) | |
| for j in range(i): | |
| result *= T.sin(pi * x[j]) | |
| return result | |
| result = [component(i) for i in range(dim - 2)] | |
| z = T.sin(pi * x[0]) | |
| for i in range(1, dim - 2): | |
| z *= T.sin(pi * x[i]) | |
| result += [z * T.cos(2 * pi * x[dim - 2])] | |
| result += [z * T.sin(2 * pi * x[dim - 2])] | |
| return T.as_tensor_variable(result) | |
| angles = pm.distributions.Uniform('angles', shape=dim - 1) | |
| return pm.Deterministic(name, transform(angles), model=model) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Not the prettiest nor the most pythonic, but it works ;)