pyclustering.cluster.ema.ema_observer Class Reference

Observer of EM algorithm for collecting algorithm state on each step. More...

Public Member Functions

def __init__ (self)
 Initializes EM observer.
 
def __len__ (self)
 
def get_iterations (self)
 
def get_evolution_means (self)
 
def get_evolution_covariances (self)
 
def get_evolution_clusters (self)
 
def notify (self, means, covariances, clusters)
 This method is used by the algorithm to notify observer about changes where the algorithm should provide new values: means, covariances and allocated clusters. More...
 

Detailed Description

Observer of EM algorithm for collecting algorithm state on each step.

It can be used to obtain whole picture about clustering process of EM algorithm. Allocated clusters, means and covariances are stored in observer on each step. Here an example of usage:

from pyclustering.cluster.ema import ema, ema_observer
from pyclustering.utils import read_sample
from pyclustering.samples.definitions import SIMPLE_SAMPLES
# Read data from text file.
sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3)
# Create EM observer.
observer = ema_observer()
# Create EM algorithm to allocated four clusters and pass observer to it.
ema_instance = ema(sample, 4, observer=observer)
# Run clustering process.
ema_instance.process()
# Print amount of steps that were done by the algorithm.
print("EMA steps:", observer.get_iterations())
# Print evolution of means and covariances.
print("Means evolution:", observer.get_evolution_means())
print("Covariances evolution:", observer.get_evolution_covariances())
# Print evolution of clusters.
print("Clusters evolution:", observer.get_evolution_clusters())
# Print final clusters.
print("Allocated clusters:", observer.get_evolution_clusters()[-1])

Definition at line 235 of file ema.py.

Member Function Documentation

◆ __len__()

def pyclustering.cluster.ema.ema_observer.__len__ (   self)
Returns
(uint) Amount of iterations that were done by the EM algorithm.

Definition at line 283 of file ema.py.

◆ get_evolution_clusters()

def pyclustering.cluster.ema.ema_observer.get_evolution_clusters (   self)
Returns
(list) Allocated clusters on each step of clustering.

Definition at line 315 of file ema.py.

◆ get_evolution_covariances()

def pyclustering.cluster.ema.ema_observer.get_evolution_covariances (   self)
Returns
(list) Covariance matrix (or variance in case of one-dimensional data) of each cluster on each step of clustering.

Definition at line 307 of file ema.py.

◆ get_evolution_means()

def pyclustering.cluster.ema.ema_observer.get_evolution_means (   self)
Returns
(list) Mean of each cluster on each step of clustering.

Definition at line 299 of file ema.py.

◆ get_iterations()

def pyclustering.cluster.ema.ema_observer.get_iterations (   self)
Returns
(uint) Amount of iterations that were done by the EM algorithm.

Definition at line 291 of file ema.py.

◆ notify()

def pyclustering.cluster.ema.ema_observer.notify (   self,
  means,
  covariances,
  clusters 
)

This method is used by the algorithm to notify observer about changes where the algorithm should provide new values: means, covariances and allocated clusters.

Parameters
[in]means(list): Mean of each cluster on currect step.
[in]covariances(list): Covariances of each cluster on current step.
[in]clusters(list): Allocated cluster on current step.

Definition at line 323 of file ema.py.


The documentation for this class was generated from the following file: