影响力最大化——最常用的模型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

爬虫Python学习是指学习如何使用Python编程语言来进行网络爬取数据提取的过程。Python是一种简单易学且功能强大的编程语言,因此被广泛用于爬虫开发。爬虫是指通过编写程序自动抓取网页上的信息,可以用于数据采集、数据分析、网站监测等多个领域。 对于想要学习爬虫的新手来说,Python是一个很好的入门语言。Python的语法简洁易懂,而且有丰富的第三方库工具,如BeautifulSoup、Scrapy等,可以帮助开发者更轻松地进行网页解析数据提取。此外,Python还有很多优秀的教程学习资源可供选择,可以帮助新手快速入门并掌握爬虫技能。 如果你对Python编程有一定的基础,那么学习爬虫并不难。你可以通过观看教学视频、阅读教程、参与在线课程等方式来学习。网络上有很多免费付费的学习资源可供选择,你可以根据自己的需求学习风格选择适合自己的学习材料。 总之,学习爬虫Python需要一定的编程基础,但并不难。通过选择合适的学习资源不断实践,你可以逐步掌握爬虫的技能,并在实际项目中应用它们。 #### 引用[.reference_title] - *1* *3* [如何自学Python爬虫? 零基础入门教程](https://blog.youkuaiyun.com/zihong523/article/details/122001612)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [新手小白必看 Python爬虫学习路线全面指导](https://blog.youkuaiyun.com/weixin_67991858/article/details/128370135)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值