Skip to content

Commit 57ffa22

Browse files
authored
Marginal gain list update (#24)
1 parent 9a716bf commit 57ffa22

8 files changed

Lines changed: 174 additions & 130 deletions

File tree

CITATION.cff

Lines changed: 0 additions & 15 deletions
This file was deleted.

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,31 @@ avg = total / n_sim
7272
### Advanced Usage
7373
See the [documentation](https://eliotwrobson.github.io/CyNetDiff/examples/activated/).
7474

75+
## Citation
76+
77+
If you use this code in your research, please use the following citation:
78+
```bibtex
79+
@article{DBLP:journals/pvldb/RobsonRU24,
80+
author = {Eilot W. Robson and
81+
Dhemath Reddy and
82+
Abhishek Kumar Umrawal},
83+
title = {CyNetDiff: {A} Python Library for Accelerated Implementation of Network
84+
Diffusion Models},
85+
journal = {Proc. {VLDB} Endow.},
86+
volume = {17},
87+
number = {12},
88+
pages = {4409--4412},
89+
year = {2024},
90+
url = {https://www.vldb.org/pvldb/vol17/p4409-umrawal.pdf},
91+
timestamp = {Thu, 19 Sep 2024 13:09:38 +0200},
92+
biburl = {https://dblp.org/rec/journals/pvldb/RobsonRU24.bib},
93+
bibsource = {dblp computer science bibliography, https://dblp.org}
94+
}
95+
```
96+
7597
## Project Status
7698

77-
This project is still considered in an alpha stage of development. As such,
99+
This project is still considered in a beta stage of development. As such,
78100
the API could still change to facilitate easier community adoption.
79101

80102
All feedback is greatly appreciated!

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cynetdiff"
3-
version = "0.1.14"
3+
version = "0.1.15"
44
description = "A fast network diffusion library"
55
authors = ["Eliot W. Robson <eliot.robson24@gmail.com>"]
66
license = "MIT"

src/cynetdiff/models.pxd

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from libcpp.deque cimport deque as cdeque
22
from libcpp.unordered_set cimport unordered_set as cset
33
from libcpp.unordered_map cimport unordered_map as cmap
4+
from libcpp.vector cimport vector as cvector
45

56
cdef class DiffusionModel:
67
cdef readonly float[:] payoffs
@@ -10,8 +11,7 @@ cdef class DiffusionModel:
1011
cpdef void advance_until_completion(self)
1112
cdef float _compute_payoff(
1213
self,
13-
cset[unsigned int]& new_seeds,
14-
cset[unsigned int]& old_seeds,
14+
cdeque[unsigned int]& activated_nodes,
1515
float[:] payoffs,
1616
)
1717

@@ -32,16 +32,17 @@ cdef class IndependentCascadeModel(DiffusionModel):
3232
cdef cset[unsigned int] original_seeds
3333

3434
cdef int _activation_succeeds(self, unsigned int edge_idx) except -1 nogil
35+
3536
cdef int _advance_model(
3637
self,
3738
cdeque[unsigned int]& work_deque,
3839
cset[unsigned int]& seen_set
3940
) except -1 nogil
4041

41-
cdef float _compute_marginal_gain(
42+
cdef cvector[float] _compute_marginal_gains(
4243
self,
43-
cset[unsigned int]& original_seeds,
44-
unsigned int new_seed,
44+
cvector[unsigned int]& original_seeds,
45+
cvector[unsigned int]& new_seeds,
4546
unsigned int num_trials
4647
)
4748

@@ -69,10 +70,10 @@ cdef class LinearThresholdModel(DiffusionModel):
6970
cmap[unsigned int, float]& buckets,
7071
) except -1 nogil
7172

72-
cdef float _compute_marginal_gain(
73+
cdef cvector[float] _compute_marginal_gains(
7374
self,
74-
cset[unsigned int]& original_seeds,
75-
unsigned int new_seed,
75+
cvector[unsigned int]& original_seeds,
76+
cvector[unsigned int]& new_seeds,
7677
unsigned int num_trials,
7778
float[:] _node_thresholds
7879
)

src/cynetdiff/models.pyi

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,27 +111,28 @@ class IndependentCascadeModel(DiffusionModel):
111111
payoffs: t.Optional[array.array] = None,
112112
_edge_probabilities: t.Optional[array.array] = None,
113113
) -> None: ...
114-
def compute_marginal_gain(
115-
self, seed_set: t.Iterable[int], new_seed: t.Optional[int], num_trials: int
116-
) -> float:
114+
def compute_marginal_gains(
115+
self, seed_set: t.Iterable[int], new_seeds: t.List[int], num_trials: int
116+
) -> t.List[float]:
117117
"""
118-
Computes the marginal gain of adding new_seed on top of seed_set. Averages over the given number
119-
of trials. If new_seed is None, just gives the average influence of the seed set. Computes
120-
marginal gain using payoffs if set.
118+
Computes the marginal gain of adding each seed in new_seeds on top of the original seed_set.
119+
Averages over num_trials number of randomized activations.
121120
122121
Parameters
123122
----------
124123
seed_set : Iterable[int]
125124
An iterable representing the current seed set. Can be empty.
126-
new_seed : int
127-
New seed set to compute marginal gain on.
125+
new_seeds : List[int]
126+
New seeds to compute marginal gains on. Can be empty.
128127
num_trials : int
129128
Number of randomized trials to run.
130129
131130
Returns
132131
----------
133-
float
134-
Average marginal gain in profit over all trials.
132+
List[float]
133+
List containing computed marginal gains. First entry is average influence of the
134+
starting seed set. Following entries are marginal gains with the addition of vertices
135+
from new_seeds in order. Has length len(new_seeds)+1.
135136
"""
136137

137138
class LinearThresholdModel(DiffusionModel):
@@ -171,30 +172,31 @@ class LinearThresholdModel(DiffusionModel):
171172
"""
172173
...
173174

174-
def compute_marginal_gain(
175+
def compute_marginal_gains(
175176
self,
176177
seed_set: t.Iterable[int],
177-
new_seed: t.Optional[int],
178+
new_seeds: t.List[int],
178179
num_trials: int,
179180
*,
180181
_node_thresholds: t.Optional[array.array] = None,
181-
) -> float:
182+
) -> t.List[float]:
182183
"""
183-
Computes the marginal gain of adding new_seed on top of seed_set. Averages over the given number
184-
of trials. If new_seed is None, just gives the average influence of the seed set. Computes
185-
marginal gain using payoffs if set.
184+
Computes the marginal gain of adding each seed in new_seeds on top of the original seed_set.
185+
Averages over num_trials number of randomized activations.
186186
187187
Parameters
188188
----------
189189
seed_set : Iterable[int]
190190
An iterable representing the current seed set. Can be empty.
191-
new_seed : int
192-
New seed set to compute marginal gain on.
191+
new_seeds : List[int]
192+
New seeds to compute marginal gains on. Can be empty.
193193
num_trials : int
194194
Number of randomized trials to run.
195195
196196
Returns
197197
----------
198-
float
199-
Average marginal gain in profit over all trials.
198+
List[float]
199+
List containing computed marginal gains. First entry is average influence of the
200+
starting seed set. Following entries are marginal gains with the addition of vertices
201+
from new_seeds in order. Has length len(new_seeds)+1.
200202
"""

0 commit comments

Comments
 (0)