Skip to content

Commit

Permalink
Deprecate lin weighting
Browse files Browse the repository at this point in the history
  • Loading branch information
dustalov committed Jul 26, 2024
1 parent a995010 commit 097696e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions chinese_whispers/chinese_whispers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import math
import random
import warnings
from collections import defaultdict
from math import log2
from operator import itemgetter
Expand Down Expand Up @@ -72,6 +73,11 @@ def linear_weighting(graph: Graph[T], node: T, neighbor: T) -> float:
return cast(WeightDict, graph[node][neighbor]).get("weight", 1.) / graph.degree[neighbor]


def lin_weighting(graph: Graph[T], node: T, neighbor: T) -> float: # noqa: D103
warnings.warn("This function is deprecated, please use linear instead of lin", DeprecationWarning, stacklevel=2)
return linear_weighting(graph, node, neighbor)


def log_weighting(graph: Graph[T], node: T, neighbor: T) -> float:
"""
Calculate the edge weight using the logarithm weighting schema.
Expand All @@ -95,7 +101,8 @@ def log_weighting(graph: Graph[T], node: T, neighbor: T) -> float:
"""Shortcuts for the node weighting functions."""
WEIGHTING: dict[str, Callable[[Graph[T], T, T], float]] = {
"top": top_weighting,
"lin": linear_weighting,
"lin": lin_weighting,
"linear": linear_weighting,
"log": log_weighting,
}

Expand Down Expand Up @@ -123,7 +130,7 @@ def resolve_weighting(

def chinese_whispers(
graph: Graph[T],
weighting: Literal["top", "lin", "log"] | Callable[[Graph[T], T, T], float] = "top",
weighting: Literal["top", "lin", "linear", "log"] | Callable[[Graph[T], T, T], float] = "top",
iterations: int = 20,
ignore: set[T] | None = None,
seed: int | None = None,
Expand Down

0 comments on commit 097696e

Please sign in to comment.