Пример #1
0
	def test_unaryFunctions(self):
		for func,inOutData in TEST_CASES_UNARY.items():
			print('testing univar_polyops.%s with numpy: ' % func.__name__, end='')
			for output,input in inOutData:
				self.assertTrue(na_eq(na(output), func(na(input))), 'testing %s = %s(%s)' % (output,func.__name__,input))
				print('.', end='')
			print()
Пример #2
0
def add_ids(json_list):
    ids = list(
        map(
            bson.Int64,
            list(
                na([get_max_id()] * len(json_list)) +
                na(list(range(1,
                              len(json_list) + 1))))))
    return list(map(add_id_, list(zip(ids, json_list))))
Пример #3
0
def getFitForN(N):
    a = []
    for i in range(1, N + 1):
        row = []
        for j in range(N - 1, -1, -1):
            row.append(pow(i, j))
        a.append(row)
    a = na(a)
    b = na([sequence(i) for i in range(1, N + 1)])
    coeffs = solve(a, b)
    fit = pv(coeffs, N + 1)
    return fit
Пример #4
0
def get_duplicates(update=False):
    dups, _ = get_duplicates_for_range(1900, 2017)
    duplicates = na(list(map(lambda x: x[0], dups)))
    if not update:
        return duplicates
    with open(duplicate_fname, 'wb') as f:
        np.save(f, duplicates)
    return duplicates
Пример #5
0
def save_processed_pmids():
    existing = get_existing_pmids()
    downloaded = get_downloaded_pmids()
    result = existing.union(downloaded)
    arr_to_save = na(list(result))
    with open(processed_fname, 'wb') as f:
        np.save(f, arr_to_save)
    return result
Пример #6
0
 def get_data_from_dcm(self, idx):
     dcms = []
     parent_path = self.ids[idx]
     for file in os.listdir(parent_path):
         if not file.endswith('dcm'):
             continue
         image, dcm_data = imread(opjoin(parent_path, file))
         if not has_slice_location(dcm_data):
             continue
         dcms.append((image, dcm_data))
     dcms.sort(key=lambda dcm: dcm[1].SliceLocation)
     nodules = parseXML(parent_path)
     id2roi = create_map_from_nodules(nodules)
     imgs = na([dcm[0] for dcm in dcms])
     imgs = imgs[np.newaxis, :]
     bbox = resolve_bbox(na(dcms), id2roi)
     return imgs, bbox
Пример #7
0
def basiccube():
    dir = na([[1,0,0]])
    k = 15
    maxvol = 0.02
    g = dg3d.impedance(dir,k)
    gg = dg3d.planeWaves(dir,k)[0]
    s = dg3d.solver(dg3d.cubemesh(maxvol), 2, 12, k).solve(g)
    v = dg3d.Visualiser(s,gg)
Пример #8
0
def numpysum():
    import time
    n = 1000
    A = numpy.mat(numpy.reshape(range(n*n), (n,n)), dtype=numpy.float64)
    t = []
    t.append(time.time())
    B1 = A + A +A + A
    t.append(time.time())
    A2 = [A,A,A,A]
    t.append(time.time())
    B2 = numpy.sum(A2, axis=0)
    t.append(time.time())
    l = len(A2)
    B3 = numpy.reshape(numpy.dot(numpy.ones(l), numpy.reshape(A2, (l, -1))), (n,n))
    t.append(time.time())
    op = lambda a,b:a+b
    B4 = reduce(op, A2)
    t.append(time.time())
     
    print na(t[1:]) - na(t[:-1])
Пример #9
0
def save_downloaded_pmids():
    downloaded_pmids = set(get_downloaded_pmids_for_range(1900, 2017))
    arr_to_save = na(list(downloaded_pmids))
    with open(downloaded_fname, 'wb') as f:
        np.save(f, arr_to_save)
    return downloaded_pmids
def getU(t):
    if t < 5:
        return u
    elif 20 < t < 22:
        return -u / 2
    else:
        return 0


deltaT = 1
D = 100
M = 1e4  # 1 ton

# system state
F = na([[1, deltaT], [0, M / (M + deltaT * D)]])
# input matrix
G = nvect(.5 * deltaT * deltaT, deltaT)
# observation matrix
H = na([[1, 0]])
# process noise covariance
Q = np.eye(2) * .1
# measurement noise covar.
R = na([100])

# true init state
x_0 = nvect(0, 0)
# assumed init state
x_0_hat = nvect(50, 0)
# assumed init state err covar matrix
P = na([[1000, 0], [0, 1]])
Пример #11
0
from numpy.random import randn
import numpy as np
import matplotlib.pyplot as plt


def nvect(*argv):
    return np.array([argv]).T


cmap = plt.get_cmap("tab20c")
""" process model """
u = 10.  #m/s^2
deltaT = 1e-2

# system state
F = na([[1, deltaT], [0, 1]])
# input matrix
G = nvect(-.5 * deltaT * deltaT, -deltaT)
# observation matrix
H = na([[1, 0]])
""" uncertainty """
n = 2  # number of states
q = 0.5  # std of process
r = 2  # std of measurement
# process noise covariance
Q = q**2 * np.eye(n)  # covariance of process
#measurement noise covar.
R = r**2  # covariance of measurement

#Q=np.zeros(2)
#R=na([4])
Пример #12
0
    A2 = [A,A,A,A]
    t.append(time.time())
    B2 = numpy.sum(A2, axis=0)
    t.append(time.time())
    l = len(A2)
    B3 = numpy.reshape(numpy.dot(numpy.ones(l), numpy.reshape(A2, (l, -1))), (n,n))
    t.append(time.time())
    op = lambda a,b:a+b
    B4 = reduce(op, A2)
    t.append(time.time())
     
    print na(t[1:]) - na(t[:-1])

if __name__ == '__main__':
    print "hello"
    dir = na([[1,0,0]])
    k = 20
    maxvol = 0.04
    print k, maxvol
    g = dg3d.impedance(dir,k)
    gg = dg3d.planeWaves(dir,k)[0]
    s = dg3d.solver(dg3d.cubemesh(maxvol), 4, 10, k)
    
    s.solve(g)
    
    v = dg3d.Visualiser(s,gg)
    v.showuaveragereal()
    
    sys.exit(0)
    
    
Пример #13
0
- Code By Michael Sherif Naguib
- license: MIT open source
- Date: 12/20/18
- @University of Tulsa
- Description: for storing constants of functions...
'''
# ========================== Predefined Transformations =======================
# Predefined Transformations: [MATRIX as [[A,B],[C,D]], SHIFTS as [X,Y], ROTATION ,PROBABILITY]
from numpy import array as na  # NOT NP... NOTE: Numpy Array as na
from math import *

constants = {}

#Barnsley Fern
constants["bfern"] = [
    [na([[0, 0], [0, 0.16]]), na([0, 0]), 0, 0.01],
    [na([[0.85, 0.04], [0 - 0.04, 0.85]]),
     na([0, 1.6]), 0, 0.85],
    [na([[0.2, 0 - 0.26], [0.23, 0.22]]),
     na([0, 1.6]), 0, 0.07],
    [na([[0 - 0.15, 0.28], [0.26, 0.24]]),
     na([0, 0.44]), 0, 0.07]
]

#Rose(like)
constants["rose"] = [
    [na([[0, 0], [0, 0.16]]), na([0, 0]), 0, 0.01],
    [na([[0.85, 0.04], [0 - 0.04, 0.85]]),
     na([0, 1.6]), 45, 0.85],
    [na([[0.2, 0 - 0.26], [0.23, 0.22]]),
     na([0, 1.6]), 3, 0.10],