Skip to content

Commit

Permalink
Merge pull request #194 from higra/attribute_topological_height
Browse files Browse the repository at this point in the history
Attribute topological height
  • Loading branch information
PerretB authored Apr 29, 2020
2 parents 7e0303d + 4606e35 commit 3ac5f3b
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 31 deletions.
61 changes: 30 additions & 31 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ branches:
- /^\d+\.\d+\.\d+(-\S*)?$/
matrix:
include:
- os: linux
if: tag IS present
services:
- docker
env: BUILD_WHEEL=1 CIBW_BUILD="cp35-*" CIBW_SKIP=*-manylinux1_i686
- os: linux
if: tag IS present
services:
- docker
env: BUILD_WHEEL=1 CIBW_BUILD="cp36-*" CIBW_SKIP=*-manylinux1_i686
- os: linux
if: tag IS present
services:
- docker
env: BUILD_WHEEL=1 CIBW_BUILD="cp37-*" CIBW_SKIP=*-manylinux1_i686
- os: linux
services:
- docker
env: BUILD_WHEEL=1 CIBW_BUILD="cp38-*" CIBW_SKIP=*-manylinux1_i686
- os: osx
if: tag IS present
env: BUILD_WHEEL=1 CIBW_BUILD="cp35-*"
- os: osx
if: tag IS present
env: BUILD_WHEEL=1 CIBW_BUILD="cp36-*"
- os: osx
if: tag IS present
env: BUILD_WHEEL=1 CIBW_BUILD="cp37-*"
- os: osx
env: BUILD_WHEEL=1 CIBW_BUILD="cp38-*"
- os: linux
addons:
apt:
Expand Down Expand Up @@ -38,37 +68,6 @@ matrix:
osx_image: xcode8
compiler: clang
env: HG_USE_TBB=On
- sudo: required
if: tag IS present
services:
- docker
env: BUILD_WHEEL=1 CIBW_BUILD="cp35-*" CIBW_SKIP=*-manylinux1_i686
- sudo: required
if: tag IS present
services:
- docker
env: BUILD_WHEEL=1 CIBW_BUILD="cp36-*" CIBW_SKIP=*-manylinux1_i686
- sudo: required
if: tag IS present
services:
- docker
env: BUILD_WHEEL=1 CIBW_BUILD="cp37-*" CIBW_SKIP=*-manylinux1_i686
- sudo: required
services:
- docker
env: BUILD_WHEEL=1 CIBW_BUILD="cp38-*" CIBW_SKIP=*-manylinux1_i686
- os: osx
if: tag IS present
env: BUILD_WHEEL=1 CIBW_BUILD="cp35-*"
- os: osx
if: tag IS present
env: BUILD_WHEEL=1 CIBW_BUILD="cp36-*"
- os: osx
if: tag IS present
env: BUILD_WHEEL=1 CIBW_BUILD="cp37-*"
- os: osx
env: BUILD_WHEEL=1 CIBW_BUILD="cp38-*"

env:
global:
- MINCONDA_VERSION="latest"
Expand Down
3 changes: 3 additions & 0 deletions doc/source/python/tree_attributes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Tree attributes
attribute_piecewise_constant_Mumford_Shah_energy
attribute_regular_altitudes
attribute_sibling
attribute_topological_height
attribute_tree_sampling_probability
attribute_volume

Expand Down Expand Up @@ -67,6 +68,8 @@ Tree attributes

.. autofunction:: higra.attribute_sibling

.. autofunction:: higra.attribute_topological_height

.. autofunction:: higra.attribute_tree_sampling_probability

.. autofunction:: higra.attribute_volume
20 changes: 20 additions & 0 deletions higra/attribute/tree_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,23 @@ def attribute_tree_sampling_probability(tree, leaf_graph, leaf_graph_edge_weight
leaf_graph_vertex_weights = leaf_graph_vertex_weights / np.sum(leaf_graph_edge_weights)
tree_node_weights = hg.accumulate_sequential(tree, leaf_graph_vertex_weights, hg.Accumulators.sum)
return hg.attribute_children_pair_sum_product(tree, tree_node_weights)


@hg.auto_cache
def attribute_topological_height(tree):
"""
Given a node :math:`n` of :attr:`tree`, the topological height of :math:`n` is the number of edges on the longest
path from the node :math:`n` to a leaf of :attr:`tree`.
The topological height of the leaves is equal to 0.
:param tree: Input tree
:return: a 1d array
"""

res = hg.accumulate_and_add_sequential(tree,
np.ones(tree.num_vertices(), dtype=np.int64),
np.zeros(tree.num_leaves(), dtype=np.int64),
hg.Accumulators.max)

return res
6 changes: 6 additions & 0 deletions test/python/test_attribute/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,12 @@ def test_attribute_tree_sampling_probability_null_model(self):
(Z * Z)
self.assertTrue(np.allclose(ref, res))

def test_topological_height(self):
tree = hg.Tree((6, 6, 9, 9, 7, 8, 10, 8, 10, 10, 10))
res = hg.attribute_topological_height(tree)
ref = (0, 0, 0, 0, 0, 0, 1, 1, 2, 1, 3)
self.assertTrue(np.array_equal(res, ref))


if __name__ == '__main__':
unittest.main()

0 comments on commit 3ac5f3b

Please sign in to comment.