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 numpy as np | |
import numpy.ma as ma | |
# Create a 3x3 array in regular numpy | |
a = np.arange(9).reshape((3,3)) | |
# Get the middle row | |
b = a[1] | |
# Change the middle value in the middle row |
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
function format(s, args...) | |
# Python-style string formatting with floating point support | |
# Note that this is 1-based to be more Julian | |
result = deepcopy(s) | |
for (i, x) in enumerate(args) | |
q = Regex("{$i(:\.([0-9])+f)?}") | |
next = result | |
for m in eachmatch(q, result) | |
val = x | |
if m.captures[2] != nothing |
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
''' | |
Implementation of the ADMM convergence rate SDP from Nishihara et al., | |
ICML 2015, equation 11. | |
Code by Wesley Tansey and Sanmi Koyejo | |
7/31/2015 | |
''' | |
import cvxpy as cvx | |
import numpy as np |
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
97=proba1[32] | |
51=proba2[32*256+35] | |
44=proba2[32*256+38] | |
51=proba2[32*256+39] | |
40=proba2[32*256+48] | |
35=proba2[32*256+49] | |
37=proba2[32*256+50] | |
51=proba2[32*256+51] | |
44=proba2[32*256+52] | |
44=proba2[32*256+53] |
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 |
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
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
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
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) |
OlderNewer