def sans_benchmark(request): r"""Sassena output containing 1000 I(Q) profiles for the hiAPP centroids. Yields ------ dict 'profiles' : HDF5 handle to the file containing the I(Q) profiles 'property_list' : list of SansProperty instances, one for each leaf 'tree_with_no_property' : cnextend.Tree with random distances among leafs and without included properties. """ # setup or initialization handle = h5py.File(os.path.join(data_dir, 'sans', 'profiles.h5'), 'r') profiles = handle['fqt'] n_leafs = len(profiles) # Create a node tree. # m is a 1D compressed matrix of distances between leafs m = np.random.random(int(n_leafs * (n_leafs - 1) / 2)) z = linkage(m) tree = cnextend.Tree(z) # values is a list of SansProperty instances, one for each tree leaf values = list() for i in range(tree.nleafs): sans_property = idprop.SansProperty() sans_property.from_sassena(handle, index=i) values.append(sans_property) def teardown(): handle.close() request.addfinalizer(teardown) return dict(profiles=handle, property_list=values, tree_with_no_property=tree)
def benchmark(): z = np.loadtxt(os.path.join(data_dir, 'linkage_matrix')) return {'z': z, 'tree': cnextend.Tree(z), 'nnodes': 44757, 'nleafs': 22379, 'simple_property': [SimpleProperty(i) for i in range(22379)], }
def test_from_linkage_matrix(self, benchmark): t = cnx.Tree() t.from_linkage_matrix(benchmark['z'], node_class=hierarchy.ClusterNode) r = t.root assert hasattr(r, 'parent') is False t.from_linkage_matrix(benchmark['z'], node_class=cnx.ClusterNodeX) r = t.root assert r.parent is None assert len(t) == benchmark['nnodes']
def small_tree(): n_leafs = 9 a = np.arange(n_leafs) dist_mat = squareform(np.square(a - a[:, np.newaxis])) z = linkage(dist_mat, method='complete') return {'dist_mat': dist_mat, 'z': z, 'tree': cnextend.Tree(z), 'simple_property': [SimpleProperty(i) for i in range(n_leafs)], }
def benchmark(): z = np.loadtxt(os.path.join(data_dir, 'linkage_matrix')) t = cnextend.Tree(z) n_leafs = 22379 # Instantiate scalar properties for the leaf nodes, then propagate # up the tree sc = np.random.normal(loc=100.0, size=n_leafs) sc_p = [idprop.ScalarProperty(name='sc', y=s) for s in sc] idprop.propagator_size_weighted_sum(sc_p, t) return { 'z': z, 'tree': t, 'nnodes': 44757, 'nleafs': n_leafs, 'simple_property': [SimpleProperty(i) for i in range(22379)], }