implemented a function that will be used to provide a generic n-th order, nth-dimension error approximation function

This commit is contained in:
sm
2010-05-04 23:03:07 -06:00
parent c5adab295b
commit 3a1c13bcac
5 changed files with 118 additions and 1 deletions
+28
View File
@@ -3,6 +3,7 @@ from baker.tools import smblog
import numpy as np
import sys
import itertools
from tools import smberror
def get_phis(X, R):
@@ -305,3 +306,30 @@ def run_baker_3D(X, R, S):
}
return answer
def _boxings(n, k):
"""\
source for this function:
http://old.nabble.com/Simple-combinatorics-with-Numpy-td20086915.html
http://old.nabble.com/Re:-Simple-combinatorics-with-Numpy-p20099736.html
"""
seq, i = [n] * k + [0], k
while i:
yield tuple(seq[i] - seq[i+1] for i in xrange(k))
i = seq.index(0) - 1
seq[i:k] = [seq[i] - 1] * (k-i)
def _samples_ur(items, k, offset = 0):
"""Returns k unordered samples (with replacement) from items."""
n = len(items)
for sample in _boxings(k, n):
selections = [[items[i]]*count for i,count in enumerate(sample)]
yield tuple([x + offset for sel in selections for x in sel])
def pattern(power, phicount, offset = 0):
smblog.debug("(power = %s, phicount = %s)" % (power, phicount))
r = []
for i in _samples_ur(range(1, phicount + 1), power, offset):
if not len(set(i)) == 1:
r.append(i)
return r