Skip to content

Commit 4e4410d

Browse files
committed
ADD 2025 SIR exercise files
1 parent 512fcb1 commit 4e4410d

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed

module1/Makefile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CXX := g++
2+
OPT=-O1 -Wall
3+
4+
CXXFLAGS := $(OPT) -Wall -Wno-unused-const-variable -std=c++17 -march=native
5+
default: SIR # SIR_python
6+
#INC := $(shell python3 -m pybind11 --includes) $(shell python3-config --ldflags)
7+
8+
SIR: SIR.cpp
9+
$(CXX) SIR.cpp -o SIR $(CXXFLAGS)
10+
11+
#SIR_python: SIR_python.cpp
12+
# $(CXX) SIR_python.cpp -o SIR_python$(shell python3-config --extension-suffix) -fPIC -shared $(CXXFLAGS) $(INC)
13+
14+
clean:
15+
rm -f SIR SIR_python
16+
# rm -f SIR_python$(shell python3-config --extension-suffix)

module1/SIR.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
#include <fstream>
3+
#include <vector>
4+
5+
// Function to take a step in the SIR model
6+
// state: vector of S, I, R
7+
// beta: infection rate
8+
// gamma: recovery rate
9+
// dt: time step
10+
std::vector<float> take_step(std::vector<float> state, float beta, float gamma, float dt){
11+
//todo: implement the SIR model
12+
return new_state;
13+
}
14+
15+
//======================================================================================================
16+
//======================== Main function ===============================================================
17+
//======================================================================================================
18+
int main(int argc, char* argv[]){
19+
// define the parameters
20+
21+
// TODO: Define the parameters of the SIR model
22+
23+
// TODO: implement the SIR model
24+
25+
// TODO: Save the results to a file
26+
}

module1/SIR_python.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <iostream>
2+
#include <fstream>
3+
#include <vector>
4+
#include <pybind11/stl.h>
5+
#include <pybind11/pybind11.h>
6+
#include <pybind11/numpy.h>
7+
8+
// Function to take a step in the SIR model
9+
// state: vector of S, I, R
10+
// beta: infection rate
11+
// gamma: recovery rate
12+
// dt: time step
13+
std::vector<float> take_step(std::vector<float> state, float beta, float gamma, float dt){
14+
//todo: implement the SIR model
15+
return new_state;
16+
}
17+
18+
// Function simulating num_steps of the SIR model, saving the state every return_every steps and returning the results
19+
// S0: initial number of susceptible individuals
20+
// I0: initial number of infected individuals
21+
// R0: initial number of recovered individuals
22+
// beta: infection rate
23+
// gamma: recovery rate
24+
// dt: time step
25+
// num_steps: number of steps to simulate
26+
// return_every: save the state every return_every steps
27+
pybind11::array integrate_system(float S0, float I0, float R0, float beta, float gamma, float dt, int num_steps, int return_every){
28+
std::vector<std::vector<float>> results;
29+
// TODO: implement the SIR model
30+
return pybind11::cast(results);
31+
}
32+
33+
PYBIND11_MODULE(SIR_python, m) {
34+
m.doc() = "This is a Python binding for the SIR model";
35+
36+
m.def("integrate_system", &integrate_system);
37+
}

