forked from seldon-code/pyseldonlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
94 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
jupytext: | ||
text_representation: | ||
extension: .md | ||
format_name: myst | ||
format_version: 0.13 | ||
jupytext_version: 1.16.4 | ||
kernelspec: | ||
display_name: Python 3 | ||
language: python | ||
name: python3 | ||
--- | ||
|
||
# DeGroot Model (Reaching Consensus) | ||
|
||
+++ | ||
|
||
Import the packages | ||
|
||
```{code-cell} ipython3 | ||
import pyseldonlib | ||
import pathlib | ||
import shutil | ||
``` | ||
|
||
Initialize some other settings for the simulation | ||
|
||
```{code-cell} ipython3 | ||
other_settings = pyseldonlib.Other_Settings(n_output_agents=10, | ||
n_output_network= None, | ||
print_progress= True, | ||
output_initial=True, | ||
start_output=1, | ||
number_of_agents = 200, | ||
connections_per_agent = 10) | ||
``` | ||
|
||
Initialize the model with parameters. | ||
|
||
```{code-cell} ipython3 | ||
model = pyseldonlib.DeGroot_Model(max_iterations=1000, | ||
convergence_tol=1e-6, | ||
rng_seed=120, | ||
other_settings=other_settings) | ||
output_dir_path = str("./output") | ||
if pathlib.Path(output_dir_path).exists(): | ||
shutil.rmtree(output_dir_path) | ||
model.run(output_dir_path) | ||
if pathlib.Path(output_dir_path).exists(): | ||
shutil.rmtree(output_dir_path) | ||
``` | ||
### On your local machine you can see a C++ std::out |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
jupytext: | ||
text_representation: | ||
extension: .md | ||
format_name: myst | ||
format_version: 0.13 | ||
jupytext_version: 1.16.4 | ||
kernelspec: | ||
display_name: Python 3 | ||
language: python | ||
name: python3 | ||
--- | ||
|
||
# Example Usage of the Network Class from the pyseldonlib Package | ||
|
||
```{code-cell} ipython3 | ||
# Import necessary modules | ||
import pyseldonlib | ||
``` | ||
|
||
```{code-cell} ipython3 | ||
# Initialize the Network object | ||
network = pyseldonlib.Network( | ||
model_string="DeGroot", | ||
neighbour_list=[[1, 2], [0, 2], [0, 1], [4], [3]], | ||
weight_list=[[0.5, 0.5], [0.5, 0.5], [0.5, 0.5], [1], [1]], | ||
direction="Incoming" | ||
) | ||
``` | ||
|
||
```{code-cell} ipython3 | ||
# Print the network details | ||
print(f"Number of agents: {network.n_agents}") | ||
print(f"Edges of 1st index agent: {network.n_edges(1)}") | ||
print(f"Direction: {network.get_direction}") | ||
print(f"Neighbour List: {network.get_neighbours(1)}") | ||
print(f"Weight List: {network.get_weights(1)}") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters