Extending Pyrea

Pyrea has been designed to be customisable and extensible. For example Pyrea can be extended by using, for example, custom clustering algorimths in your workflows.

Custom Clustering Algorithms

When you create a view, it must have an associated clustering algorithm.

Normally, views are created one of the built in clustering methods, such as follows:

Creating a view
 1    import pyrea
 2
 3    data = [[1,2,3],
 4            [4,5,6],
 5            [7,8,9]]
 6
 7    c = ClusterMethod('ward')
 8
 9    v = pyrea.View(data, c)
10
11    #or, more simply:
12    v = pyrea.View(data, pyrea.ClusterMethod('ward'))

The built in methods derive from SciKit-Learn, and can be determined printing pyrea.CLUSTER_METHODS:

Viewing Pyrea’s built in clustering algorimths.
1    import pyrea
2
3    print(pyrea.CLUSTER_METHODS)
4
5    # Outputs
6    ['ward', 'complete', 'single', 'average', 'random_method']

However, you may wish to supply your own algorithm to your view and within your workflow.

To do this, create your own ClusterMethod type, as follows:

Creating a custom clustering algorithm
1    import pyrea
2
3    class CustomClusterMethod(pyrea.ClusterMethod):
4        def __init__():
5            super().__init__()
6            # Your implementation here
7            pass

If your implementation is of type ClusterMethod then you can do the following:

Using a custom ClusterMethod class
 1    import pyrea
 2
 3    # Assuming you have defined your custom class as above:
 4
 5    data = [[1,2,3],
 6            [4,5,6],
 7            [7,8,9]]
 8
 9    c = CustomClusterMethod()
10
11    v = pyrea.View(data, c)

More details to follow…