This file contains 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
'''Pool adjacent violators algorithm for (column-)monotone matrix factorization. | |
Applies the PAV algorithm to column factors of a matrix factorization: | |
Given: M = W.V' | |
Returns: V_proj, a projected version of V such that M[i] is monotone decreasing | |
for all i. | |
Author: Wesley Tansey | |
Date: May 2019 | |
''' |
This file contains 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
# Fit using a simple EM algorithm | |
# observations are x | |
# weights are w (must be same length as x) | |
# returns (r, p) | |
# r - dispersion parameter | |
# p - probability of success | |
weightedNegBinomFit <- function(x, w, maxsteps=30) | |
{ | |
sum.wx = sum(x*w) | |
sum.w = sum(w) |
This file contains 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
import tensorflow as tf | |
def unpack_cholesky(q, ndims): | |
# Build the lower-triangular Cholesky from the flat buffer (assumes q shape is [batchsize, cholsize]) | |
chol_diag = tf.nn.softplus(q[:,:ndims]) | |
chol_offdiag = q[:,ndims:] | |
chol_rows = [] | |
chol_start = 0 | |
chol_end = 1 | |
for i in xrange(ndims): |
This file contains 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 <set> | |
#include <iostream> | |
class A | |
{ | |
std::set<int> s; | |
public: | |
A() { s.insert(0); s.insert(1); } | |
std::set<int> getSet() { return s; } |
This file contains 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 plot_with_bands(graph_title, means, bands, series, xvals=None, xlabel=None, ylabel=None, subtitle=None, filename='results.pdf'): | |
colors = ['blue','red','green', 'black', 'yellow', 'orange', 'purple', 'brown'] # max 8 lines | |
print 'means: {0} bands: {1}'.format(means.shape, bands.shape) | |
assert(means.shape == bands.shape) | |
assert(xvals is None or xvals.shape[0] == means.shape[1]) | |
assert(means.shape[1] <= len(colors)) | |
if xvals is None: | |
xvals = np.arange(means.shape[0]) | |
ax = plt.subplot(111) | |
plt.ticklabel_format(axis='y', style='plain', useOffset=False) |
This file contains 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
import random | |
import math | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def acf(x, length=35): | |
return np.array([1] + [np.corrcoef(x[:-i], x[i:])[0,1] for i in range(1,length)]) | |
# The number of samples to observe | |
n = 100 |
This file contains 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
class A(object): | |
def __init__(self, myvar = {}): | |
self.myvar = myvar | |
a1 = A() | |
a1.myvar['foo'] = 1 | |
a2 = A() | |
a2.myvar['bar'] = 2 | |
This file contains 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
class A(object): | |
def __init__(self, myvar = {}): | |
self.myvar = myvar | |
a1 = A() | |
a1.myvar['foo'] = 1 | |
a2 = A() | |
a2.myvar['bar'] = 2 |
This file contains 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
double[] inputs = ... | |
double[] desiredOutputs = ... | |
// Get the neural network | |
var network = ((FastCyclicNetwork)blackbox; | |
// Perform backpropagation through time | |
network.Train(inputs, desiredOutputs); |
This file contains 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
/// <summary> | |
/// Saves all phenotypic progress back to the genomes. | |
/// </summary> | |
private void PerformLamarkianEvolution(IList<TGenome> genomeList, Func<IAgent, FastCyclicNetwork> networkSelector) | |
{ | |
for (int i = 0; i < _agents.Length; i++) | |
{ | |
var agent = _agents[i]; | |
// Get the network for this teacher |