add_similarity_weight_to_edges#

add_similarity_weight_to_edges(domain, network_name='default_network', edge_weight_name='new weight', label_name=None, similarity_function=None)#

Adds edge weight to all connected nodes that is valued as a similarity of node features. Node features are provided label in the domain and are compared using a similarity function.

Parameters:
domainobject

A muspan domain object.

network_namestr, optional

The name of a network stored in the muspan domain object, defaults to ‘default_network’.

edge_weight_namestr, optional

Name given to new edge weights, defaults to ‘new weight’.

label_namestr or array-like, optional

A name of a label existing in the domain used to compute dissimilarity between adjacent objects.

similarity_functioncallable, optional

A function that takes a feature distance and returns a similarity value, defaults to None.

similarity_functioncallable, optional

A function that takes a feature distance and returns a similarity value, defaults to None. If None, a default function is used that scales the feature distance to a value between 0 and 1 and is of the form: (1)/(1+invDistScale*feature_distance) where invDistScale is 4 divided by the maximum feature distance between any two nodes in the network.

Raises:
RuntimeError

If the network name is not in the list of generated networks. If the node feature label is not in the list of labels. If the node feature vector has a different length than the number of nodes in the network. If the similarity function provided is not callable.

Notes

The function assumes that the node features are either categorical or continuous and calculates feature distance accordingly. For categorical features, the feature distance is 1 if the features are different and 0 if they are the same. For continuous features, the feature distance is the absolute difference between the feature values.