Skip to content

Commit fc02017

Browse files
committed
v1.0.0: Added scipy requirement, tested on previous Python versions down to 3.10, added the possibility to customize classes and pass them inside the InfluenceMaximization object
1 parent bc78862 commit fc02017

File tree

140 files changed

+3520
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+3520
-24
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/netmax.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ NetMax was developed with Python 3.12 and requires the installation of the follo
3232

3333
- **networkx** (version 3.3)
3434
- **numpy**
35+
- **scipy**
3536
- **tqdm**
3637
- **heapdict**
3738

@@ -55,9 +56,9 @@ This framework wants to be a useful tool for all those people who study the prob
5556
- `r`: number of simulations to execute (default is 100)
5657
- `verbose`: if `True` sets the logging level to `INFO`, otherwise displays only the minimal information
5758

58-
**Important**: `alg`, `diff_model`, `inf_prob` and `endorsement_policy` are `str` parameters, in order to prevent the user from directly importing and instantiating all the specific classes, which could have not been user-friendly.
59-
If the user, after reading the documentation, wants to customize some specific parameters, he can still change the corresponding attribute after the instantiation of the `InfluenceMaximization` object.
60-
To view all the keywords for these parameters, see the corresponding section.
59+
**Important**: `alg`, `diff_model`, `inf_prob` and `endorsement_policy` can be either `str` or class parameters:
60+
- If they are `str` parameters, they represent the `name` attribute of the corresponding class already present in the framework. This was done in order to prevent the user from directly importing and instantiating all the specific classes, which could have not been user-friendly. To view all the keywords for these parameters, see the corresponding section
61+
- Otherwise, they must extend the corresponding superclass depending on the parameters (`Algorithm` for `alg`, `DiffusionModel` for `diff_model`, `InfluenceProbability` for `inf_prob`, `EndorsementPolicy` for `endorsement_policy`). This way, the user can define his own custom classes
6162

6263
After creating the `InfluenceMaximization` object, the user may call its `run()` method, which returns:
6364

__pycache__/utils.cpython-310.pyc

6.55 KB
Binary file not shown.

__pycache__/utils.cpython-39.pyc

6.59 KB
Binary file not shown.

build/lib/netmax/__init__.py

Whitespace-only changes.

build/lib/netmax/agent.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import copy
2+
3+
class Agent(object):
4+
5+
def __init__(self, name: str, budget: int, id: int = -1):
6+
"""
7+
This class models an agent.
8+
:param name: The name of the agent.
9+
:param budget: The budget of the agent.
10+
:param id: The id of the agent.
11+
"""
12+
self.name: str = name
13+
self.budget: int = budget
14+
self.seed: [int] = []
15+
self.spread = 0
16+
self.id: int = id
17+
18+
def __deepcopy__(self, memodict={}):
19+
"""
20+
Makes a deep copy of the agent object.
21+
"""
22+
new_agent = Agent(self.name, self.budget)
23+
new_agent.seed = copy.deepcopy(self.seed)
24+
new_agent.spread = self.spread
25+
new_agent.id = self.id
26+
return new_agent
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from .proxy_based.degdis import DegDis
2+
from .proxy_based.highest_out_degree import HighestOutDegree
3+
from .proxy_based.group_pr import Group_PR
4+
from .simulation_based.mcgreedy import MCGreedy
5+
from .simulation_based.celf import CELF
6+
from .simulation_based.celfpp import CELF_PP
7+
from .sketch_based.static_greedy import StaticGreedy
8+
from .sketch_based.ris import RIS
9+
from .sketch_based.tim import TIM
10+
from .sketch_based.timp import TIMp
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import networkx as nx
2+
from netmax.agent import Agent
3+
4+
class Algorithm:
5+
6+
def __init__(self, graph: nx.DiGraph, agents: list[Agent], curr_agent_id: int, budget, diff_model, r):
7+
"""
8+
:param graph: networkx DiGraph
9+
:param agents: list of Agent
10+
:param curr_agent_id: int - index of the current agent
11+
:param budget: int - budget of the current agent
12+
:param diff_model: str - diffusion model
13+
:param r: float - discount factor
14+
"""
15+
self.graph = graph
16+
self.agents = agents
17+
self.curr_agent_id = curr_agent_id
18+
self.budget = budget
19+
self.diff_model = diff_model
20+
self.r = r
21+
22+
def set_curr_agent(self, curr_agent_id):
23+
"""
24+
Sets the current agent as the one passed.
25+
:param curr_agent_id: index of the current agent.
26+
"""
27+
self.curr_agent_id = curr_agent_id
28+
29+
def __in_some_seed_set__(self, v, agents):
30+
"""
31+
Checks if a node is in some seed set.
32+
:param v: the node to check.
33+
:param agents: the 'agents' dictionary, which contain all the seed sets.
34+
:return: True if the node is in some seed set, False otherwise.
35+
"""
36+
for a in agents:
37+
if v in a.seed:
38+
return True
39+
return False
40+
41+
def run(self):
42+
raise NotImplementedError("This method must be implemented by subclasses")

build/lib/netmax/algorithms/proxy_based/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)