影响力最大化——最常用的模型IC和LT模型以及python实现

本文介绍了两种主要的社交网络传播模型:IC模型(独立级联模型)和LT模型(线性阈值模型)。IC模型通过设定每条边的传播概率来模拟信息在社交网络中的传播过程;而LT模型则为每个节点设定了一个激活阈值,当邻居节点的激活概率总和超过该阈值时,节点被激活。文章详细解释了这两种模型的工作原理及模拟过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、IC模型(独立级联模型)

        红色为处于激活态的种子节点,每条边都有一个传播概率p,激活的节点会以p的概率去激活邻居节点,一个节点有且只有一次机会去激活另一个节点,如果失败,则不再去尝试激活这个节点。

def preprocess(G):
    p = 0
    directedGraph = nx.DiGraph()
    for u in G.nodes():
        for v in G.neighbors(u):
            if (v != u):
                #propProb = G.number_of_edges(u, v) / G.in_degree(v)
                propProb = G.number_of_edges(u, v) / G.degree(v)
                directedGraph.add_edge(u, v, pp=propProb)
                #p += propProb
                #print(propProb)
    #print('平均阈值:', p/2939)
    return directedGraph
def simulate(G, seedNode, propProbability):
    newActive = True
    currentActiveNodes = copy.deepcopy(seedNode)
    newActiveNodes = set()
    activatedNodes = copy.deepcopy(seedNode)  # Biar ga keaktivasi 2 kali
    influenceSpread = len(seedNode)

    while (newActive):
        for node in currentActiveNodes:
            for neighbor in G.neighbors(node):  # Harus dicek udah aktif apa belom, jangan sampe ngaktifin yang udah aktif
                if (neighbor not in activatedNodes):
                    if (G[node][neighbor]['pp']>propProbability): #flipCoin(propProbability)
                        newActiveNodes.add(neighbor)
                        activatedNodes.append(neighbor)
        influenceSpread += len(newActiveNodes)
        if newActiveNodes:
            currentActiveNodes = list(newActiveNodes)
            newActiveNodes = set()
        else:
            newActive = False
    # print("activatedNodes",len(activatedNodes),activatedNodes)
    return influenceSpread


def flipCoin(probability):
    return random.random() < probability

二、LT模型(线性阈值模型)

        红色节点为处于激活状态的节点,每个节点会有一个激活阈值,如果该节点的处于激活态的邻居节点的激活概率相加大于这个节点的激活阈值,则该节点被激活,每个节点会有多次机会被激活。

def weight(G, u, v):
    if G.has_edge(u, v):
        return G[u][v]['weight']
    else:
        return 0

# LT传播模型
def simulate(G, seedNode,threshold_active):
    # Set Random threshold for every node ~ [0,1]
    # nodeThresholds = {}
    # for node in G.nodes():
    #     nodeThresholds[node] = random.uniform(0, 1)
    # Set predefined threshold for every node ~ threshold_active [0,1]
    nodeThresholds = {}
    for node in G.nodes():
        nodeThresholds[node] = threshold_active

    nodeValues = {}
    for node in G.nodes():
        nodeValues[node] = 0

    newActive = True
    currentActiveNodes = copy.deepcopy(seedNode)
    newActiveNodes = set()
    activatedNodes = copy.deepcopy(seedNode)  # Prevent from activating node twice
    influenceSpread = len(seedNode)

    while (newActive):
        for node in currentActiveNodes:
            for neighbor in G.neighbors(node):
                if (neighbor not in activatedNodes):
                    nodeValues[neighbor] += weight(G, node, neighbor)
                    if (nodeValues[neighbor] >= nodeThresholds[neighbor]):
                        newActiveNodes.add(neighbor)
                        activatedNodes.append(neighbor)
        influenceSpread += len(newActiveNodes)
        if newActiveNodes:
            currentActiveNodes = list(newActiveNodes)
            newActiveNodes = set()
        else:
            newActive = False
    return influenceSpread

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值