module1/Unknown_SIR_data.csv

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
,S,I,R
2+
0.0,1006.3962321148992,1.0070910683435152,7.674741286043622e-05
3+
2.0408163265306123,1014.5530989172524,1.4228372519638564,0.17801879976726537
4+
4.081632653061225,1000.7690545258415,2.0649559812501175,0.4357831476990105
5+
6.122448979591837,996.1175035857603,2.826917534720307,0.8026813201190486
6+
8.16326530612245,1011.9294971598068,4.0801534860520015,1.3148981972730154
7+
10.204081632653061,974.391662965824,5.692035241042004,2.0098514363818563
8+
12.244897959183675,987.2580209977217,8.127084233861519,3.077002361340375
9+
14.285714285714286,997.1921555652444,11.1411402004285,4.460492394260581
10+
16.3265306122449,982.5264642273422,16.178692639617495,6.640116313279181
11+
18.367346938775512,985.5391134693785,22.438734952694826,9.302401673285305
12+
20.408163265306122,950.3929592274865,30.9867062109544,13.453561212371968
13+
22.448979591836736,943.6768450787737,43.1172181507687,18.902994501944676
14+
24.48979591836735,923.9712883457852,58.55787164713293,26.461358749920777
15+
26.53061224489796,889.3736903686494,78.3870367496892,36.42799336312908
16+
28.571428571428573,829.7717726263381,103.99688813928137,50.47456378959229
17+
30.612244897959183,803.6038006158797,134.86301821185936,67.78296315480418
18+
32.6530612244898,739.4531398609986,170.07930310542255,89.57453306868761
19+
34.69387755102041,662.6057572102866,207.0584204365696,120.4683551291235
20+
36.734693877551024,588.7107715185717,251.76602405172594,155.82715996942417
21+
38.775510204081634,528.0945273414742,284.48622084623474,196.03112205363107
22+
40.816326530612244,453.6387542336385,311.49392179639165,238.62917703193912
23+
42.85714285714286,379.64101876152733,324.6956212073424,295.3771886609074
24+
44.89795918367347,328.7240024764717,335.86960613328057,336.9380611019739
25+
46.93877551020408,276.6226521708966,342.9129552547733,386.64888732108915
26+
48.9795918367347,230.46604078409402,332.5172677294927,436.2620642180145
27+
51.02040816326531,198.41886797255233,312.985461763179,482.2774728413838
28+
53.06122448979592,172.31113754951818,295.36931154816244,536.5337246723285
29+
55.10204081632653,147.10640197410112,280.47647356374284,591.4279411760413
30+
57.142857142857146,130.2172301299589,257.34236499547103,614.2528711129506
31+
59.183673469387756,114.13385455729035,232.85793225104177,655.9244771150093
32+
61.224489795918366,102.4047733203167,208.066233857558,694.3136177899195
33+
63.26530612244898,91.79101179657,189.2152289525042,715.0072780394455
34+
65.3061224489796,84.84614462227702,170.5458134975131,746.7161144614075
35+
67.34693877551021,77.56253691742647,154.62995852816593,772.2091496683425
36+
69.38775510204081,73.30534380238566,135.99961469908644,776.27645565576
37+
71.42857142857143,67.34601887552232,122.52869734263317,814.7301940332044
38+
73.46938775510205,64.31334481761729,110.21573349736046,836.4965234263399
39+
75.51020408163265,61.66582472302947,96.03826238406376,842.6057280125577
40+
77.55102040816327,58.97457490297767,86.49580546030899,848.9915046223448
41+
79.59183673469389,56.07920007819682,75.9703698400598,849.5257527067243
42+
81.63265306122449,53.29737876865533,67.02012369361692,875.3995783493236
43+
83.6734693877551,52.78529217886916,59.541480121267504,881.0482364490581
44+
85.71428571428572,50.91742018377428,51.66658726016318,920.9086552034577
45+
87.75510204081633,49.98086105684715,46.26699373748106,906.5765503440235
46+
89.79591836734694,47.580613323137655,40.5184260065114,906.9232321517168
47+
91.83673469387756,47.18889650978118,36.03883717711462,912.0509520982456
48+
93.87755102040816,46.55568568499699,31.46335647347164,928.7371564916173
49+
95.91836734693878,45.78250532061345,27.796278245398238,931.6387069680544
50+
97.9591836734694,46.018787328504715,24.222348556744723,944.5588773050516
51+
100.0,44.70104560362663,21.48687578031168,942.6100942732352

0 commit comments

Comments
 (0)