summaryrefslogtreecommitdiff
path: root/src/python/doc/barycenter_user.rst
blob: 83e9bebbeab4d63a9c184d16732475a0a70bf16b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
:orphan:

.. To get rid of WARNING: document isn't included in any toctree

Barycenter user manual
================================
Definition
----------

.. include:: barycenter_sum.inc

This implementation is based on ideas from "Frechet means for distribution of 
persistence diagrams", Turner et al. 2014.

Function
--------
.. autofunction:: gudhi.barycenter.lagrangian_barycenter


Basic example
-------------

This example computes the Frechet mean (aka Wasserstein barycenter) between 
four persistence diagrams.
It is initialized on the 4th diagram.
As the algorithm is not convex, its output depends on the initialization and 
is only a local minimum of the objective function.
Initialization can be either given as an integer (in which case the i-th 
diagram of the list is used as initial estimate) or as a diagram. 
If None, it will randomly select one of the diagram of the list 
as initial estimate.
Note that persistence diagrams must be submitted as 
(n x 2) numpy arrays and must not contain inf values.

.. testcode::

    import gudhi.barycenter
    import numpy as np

    dg1 = np.array([[0.2, 0.5]])
    dg2 = np.array([[0.2, 0.7]])
    dg3 = np.array([[0.3, 0.6], [0.7, 0.8], [0.2, 0.3]])
    dg4 = np.array([])
    pdiagset = [dg1, dg2, dg3, dg4]
    bary = gudhi.barycenter.lagrangian_barycenter(pdiagset=pdiagset,init=3)

    message = "Wasserstein barycenter estimated:"    
    print(message)
    print(bary)

The output is:

.. testoutput::

    Wasserstein barycenter estimated:
    [[0.27916667 0.55416667]
     [0.7375     0.7625    ]
     [0.2375     0.2625    ]]