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
module BinarySearch where | |
import Data.Array | |
binarySearch :: (Ord a1) => Array Int a1 -> a1 -> Int -> Int -> Maybe Int | |
binarySearch haystack needle lo hi | |
| hi < lo = Nothing | |
| pivot > needle = binarySearch haystack needle lo (mid-1) | |
| pivot < needle = binarySearch haystack needle (mid+1) hi | |
| lo /= mid = binarySearch haystack needle lo mid |
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
{-# LANGUAGE ScopedTypeVariables #-} | |
import Data.Maybe | |
swords :: String -> Bool | |
swords "hello" = True | |
swords "my" = True | |
swords "sam" = True | |
swords _ = False |
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
module MicroKanren where | |
import Data.List (transpose) | |
import Data.Maybe | |
import Control.Monad | |
data Term = Var Int | Atom String | |
deriving (Eq, Show) | |
------------------------------------------ |
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
data { | |
int<lower=0> N; // num individuals | |
int<lower=1> K; // num ind predictors | |
int<lower=1> J; // num groups | |
int<lower=1> L; // num group predictors | |
int<lower=1,upper=J> jj[N]; // group for individual | |
matrix[N, K] x; // individual predictors | |
row_vector[L] u[J]; // group predictors | |
vector[N] y; // outcomes | |
} |
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
data { | |
int<lower=0> N; // num individuals | |
int<lower=1> K; // num ind predictors | |
int<lower=1> J; // num groups | |
int<lower=1> L; // num group predictors | |
int<lower=1,upper=J> jj[N]; // group for individual | |
matrix[N, K] x; // individual predictors | |
matrix[J, L] u; // group predictors | |
vector[N] y; // outcomes | |
} |
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
data { | |
int<lower=0> N; // num individuals | |
int<lower=1> K; // num ind predictors | |
int<lower=1> J; // num groups | |
int<lower=1> L; // num group predictors | |
int<lower=1,upper=J> jj[N]; // group for individual | |
} | |
generated quantities { | |
matrix[K, J] z; |
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
dans.rng = function(N_samp, n_eff, planck_length) { | |
pnorm(rnorm(N_samp, sd=1 + runif(N_samp, -1/sqrt(n_eff), 1/sqrt(n_eff)))) | |
} | |
discrete.dan = function(N_samp, n_eff, pl) { | |
round(pnorm(rnorm(N_samp, sd=1 + runif(N_samp, -1/sqrt(n_eff), 1/sqrt(n_eff)))) * pl) / pl | |
} | |
linear_neff_plots = function(xlab, gen_data, n_samp, n_eff, planck_length) { | |
data = gen_data(n_samp, n_eff, planck_length) | |
bins <- n_eff * c(0.5, 1, 2, 3, 10, 50) |
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
diff --git a/stan/math/prim/mat/fun/log_mix.hpp b/stan/math/prim/mat/fun/log_mix.hpp | |
index 3c7063ba3f..de82cc89b7 100644 | |
--- a/stan/math/prim/mat/fun/log_mix.hpp | |
+++ b/stan/math/prim/mat/fun/log_mix.hpp | |
@@ -125,20 +125,20 @@ typename return_type<T_theta, T_lam>::type log_mix(const T_theta& theta, | |
* @param lambda array containing vectors of log densities. | |
* @return log mixture of densities in specified proportion | |
*/ | |
-template <typename T_theta, typename T_lam> | |
-typename return_type<T_theta, std::vector<Eigen::Matrix<T_lam, -1, 1> > >::type |
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
cdf = function(x, pdf) { | |
sapply(x, function(x) { | |
integrate(pdf, -Inf, x)$value | |
}) | |
} | |
u = cdf(rnorm(1e5), dnorm) | |
hist(u, breaks=100) |
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
#include <vector> | |
#include <functional> | |
#include <Eigen/Dense> | |
#include <algorithm> | |
#include <iostream> | |
// CONFIGURABLE SIZES | |
typedef unsigned int index_t; // determines max expression size | |
typedef double real_t; // basic scalar type |