影响力传播的线性阈值模型:

网络中连接任意两个节点u,v之间的边都有权重,任意一个节点它的各个邻居节点的边的权重之和为1,即

N(v):neighbors of v.

网络中的节点分为已激活节点和未激活节点,每个节点都有一个自己的激活阈值Θ(每个节点的激活阈值可以不同,且现实情况下社交网络的各个用户的激活阈值一般不相同,有的用户活跃,阈值低,容易受人影响,而有的用户较沉默,阈值高)。未被激活的节点v受所有与之相邻且已被激活的节点u的影响。当未激活节点v与所有已被激活的邻居节点的边的权重之和达到或超过激活阈值Θ时,节点v就会被激活。

即当满足条件:

Na(v):active neighbors of v.

v被激活之后,它也会以同样的方式影响它自己的未被激活的邻居节点。这样会有越来越多的,满足激活条件的节点被激活,直到最后再也没有新的节点被激活了,激活过程才会停止。

上述过程被称为影响力传播的线性阈值模型(Linear Threshold Model),传播过程停止时最终被激活的节点的数量被称为影响力的传播范围(Influence Spread)。

无向无权图的线性阈值模型的Java实现:

public int beginDiffusionProcess(ArrayList<Node> graph,ArrayList<Integer> activeNodeIds,int lastInfSpread)
{
//Mark the active neighbors of each node.
for(Node nd:graph)
{
for(Node n:nd.neighbors)
{
if(activeNodeIds.contains(n.nodeId))
{
n.setActive(true);
}
}
} //Determine whether each node is activated or not.
for(Node nd:graph)
{
int activeNeighbor_Num=0;
for(Node n:nd.neighbors)
{
if(n.isActive())
{
activeNeighbor_Num++;
}
}
if (activeNeighbor_Num/(nd.neighbors.size()*1.0)>=nd.getThreshold())//如果是带权图,这里要修改
{
nd.setActive(true);
activeNodeIds.add(nd.nodeId);
}
}
//Get the influence spread of the current step.
int infSpread=0;
for(Node n:graph)
{
if(n.isActive())
{
infSpread++;
}
}
//If it converges,stop the diffusion process,else continue the next step.
if(lastInfSpread==infSpread)
return infSpread;
else
return beginDiffusionProcess(graph,activeNodeIds,infSpread);
}

下面的代码调用上述方法,获取最终的Influence Spread:

public int GetInfSpread(ArrayList<Node> graph)
{
ArrayList<Integer> activeNodeIds=new ArrayList<Integer>();
     //this.dimensions是已经被激活的种子节点,是某一个类的静态属性,类型为ArrayList<Node>,这些节点会尝试激活它们的邻居节点。
for(Node n:this.dimensions)
{
activeNodeIds.add(n.nodeId);
}
int lastInfSpread=0;
return beginDiffusionProcess(graph, activeNodeIds,lastInfSpread);
}

其他相关的代码:

Node.java

import java.util.ArrayList;

public class Node implements Comparable<Node>
{
public int nodeId;
public ArrayList<Node> neighbors = new ArrayList<Node>();
private boolean b_isActive = false;
private double threshold = 0.0; public Node(int nodeId, double threshold)
{
this.nodeId = nodeId;
this.threshold = threshold;
} public int neighbors_num()
{
return this.neighbors.size();
} public void setActive(boolean isActive)
{
this.b_isActive = isActive;
} public boolean isActive(){
return this.b_isActive;
}
public double getThreshold(){
return this.threshold;
}
// Sort nodes by (out)degree
public int compareTo(Node anotherNode)
{
if (this.neighbors != null && anotherNode.neighbors != null)
{
// reverse order
return anotherNode.neighbors_num() - this.neighbors_num();
// positive order
// return this.neighbors_num()-anotherNode.neighbors_num();
}
return 0;
}
}

