Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_inverse():
"Tests of the matrix inverse"
m = unumpy.matrix([[ufloat((10, 1)), -3.1],
[0, ufloat((3, 0))]])
m_nominal_values = unumpy.nominal_values(m)
# "Regular" inverse matrix, when uncertainties are not taken
# into account:
m_no_uncert_inv = m_nominal_values.I
# The matrix inversion should not yield numbers with uncertainties:
assert m_no_uncert_inv.dtype == numpy.dtype(float)
# Inverse with uncertainties:
m_inv_uncert = m.I # AffineScalarFunc elements
# The inverse contains uncertainties: it must support custom
# operations on matrices with uncertainties:
assert isinstance(m_inv_uncert, unumpy.matrix)
assert type(m_inv_uncert[0, 0]) == uncertainties.AffineScalarFunc
# Checks of the numerical values: the diagonal elements of the
# some arbitrary distribution
y_old = 1. + np.sin(x_old[:-1]*np.pi) / np.ediff1d(x_old)
y_old = unp.uarray(y_old, 0.1*y_old*uniform((m,)))
# rebin
y_new = rebin.rebin(x_old, y_old, x_new, interp_kind='piecewise_constant')
# compute answer here to check rebin
y_new_here = unp.uarray(np.zeros(2), np.zeros(2))
y_new_here[0] = 0.5 * y_old[2] + y_old[3] + y_old[4] + 0.5 * y_old[5]
y_new_here[1] = 0.5 * y_old[5] + y_old[6] + 0.5 * y_old[7]
assert_allclose(unp.nominal_values(y_new),
unp.nominal_values(y_new_here))
# mean or nominal value comparison
assert_allclose(unp.std_devs(y_new),
unp.std_devs(y_new_here))
y_new_ref = unp.uarray(a,a)
y_new_ref[1] = y_old[0] * area_subbins[2] / area_old[0]
y_new_ref[2] = y_old[0] * area_subbins[3] / area_old[0]
y_new_ref[3] = y_old[0] * area_subbins[4] / area_old[0]
y_new_ref[4] = y_old[1] * area_subbins[5] / area_old[1]
y_new_ref[5] = y_old[1] * area_subbins[6] / area_old[1]
y_new_ref[5] += y_old[2] * area_subbins[7] / area_old[2]
y_new_ref[5] += y_old[3] * area_subbins[8] / area_old[3]
# call rebin function
y_new = rebin.rebin(x_old, y_old, x_new, interp_kind=3)
# mean or nominal value comparison
assert_allclose(unp.nominal_values(y_new),
unp.nominal_values(y_new_ref))
# mean or nominal value comparison
assert_allclose(unp.std_devs(y_new),
unp.std_devs(y_new_ref))
v
Bicylce speed.
If you have a flywheel defined, body D, it will completely be
ignored in these results. These results are strictly for the Whipple
bicycle model.
"""
par = self.parameters['Benchmark']
M, C1, K0, K2 = bicycle.benchmark_par_to_canonical(par)
if nominal is True:
return (unumpy.nominal_values(M),
unumpy.nominal_values(C1),
unumpy.nominal_values(K0),
unumpy.nominal_values(K2))
elif nominal is False:
return M, C1, K0, K2
else:
raise ValueError('nominal must be True or False')
evecs : ndarray, shape (n, 4, 4)
eigenvectors
'''
# this allows you to enter a float
try:
speeds.shape
except AttributeError:
speeds = np.array([speeds])
m, n = 4, speeds.shape[0]
evals = np.zeros((n, m), dtype='complex128')
evecs = np.zeros((n, m, m), dtype='complex128')
for i, speed in enumerate(speeds):
A, B = self.state_space(speed)
w, v = np.linalg.eig(unumpy.nominal_values(A))
evals[i] = w
evecs[i] = v
return evals, evecs
steer torque]
If you have a flywheel defined, body D, it will completely be ignored
in these results. These results are strictly for the Whipple bicycle
model.
"""
M, C1, K0, K2 = self.canonical()
g = self.parameters['Benchmark']['g']
A, B = bicycle.ab_matrix(M, C1, K0, K2, speed, g)
if nominal is True:
return (unumpy.nominal_values(A), unumpy.nominal_values(B))
elif nominal is False:
return A, B
else:
raise ValueError('nominal must be True or False')
# Find the zeros
phiTphiZeros = roots(phiTphi, s, multiple=True)
deltaTphiZeros = roots(deltaTphi, s, multiple=True)
phiTdeltaZeros = roots(phiTdelta, s, multiple=True)
deltaTdeltaZeros = roots(deltaTdelta, s, multiple=True)
# Load a bicycle with some parameters and calculate the canonical matrices.
pathToData = '/media/Data/Documents/School/UC Davis/Bicycle Mechanics/BicycleParameters/data'
bicycle = bp.Bicycle('Rigidcl', pathToData=pathToData, forceRawCalc=True)
bicycle.add_rider('Charlie')
#bicycle = bp.Bicycle('Benchmark', pathToData=pathToData)
Mn, C1n, K0n, K2n = bicycle.canonical()
Mn = un.unumpy.nominal_values(Mn)
C1n = un.unumpy.nominal_values(C1n)
K0n = un.unumpy.nominal_values(K0n)
K2n = un.unumpy.nominal_values(K2n)
# Create a dictionary to substitute numerical values.
# These are the benchmark bicycle parameters.
#num = {M[0, 0] : 80.81722,
#M[0, 1] : 2.31941332208709,
#M[1, 0] : 2.31941332208709,
#M[1, 1] : 0.29784188199686,
#K0[0, 0] : -80.95,
#K0[0, 1] : -2.59951685249872,
#K0[1, 0] : -2.59951685249872,
#K0[1, 1] : -0.80329488458618,
#K2[0, 1] : 76.59734589573222,
#K2[1, 1] : 2.65431523794604,
#C1[0, 1] : 33.86641391492494,
#C1[1, 0] : -0.85035641456978,
Steer torque.
v
Bicylce speed.
If you have a flywheel defined, body D, it will completely be
ignored in these results. These results are strictly for the Whipple
bicycle model.
"""
par = self.parameters['Benchmark']
M, C1, K0, K2 = bicycle.benchmark_par_to_canonical(par)
if nominal is True:
return (unumpy.nominal_values(M),
unumpy.nominal_values(C1),
unumpy.nominal_values(K0),
unumpy.nominal_values(K2))
elif nominal is False:
return M, C1, K0, K2
else:
raise ValueError('nominal must be True or False')
if k == 'lC' or k == 'mC' or k == 'dC':
# these are not arrays, so make them one
vn = ones(8, dtype='object') * v
print "Made", k, "into and array"
# rename k
k = k[0] + 'P'
for i, val in enumerate(vn):
if k == 'bikes':
k = 'name'
try:
nom = val.nominal_value
std = val.std_dev()
line = k + ' = ' + str(nom) + '+/-' + str(std) + '\n'
except AttributeError:
try:
nom = unumpy.nominal_values(val)
line = ''
for j, number in enumerate(nom):
line += k + str(j + 1) + ' = ' + str(val[j]) + '\n'
except ValueError:
line = k + ' = ' + str(val) + '\n'
#print shortnames[i], line
measuredFiles[i].write(line)
else:
print "Did not add:", k
print '\n'
for openfile in measuredFiles:
openfile.write('g = 9.81 +/- 0.01\n')
openfile.close()
def _parse_uarray(self, uarray):
from uncertainties import unumpy
values = unumpy.nominal_values(uarray)
errors = unumpy.std_devs(uarray)
return values, errors