add_dissimilarity_weight_to_edges#
- add_dissimilarity_weight_to_edges(domain, network_name='default_network', edge_weight_name='new weight', label_name=None, dissimilarity_function=None)#
Adds edge weight to all connected nodes that is valued as a dissimilarity of node features. Node features can be provided as a label in the domain or as an array of values representing features for each node and are compared using a dissimilarity 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.
- dissimilarity_functioncallable, optional
A function that takes a feature distance and returns a dissimilarity 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: (invDistScale*feature_distance)/(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 dissimilarity 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.