Java实现线性阈值模型(Linear Threshold Model)的更多相关文章

  1. [zz] 混合高斯模型 Gaussian Mixture Model

    聚类(1)——混合高斯模型 Gaussian Mixture Model http://blog.csdn.net/jwh_bupt/article/details/7663885 聚类系列: 聚类( ...

  2. 生成模型(Generative Model)和 判别模型(Discriminative Model)

    引入 监督学习的任务就是学习一个模型(或者得到一个目标函数),应用这一模型,对给定的输入预测相应的输出.这一模型的一般形式为一个决策函数Y=f(X),或者条件概率分布P(Y|X). 监督学习方法又可以 ...

  3. 从损失函数优化角度:讨论“线性回归(linear regression)”与”线性分类(linear classification)“的联系与区别

    1. 主要观点 线性模型是线性回归和线性分类的基础 线性回归和线性分类模型的差异主要在于损失函数形式上,我们可以将其看做是线性模型在多维空间中“不同方向”和“不同位置”的两种表现形式 损失函数是一种优 ...

  4. 开始 Keras 序列模型(Sequential model)

    开始 Keras 序列模型(Sequential model) 序列模型是一个线性的层次堆栈. 你可以通过传递一系列 layer 实例给构造器来创建一个序列模型. The Sequential mod ...

  5. 计算广告学-多点归因模型(Multi-Touch Attribution Model)

    计算广告学中的一个重要的问题是, 如果用户产生了一次转化(conversion, 比如购买, 注册等), 且该用户在转化之前看过大量不同频道(比如搜索, 展示, 社交等等)的广告, 那么我们如何确定是 ...

  6. 生成模型(Generative Model)Vs 判别模型(Discriminative Model)

      概率图分为有向图(bayesian network)与无向图(markov random filed).在概率图上可以建立生成模型或判别模型.有向图多为生成模型,无向图多为判别模型. 判别模型(D ...

  7. CSS学习笔记——视觉格式化模型 visual formatting model

    CSS 视觉格式化模型(visual formatting model)是用来处理文档并将它显示在视觉媒体上的机制.他有一套既定的规则(也就是W3C规范),规定了浏览器该怎么处理每一个盒子.以下内容翻 ...

  8. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

  9. 关于JAVA中的static方法、并发问题以及JAVA运行时内存模型

    一.前言 最近在工作上用到了一个静态方法,跟同事交流的时候,被一个问题给问倒了,只怪基础不扎实... 问题大致是这样的,“在多线程环境下,静态方法中的局部变量会不会被其它线程给污染掉?”: 我当时的想 ...

随机推荐

  1. SQL中使用or影响性能的解决办法

    近期做了一个存储过程,执行时发现非常的慢,竟然需要6.7秒! 经排查,发现时间主要都耗在了其中一段查询语句上.这个语句用于查出结构相同的两个表中,其中两个字段的任一个字段数据相同的记录. 例如,A表的 ...

  2. RecycleView 实现多布局

    最近的一个新需求,简单描述下吧: 需求: 目标样式如图所示,我们需要根据需求动态添加网关和设备. 目标有了下面就是怎么实现了.首先我们选用的是RecycleView 那么主要目标就成了 在recycl ...

  3. 前端性能优化---yahoo军规

    一.尽可能减少HTTP请求数 二.使用CDN(内容分发网络) 三.添加Expire/Cache-Control头 四.启用Gzip压缩 五.将CSS放在页面最上面 六.将Script放在页面最下面 七 ...

  4. java-读取javabean中所有属性和属性的类型

    /** * java读取文件中的属性类型 * @param model * @return * @throws Exception */ public static Map<String,Str ...

  5. 定制sqlmap tamper脚本

    前言 渗透测试过程中遇到注入点常常丢到sqlmap中进行测试,假如网站有waf,sqlmap便无法直接注入了. 测试 在测试某个项目的过程中,一个页面的aid参数,习惯性的提交 and 1=1发现直接 ...

  6. Jackson 通过自定义注解来控制json key的格式

    Jackson 通过自定义注解来控制json key的格式 最近我这边有一个需求就是需要把Bean中的某一些特殊字段的值进行替换.而这个替换过程是需要依赖一个第三方的dubbo服务的.为了使得这个转换 ...

  7. php+swoole+websocket

    //创建websocket服务器对象,监听0.0.0.0:9502端口 $ws = new swoole_websocket_server("0.0.0.0", 9502); // ...

  8. DOM解析XML报错:Content is not allowed in prolog

    报错内容为: Content is not allowed in prolog. Nested exception: Content is not allowed in prolog. 网上所述总结来 ...

  9. DirectX runtime

    DirectX 9.0 runtime etc https://www.microsoft.com/en-us/download/details.aspx?id=7087 DirectX 11 run ...

  10. ReportServices如何在一页中将报表分成两列显示

    创建两个数据集 DataSet1    DataSet2 DataSet1 SELECT   TOP                    (SELECT   (COUNT(*) + 1) / 2 A ...