本文整理汇总了Python中numpy.array_equal函数的典型用法代码示例。如果您正苦于以下问题:Python array_equal函数的具体用法?Python array_equal怎么用?Python array_equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_square_matrices_1
def test_square_matrices_1(self):
op4 = OP4()
# matrices = op4.read_op4(os.path.join(op4Path, fname))
form1 = 1
form2 = 2
form3 = 2
from numpy import matrix, ones, reshape, arange
A1 = matrix(ones((3, 3), dtype="float64"))
A2 = reshape(arange(9, dtype="float64"), (3, 3))
A3 = matrix(ones((1, 1), dtype="float32"))
matrices = {"A1": (form1, A1), "A2": (form2, A2), "A3": (form3, A3)}
for (is_binary, fname) in [(False, "small_ascii.op4"), (True, "small_binary.op4")]:
op4_filename = os.path.join(op4Path, fname)
op4.write_op4(op4_filename, matrices, name_order=None, precision="default", is_binary=False)
matrices2 = op4.read_op4(op4_filename, precision="default")
(form1b, A1b) = matrices2["A1"]
(form2b, A2b) = matrices2["A2"]
self.assertEqual(form1, form1b)
self.assertEqual(form2, form2b)
(form1b, A1b) = matrices2["A1"]
(form2b, A2b) = matrices2["A2"]
(form3b, A3b) = matrices2["A3"]
self.assertEqual(form1, form1b)
self.assertEqual(form2, form2b)
self.assertEqual(form3, form3b)
self.assertTrue(array_equal(A1, A1b))
self.assertTrue(array_equal(A2, A2b))
self.assertTrue(array_equal(A3, A3b))
del A1b, A2b, A3b
del form1b, form2b, form3b
开发者ID:ClaesFredo,项目名称:pyNastran,代码行数:34,代码来源:op4_test.py
示例2: testNegativeDelta
def testNegativeDelta(self):
self.assertTrue(
np.array_equal(self._Range(5, -1, -1), np.array([5, 4, 3, 2, 1, 0])))
self.assertTrue(
np.allclose(self._Range(2.5, 0, -0.5), np.array([2.5, 2, 1.5, 1, 0.5])))
self.assertTrue(
np.array_equal(self._Range(-5, -10, -3), np.array([-5, -8])))
开发者ID:HughKu,项目名称:tensorflow,代码行数:7,代码来源:init_ops_test.py
示例3: test_train
def test_train(self):
# y = x + 0
x1 = np.array([2, 4])
y1 = np.array([2, 4])
m1 = LinearRegression(1)
m1.train(x1, y1, n_iter=1, lr=0.1)
# expected W and b after 1 iteration with lr 0.1
exp_W1 = np.array([1.0])
exp_b1 = 0.3
self.assertTrue(np.array_equal(m1.W, exp_W1))
self.assertAlmostEqual(m1.b[0], exp_b1)
# y = x1 + x2 + 0
x2 = np.array([[2, 2],
[4, 4]])
y2 = np.array([4, 8])
m2 = LinearRegression(2)
m2.train(x2, y2, n_iter=1, lr=0.1)
# expected W and b after 1 iteration with lr 0.1
exp_W2 = np.array([2.0, 2.0])
exp_b2 = 0.6
self.assertTrue(np.array_equal(m2.W, exp_W2))
self.assertAlmostEqual(m2.b[0], exp_b2)
开发者ID:yasumori,项目名称:machine_learning,代码行数:25,代码来源:test_linear_regression.py
示例4: _testFloodFill
def _testFloodFill(SegmentationHelper):
filledMask = SegmentationHelper._floodFill(
testImage, (1, 1), 5, connectivity=8)
assert numpy.array_equal(
filledMask,
numpy.array([
[255, 255, 0, 0, 0, 0],
[255, 255, 255, 255, 0, 0],
[0, 255, 0, 255, 255, 255],
[0, 255, 255, 255, 0, 0],
[0, 0, 255, 0, 0, 0],
[0, 0, 0, 255, 0, 0]
], dtype=numpy.uint8))
assert numpy.array_equal(testImage, originalTestImage)
# Now, with connectivity=4
filledMask = SegmentationHelper._floodFill(
testImage, (1, 1), 5, connectivity=4)
assert numpy.array_equal(
filledMask,
numpy.array([
[255, 255, 0, 0, 0, 0],
[255, 255, 255, 255, 0, 0],
[0, 255, 0, 255, 255, 255],
[0, 255, 255, 255, 0, 0],
[0, 0, 255, 0, 0, 0],
[0, 0, 0, 0, 0, 0]
], dtype=numpy.uint8))
assert numpy.array_equal(testImage, originalTestImage)
开发者ID:ImageMarkup,项目名称:isic-archive,代码行数:29,代码来源:segmentation_helper_test.py
示例5: test_Moster13SmHm_behavior
def test_Moster13SmHm_behavior():
"""
"""
default_model = Moster13SmHm()
mstar1 = default_model.mean_stellar_mass(prim_haloprop = 1.e12)
ratio1 = mstar1/3.4275e10
np.testing.assert_array_almost_equal(ratio1, 1.0, decimal=3)
default_model.param_dict['n10'] *= 1.1
mstar2 = default_model.mean_stellar_mass(prim_haloprop = 1.e12)
assert mstar2 > mstar1
default_model.param_dict['n11'] *= 1.1
mstar3 = default_model.mean_stellar_mass(prim_haloprop = 1.e12)
assert mstar3 == mstar2
mstar4_z1 = default_model.mean_stellar_mass(prim_haloprop = 1.e12, redshift=1)
default_model.param_dict['n11'] *= 1.1
mstar5_z1 = default_model.mean_stellar_mass(prim_haloprop = 1.e12, redshift=1)
assert mstar5_z1 != mstar4_z1
mstar_realization1 = default_model.mc_stellar_mass(prim_haloprop = np.ones(1e4)*1e12, seed=43)
mstar_realization2 = default_model.mc_stellar_mass(prim_haloprop = np.ones(1e4)*1e12, seed=43)
mstar_realization3 = default_model.mc_stellar_mass(prim_haloprop = np.ones(1e4)*1e12, seed=44)
assert np.array_equal(mstar_realization1, mstar_realization2)
assert not np.array_equal(mstar_realization1, mstar_realization3)
measured_scatter1 = np.std(np.log10(mstar_realization1))
model_scatter = default_model.param_dict['scatter_model_param1']
np.testing.assert_allclose(measured_scatter1, model_scatter, rtol=1e-3)
default_model.param_dict['scatter_model_param1'] = 0.3
mstar_realization4 = default_model.mc_stellar_mass(prim_haloprop = np.ones(1e4)*1e12, seed=43)
measured_scatter4 = np.std(np.log10(mstar_realization4))
np.testing.assert_allclose(measured_scatter4, 0.3, rtol=1e-3)
开发者ID:bsipocz,项目名称:halotools,代码行数:35,代码来源:test_smhm_components.py
示例6: test_A
def test_A(self):
cid0 = CORD2R()
Lx = 2.
Ly = 0.
Lz = 3.
Fy = 1.
origin = array([-Lx, 0., -Lz])
z_axis = origin + array([0., 0., 1.])
xz_plane = origin + array([1., 0., 1.])
rid = 0
data = [1, rid] + list(origin) + list(z_axis) + list(xz_plane)
Fxyz = [0., -Fy, 0.]
Mxyz = [0., 0., 0.]
cid_new = CORD2R(data=data)
model = None
Fxyz_local, Mxyz_local = TransformLoadWRT(Fxyz, Mxyz, cid0, cid_new,
model, is_cid_int=False)
r = array([Lx, Ly, Lz])
F = array([0., -Fy, 0.])
M = cross(r, F)
self.assertTrue(array_equal(Fxyz_local, F)), "expected=%s actual=%s" % (F, Fxyz_local)
self.assertTrue(array_equal(Mxyz_local, cross(r, F))), "expected=%s actual=%s" % (M, Mxyz_local)
开发者ID:ClaesFredo,项目名称:pyNastran,代码行数:25,代码来源:test_coords.py
示例7: test_Period
def test_Period():
p = Period(numbers[0:2], units[0])
assert sa_asserts.sa_access(p)
assert i_asserts.interval(p, start=numbers[0], stop=numbers[1])
assert np.array_equal(p.info['start'], p.start)
assert np.array_equal(p.info['stop'], p.stop)
assert np.array_equal(p.info['length'], p.length)
开发者ID:G-Node,项目名称:Datajongleur,代码行数:7,代码来源:test_beanbags.py
示例8: test_find_optimal_paras_rf
def test_find_optimal_paras_rf(self):
# first, load the file
f = h5py.File('tuning_ref_results/NIS_results.hdf5', 'r+')
# get the filter
grp = f['ICA/tuning']
wica = grp['Wica'][:] # should be
# get the reference results
ica_optx = grp.attrs['ica_optx']
ica_opty = grp.attrs['ica_opty']
ica_optfreq = grp.attrs['ica_optfreq']
ica_optor = grp.attrs['ica_optor']
ica_optphase = grp.attrs['ica_optphase']
# now shuffle this Wica. 1024x256
wica = transpose_c_and_f(wica.T)
# get result
result = tuning.find_optimal_paras_rf(w=wica, legacy=True)
# print result
self.assertTrue(np.allclose(result['optx'], ica_optx))
self.assertTrue(np.allclose(result['opty'], ica_opty))
self.assertTrue(np.array_equal(result['optfreq'], ica_optfreq))
self.assertTrue(np.array_equal(result['optor'], ica_optor))
self.assertTrue(np.array_equal(result['optphase'], ica_optphase))
f.close()
开发者ID:leelabcnbc,项目名称:early-vision-toolbox,代码行数:26,代码来源:test_tuning.py
示例9: _read_volume_info
def _read_volume_info(fobj):
"""An implementation of nibabel.freesurfer.io._read_volume_info, since old
versions of nibabel (<=2.1.0) don't have it.
"""
volume_info = dict()
head = np.fromfile(fobj, '>i4', 1)
if not np.array_equal(head, [20]): # Read two bytes more
head = np.concatenate([head, np.fromfile(fobj, '>i4', 2)])
if not np.array_equal(head, [2, 0, 20]):
warnings.warn("Unknown extension code.")
return volume_info
volume_info['head'] = head
for key in ['valid', 'filename', 'volume', 'voxelsize', 'xras', 'yras',
'zras', 'cras']:
pair = fobj.readline().decode('utf-8').split('=')
if pair[0].strip() != key or len(pair) != 2:
raise IOError('Error parsing volume info.')
if key in ('valid', 'filename'):
volume_info[key] = pair[1].strip()
elif key == 'volume':
volume_info[key] = np.array(pair[1].split()).astype(int)
else:
volume_info[key] = np.array(pair[1].split()).astype(float)
# Ignore the rest
return volume_info
开发者ID:adykstra,项目名称:mne-python,代码行数:26,代码来源:fixes.py
示例10: test_setPairMask
def test_setPairMask(self):
'''check different setPairMask arguments.
'''
bdc = self.bdc
dall = bdc(self.nickel)
bdc.maskAllPairs(False)
self.assertEqual(0, len(bdc(self.nickel)))
for i in range(4):
bdc.setPairMask(0, i, True)
dst0a = bdc(self.nickel)
bdc.setPairMask(range(4), 0, True, others=False)
dst0b = bdc(self.nickel)
self.assertTrue(numpy.array_equal(dst0a, dst0b))
bdc.maskAllPairs(False)
bdc.setPairMask(0, -7, True)
dst0c = bdc(self.nickel)
self.assertTrue(numpy.array_equal(dst0a, dst0c))
bdc.maskAllPairs(False)
bdc.setPairMask(0, 'all', True)
dst0d = bdc(self.nickel)
self.assertTrue(numpy.array_equal(dst0a, dst0d))
bdc.setPairMask('all', 'all', False)
self.assertEqual(0, len(bdc(self.nickel)))
bdc.setPairMask('all', range(4), True)
dall2 = bdc(self.nickel)
self.assertTrue(numpy.array_equal(dall, dall2))
self.assertRaises(ValueError, bdc.setPairMask, 'fooo', 2, True)
self.assertRaises(ValueError, bdc.setPairMask, 'aLL', 2, True)
return
开发者ID:XiaohaoYang,项目名称:diffpy.srreal,代码行数:29,代码来源:testbondcalculator.py
示例11: test_tz_localize_dti
def test_tz_localize_dti(self):
from pandas.tseries.offsets import Hour
dti = DatetimeIndex(start='1/1/2005', end='1/1/2005 0:00:30.256',
freq='L')
dti2 = dti.tz_localize('US/Eastern')
dti_utc = DatetimeIndex(start='1/1/2005 05:00',
end='1/1/2005 5:00:30.256', freq='L',
tz='utc')
self.assert_(np.array_equal(dti2.values, dti_utc.values))
dti3 = dti2.tz_convert('US/Pacific')
self.assert_(np.array_equal(dti3.values, dti_utc.values))
dti = DatetimeIndex(start='11/6/2011 1:59',
end='11/6/2011 2:00', freq='L')
self.assertRaises(pytz.AmbiguousTimeError, dti.tz_localize,
'US/Eastern')
dti = DatetimeIndex(start='3/13/2011 1:59', end='3/13/2011 2:00',
freq='L')
self.assertRaises(pytz.AmbiguousTimeError, dti.tz_localize,
'US/Eastern')
开发者ID:andreas-h,项目名称:pandas,代码行数:25,代码来源:test_timezones.py
示例12: test_tabulate
def test_tabulate():
scalar_no_units = lambda wlen: math.sqrt(wlen)
scalar_with_units = lambda wlen: math.sqrt(wlen.value)
array_no_units = lambda wlen: 1. + np.sqrt(wlen)
array_with_units = lambda wlen: np.sqrt(wlen.value)
add_units = lambda fval: (lambda wlen: fval(wlen) * u.erg)
wlen = np.arange(1, 3) * u.Angstrom
for v in True, False:
# Test each mode without any function return units.
f1 = tabulate_function_of_wavelength(scalar_no_units, wlen, v)
assert f1[1] == None
f2 = tabulate_function_of_wavelength(scalar_with_units, wlen, v)
assert f2[1] == None
f3 = tabulate_function_of_wavelength(array_no_units, wlen, v)
assert f3[1] == None
f4 = tabulate_function_of_wavelength(scalar_with_units, wlen, v)
assert f4[1] == None
# Now test with return units.
g1 = tabulate_function_of_wavelength(
add_units(scalar_no_units), wlen, v)
assert np.array_equal(f1[0], g1[0]) and g1[1] == u.erg
g2 = tabulate_function_of_wavelength(
add_units(scalar_with_units), wlen, v)
assert np.array_equal(f2[0], g2[0]) and g2[1] == u.erg
g3 = tabulate_function_of_wavelength(
add_units(array_no_units), wlen, v)
assert np.array_equal(f3[0], g3[0]) and g3[1] == u.erg
g4 = tabulate_function_of_wavelength(
add_units(scalar_with_units), wlen, v)
assert np.array_equal(f4[0], g4[0]) and g4[1] == u.erg
开发者ID:sbailey,项目名称:speclite,代码行数:30,代码来源:test_filters.py
示例13: test_StatesMatrixMerger
def test_StatesMatrixMerger():
val_mat1_text = list(tools.ngram(test_text_df["text"].values[0], [1]))
val_mat2_text = list(tools.ngram(test_text_df["text"].values[1], [1]))
val_mat1 = ValuesMatrix(val_mat1_text, force2d="as_col")
val_mat2 = ValuesMatrix(val_mat2_text, force2d="as_col")
idx_data_mat1 = val_mat1.build_index_data_matrix()
idx_data_mat2 = val_mat2.build_index_data_matrix()
idx_data_mat1_old_ref_data = idx_data_mat1.states_matrix._ref_data
idx_data_mat2_old_ref_data = idx_data_mat2.states_matrix._ref_data
old_idx_data_mat1 = idx_data_mat1.index_matrix.copy()
old_idx_data_mat2 = idx_data_mat2.index_matrix.copy()
assert len(idx_data_mat1_old_ref_data) > 0
assert len(idx_data_mat2_old_ref_data) > 0
states_mats_merger = StatesMatrixMerger(idx_data_mat1.states_matrix,
idx_data_mat2.states_matrix)
assert len(states_mats_merger._unique_states_matrix_ids) > 1
states_mats_merger.update()
assert len(idx_data_mat1_old_ref_data) == 0
assert len(idx_data_mat2_old_ref_data) == 0
assert id(idx_data_mat1.states_matrix) == id(idx_data_mat2.states_matrix)
assert len(idx_data_mat2.states_matrix._ref_data) > 1
assert np.array_equal(idx_data_mat1.index_matrix, old_idx_data_mat1)
assert not np.array_equal(idx_data_mat2.index_matrix, old_idx_data_mat2)
assert np.array_equal(idx_data_mat1._data, val_mat1)
assert np.array_equal(idx_data_mat2._data, val_mat2)
开发者ID:GingerHugo,项目名称:PlaYdata,代码行数:34,代码来源:test_states_mergers.py
示例14: test_two_triangles_without_edges
def test_two_triangles_without_edges():
grid = two_triangles_with_depths()
grid.edges = None
grid.save_as_netcdf("2_triangles_without_edges.nc")
# read it back in and check it out
ug = UGrid.from_ncfile("2_triangles_without_edges.nc", load_data=True)
assert ug.nodes.shape == (4, 2)
assert ug.nodes.shape == grid.nodes.shape
# not ideal to pull specific values out, but how else to test?
assert np.array_equal(ug.nodes[0, :], (0.1, 0.1))
assert np.array_equal(ug.nodes[-1, :], (3.1, 2.1))
assert np.array_equal(ug.nodes, grid.nodes)
assert ug.faces.shape == grid.faces.shape
assert ug.edges is None
depths = find_depths(ug)
assert depths.data.shape == (4,)
assert depths.data[0] == 1
assert depths.attributes["units"] == "unknown"
开发者ID:rsignell-usgs,项目名称:pyugrid,代码行数:25,代码来源:test_find_uvar.py
示例15: test_n_largest_area_contours_images__with_invert
def test_n_largest_area_contours_images__with_invert(self):
# given
image = cv2.imread("./images/SnipNLargestAreaContours/"
"test_n_largest_area_contours_image__with_invert__input_image.png",
cv2.IMREAD_GRAYSCALE)
n = 2
invert_flag = True
snip_n_largest_area_contours = SnipNLargestAreaContours(image, n, invert_flag)
expected_largest_contour_image_1 = cv2.imread(
"./images/SnipNLargestAreaContours/test_n_largest_area_contours_images__with_invert__snipped_image_1.png",
flags=cv2.IMREAD_GRAYSCALE)
expected_largest_contour_image_2 = cv2.imread(
"./images/SnipNLargestAreaContours/test_n_largest_area_contours_images__with_invert__snipped_image_2.png",
flags=cv2.IMREAD_GRAYSCALE)
expected_n_largest_area_contours_images = [expected_largest_contour_image_1, expected_largest_contour_image_2]
# when
actual_n_largest_area_contours_images = snip_n_largest_area_contours.n_largest_area_contours_images
# that
self.assertEqual(np.array_equal(actual_n_largest_area_contours_images[0],
expected_n_largest_area_contours_images[0]), True)
self.assertEqual(np.array_equal(actual_n_largest_area_contours_images[1],
expected_n_largest_area_contours_images[1]), True)
开发者ID:bbaattaahh,项目名称:acss,代码行数:26,代码来源:TestSnipNLargestAreaContours.py
示例16: _serialize_volume_info
def _serialize_volume_info(volume_info):
"""An implementation of nibabel.freesurfer.io._serialize_volume_info, since
old versions of nibabel (<=2.1.0) don't have it."""
keys = ['head', 'valid', 'filename', 'volume', 'voxelsize', 'xras', 'yras',
'zras', 'cras']
diff = set(volume_info.keys()).difference(keys)
if len(diff) > 0:
raise ValueError('Invalid volume info: %s.' % diff.pop())
strings = list()
for key in keys:
if key == 'head':
if not (np.array_equal(volume_info[key], [20]) or np.array_equal(
volume_info[key], [2, 0, 20])):
warnings.warn("Unknown extension code.")
strings.append(np.array(volume_info[key], dtype='>i4').tostring())
elif key in ('valid', 'filename'):
val = volume_info[key]
strings.append('{} = {}\n'.format(key, val).encode('utf-8'))
elif key == 'volume':
val = volume_info[key]
strings.append('{} = {} {} {}\n'.format(
key, val[0], val[1], val[2]).encode('utf-8'))
else:
val = volume_info[key]
strings.append('{} = {:0.10g} {:0.10g} {:0.10g}\n'.format(
key.ljust(6), val[0], val[1], val[2]).encode('utf-8'))
return b''.join(strings)
开发者ID:adykstra,项目名称:mne-python,代码行数:28,代码来源:fixes.py
示例17: testReadWrite
def testReadWrite(self):
"""Test ScalarEncoder Cap'n Proto serialization implementation."""
originalValue = self._l.encode(1)
proto1 = ScalarEncoderProto.new_message()
self._l.write(proto1)
# Write the proto to a temp file and read it back into a new proto
with tempfile.TemporaryFile() as f:
proto1.write(f)
f.seek(0)
proto2 = ScalarEncoderProto.read(f)
encoder = ScalarEncoder.read(proto2)
self.assertIsInstance(encoder, ScalarEncoder)
self.assertEqual(encoder.w, self._l.w)
self.assertEqual(encoder.minval, self._l.minval)
self.assertEqual(encoder.maxval, self._l.maxval)
self.assertEqual(encoder.periodic, self._l.periodic)
self.assertEqual(encoder.n, self._l.n)
self.assertEqual(encoder.radius, self._l.radius)
self.assertEqual(encoder.resolution, self._l.resolution)
self.assertEqual(encoder.name, self._l.name)
self.assertEqual(encoder.verbosity, self._l.verbosity)
self.assertEqual(encoder.clipInput, self._l.clipInput)
self.assertTrue(numpy.array_equal(encoder.encode(1), originalValue))
self.assertEqual(self._l.decode(encoder.encode(1)),
encoder.decode(self._l.encode(1)))
# Feed in a new value and ensure the encodings match
result1 = self._l.encode(7)
result2 = encoder.encode(7)
self.assertTrue(numpy.array_equal(result1, result2))
开发者ID:leotam,项目名称:cupic,代码行数:34,代码来源:scalar_test.py
示例18: test_save_and_load
def test_save_and_load(self):
states = "NR"
alphabet = "AGTC"
p_initial = array([1.0, 0.0])
p_transition = array([[0.75, 0.25], [0.25, 0.75]])
p_emission = array(
[[0.45, 0.36, 0.06, 0.13], [0.24, 0.18, 0.12, 0.46]])
markov_model_save = MarkovModel.MarkovModel(
states,
alphabet,
p_initial,
p_transition,
p_emission)
handle = StringIO()
MarkovModel.save(markov_model_save, handle)
handle.seek(0)
markov_model_load = MarkovModel.load(handle)
self.assertEqual(''.join(markov_model_load.states), states)
self.assertEqual(''.join(markov_model_load.alphabet), alphabet)
self.assertTrue(array_equal(markov_model_load.p_initial, p_initial))
self.assertTrue(array_equal
(markov_model_load.p_transition, p_transition))
self.assertTrue(array_equal(markov_model_load.p_emission, p_emission))
开发者ID:BioGeek,项目名称:biopython,代码行数:25,代码来源:test_MarkovModel.py
示例19: test_rasterize_supported_dtype
def test_rasterize_supported_dtype(basic_geometry):
""" Supported data types should return valid results """
with Env():
supported_types = (
('int16', -32768),
('int32', -2147483648),
('uint8', 255),
('uint16', 65535),
('uint32', 4294967295),
('float32', 1.434532),
('float64', -98332.133422114)
)
for dtype, default_value in supported_types:
truth = np.zeros(DEFAULT_SHAPE, dtype=dtype)
truth[2:4, 2:4] = default_value
result = rasterize(
[basic_geometry],
out_shape=DEFAULT_SHAPE,
default_value=default_value,
dtype=dtype
)
assert np.array_equal(result, truth)
assert np.dtype(result.dtype) == np.dtype(truth.dtype)
result = rasterize(
[(basic_geometry, default_value)],
out_shape=DEFAULT_SHAPE
)
if np.dtype(dtype).kind == 'f':
assert np.allclose(result, truth)
else:
assert np.array_equal(result, truth)
开发者ID:EricAlex,项目名称:rasterio,代码行数:35,代码来源:test_features.py
示例20: test_mle
def test_mle(self):
states = ["0", "1", "2", "3"]
alphabet = ["A", "C", "G", "T"]
training_data = [("AACCCGGGTTTTTTT", "001112223333333"),
("ACCGTTTTTTT", "01123333333"),
("ACGGGTTTTTT", "01222333333"),
("ACCGTTTTTTTT", "011233333333"), ]
training_outputs = array([[0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3], [
0, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3], [0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3], [0, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3]])
training_states = array([[0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3], [
0, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3], [0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3], [0, 1, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3]])
p_initial = array([1., 0., 0., 0.])
p_transition = array([[0.2, 0.8, 0., 0.],
[0., 0.5, 0.5, 0.],
[0., 0., 0.5, 0.5],
[0., 0., 0., 1.]])
p_emission = array(
[[0.66666667, 0.11111111, 0.11111111, 0.11111111],
[0.08333333, 0.75, 0.08333333, 0.08333333],
[0.08333333, 0.08333333, 0.75, 0.08333333],
[0.03125, 0.03125, 0.03125, 0.90625]])
p_initial_out, p_transition_out, p_emission_out = MarkovModel._mle(
len(states), len(alphabet), training_outputs, training_states, None, None, None)
self.assertTrue(
array_equal(around(p_initial_out, decimals=3), around(p_initial, decimals=3)))
self.assertTrue(
array_equal(around(p_transition_out, decimals=3), around(p_transition, decimals=3)))
self.assertTrue(
array_equal(around(p_emission_out, decimals=3), around(p_emission, decimals=3)))
开发者ID:BioGeek,项目名称:biopython,代码行数:30,代码来源:test_MarkovModel.py
注:本文中的numpy.array_equal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论