Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Area under the curves. #257

Open
SaicharanRitwik39 opened this issue Sep 2, 2024 · 1 comment
Open

Area under the curves. #257

SaicharanRitwik39 opened this issue Sep 2, 2024 · 1 comment

Comments

@SaicharanRitwik39
Copy link

How can I calculate the area under the curves? For example I want to compute the area under the infected curve, how can I do that?

@SaicharanRitwik39
Copy link
Author

SaicharanRitwik39 commented Nov 3, 2024

Hello. I have been able to figure out a solution for this. The main thing I was missing was how to access the time series data. This can be done through node_counts = trends[0]['trends']['node_count']. This structure provides lists of node counts per time step for each state, which is essential for calculating the average proportion of nodes in each state over time.

The following code helps in finding the areas under the curves:

**_node_counts = trends[0]['trends']['node_count']
areas = {}

for state_key, y_values in node_counts.items():
x_values = np.arange(len(y_values))
area = np.trapz(y_values, x=x_values) / N
areas[state_key] = area

for state_key, area in areas.items():
print(f"Normalized area under the curve for {state_key}: {area}")_**

Entire code for an example SIR epidemic simulation:

N = 1000
g = nx.erdos_renyi_graph(N, 0.1)
model = ep.SIRModel(g)
config = mc.Configuration()
config.add_model_parameter("beta", 0.01)
config.add_model_parameter("gamma", 0.005)
infected_nodes = list(range(10))
config.add_model_initial_configuration("Infected", infected_nodes)
model.set_initial_status(config)

iterations = model.iteration_bunch(200)
trends = model.build_trends(iterations)

viz = DiffusionTrend(model, trends)
viz.plot()
plt.show()

**_node_counts = trends[0]['trends']['node_count']
areas = {}

for state_key, y_values in node_counts.items():
x_values = np.arange(len(y_values))
area = np.trapz(y_values, x=x_values) / N
areas[state_key] = area

for state_key, area in areas.items():
print(f"Normalized area under the curve for {state_key}: {area}")_**

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant