Skip to content

Instantly share code, notes, and snippets.

View jg-you's full-sized avatar
🐢

Jean-Gabriel Young jg-you

🐢
View GitHub Profile
@jg-you
jg-you / dirichlet_process.r
Last active August 29, 2015 14:20
Finite Dirichlet process with N(0,1)
diri <- function(alpha) {
# Sample from the Dirichlet distribution with parameter (vector) alpha
k <- length (alpha)
Z <- rep(0,k)
for(i in 1:k) {
Z[i] <- rgamma(n=1,shape=alpha[i], rate =1)
S <- sum(Z)
P <- Z/S
}
return(P)
@jg-you
jg-you / degree_of_neighbors.py
Created April 13, 2015 20:18
NetworkX: Degree of neighbors, by degree
import networkx as nx
# Mean function (no statistics module in python2)
mean = lambda l: sum(l)/len(l)
# Declare some graph
G = nx.erdos_renyi_graph(200,0.1)
# Prepare raw results container
result = dict()
@jg-you
jg-you / HDF5VL.cpp
Last active August 29, 2015 14:17
HDF5, C interface: From jagged array to variable lenght
// Test data
std::vector< std::vector<int> > jagged_array(3);
jagged_array[0] = {0};
jagged_array[1] = {0, 1, 2, 3};
jagged_array[2] = {0, 1, 2};
hvl_t * X = (hvl_t *)malloc(jagged_array.size() * sizeof(hvl_t))
for (unsigned int i = 0; i < jagged_array.size(); ++i) {
X[i].len = jagged_array[i].size();
int * ptr = (int *) malloc (X[i].len * sizeof(int));