def clustering_coefficient_weighted(user, interaction=None):
    matrix = matrix_undirected_weighted(user, interaction=interaction)
    weights = [weight for g in matrix for weight in g if weight is not None]
    if len(weights) == 0:
        return None
    max_weight = max(weights)
    triplet_weight = 0
    for a, b in combinations(range(len(matrix)), 2):
        a_b, a_c, b_c = matrix[a][b], matrix[a][0], matrix[b][0]
        if a_b is None or a_c is None or b_c is None:
            continue
        if a_b and a_c and b_c:
            triplet_weight += (a_b * a_c * b_c) ** (1 / 3) / max_weight
    d_ego = sum(1 for i in matrix[0] if i > 0)
    return 2 * triplet_weight / (d_ego * (d_ego - 1)) if d_ego > 1 else 0