Repository navigation
Expand file tree
/
Copy pathFittingInterface.cpp
More file actions
172 lines (162 loc) · 7.17 KB
/
Copy pathFittingInterface.cpp
File metadata and controls
172 lines (162 loc) · 7.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <iostream>
#include <string>
#include <utility>
#include <iomanip>
#include <vector>
#include <variant> // for std::variant
#include "ManySimulations.cpp"
#include "cellLibrary/ModelA549.h"
class FittingInterface {
public:
// PROPERTIES
double maxDose;
std::vector<ProtractedDamageInput> scheduledProtractedDamageInputCell;
std::string checkManySimulationStopMode = "fast";
// CONSTRUCTOR: load the SDD once
FittingInterface(const std::string& sddPath, double maxDose = 2)
: manySdd(sddPath, maxDose), maxDose(maxDose)
{
// std::cerr << "[FittingInterface] SDD loaded from: " << sddPath << std::endl;
}
// RUN FUNCTIONS
// Run simulation with given RepairMechanism parameters
// Return pair of vectors: (times, meanNumberDamages)
std::pair<std::vector<double>, std::vector<double>> runSimulationFoci(
double detectRate,
double finishRate,
double correctProb
) {
// Create Cell
Cell cell(manySdd, 0, 2, 0, -1, false); // MUST BE FALSE. MANY SIMS REQUIRES IT
cell.repairModel = RepairMechanism(detectRate,finishRate, correctProb);
// Run ManySimulations
int nSims = 100;
ManySimulations manySims(cell, nSims);
manySims.manyRun(60*25, 15, false);
// Compute average number of damage sites over time
auto [timePoints, mean, stddev, stderr] =
computeStatsOverTime(
manySims.manyArraySimulationTime,
manySims.manyArrayNumberDetectedDamageSitesPerTime, true
);
return { timePoints, mean };
}
// Return survival:
double runSimulationSurvival(
int thresholdForDeath,
int thresholdCycleChange,
double weightLethalityMisrepair
) {
// Create Cell
Cell cell(manySdd, 0, 2, 0, -1, false); // MUST BE FALSE. MANY SIMS REQUIRES IT
cell.repairModel = RepairMechanism(0.2, 0.0022, -0.30756086282);
// Variables to fit
cell.thresholdForDeath = thresholdForDeath;
cell.thresholdCycleChange = thresholdCycleChange;
cell.weightLethalityMisrepair = weightLethalityMisrepair;
// Run ManySimulations
int nSims = 10000;
ManySimulations manySims(cell, nSims);
manySims.manyRun(60*25, 15, false);
// Compute average number of damage sites over time
manySims.calculateAverageSurvivalAndError();
return manySims.averageSurvival;
}
// Return survival:
double runSimulationSurvivalAllParameters(
double detectRate,
double finishRate,
double correctProb,
int thresholdForDeath,
int thresholdCycleChange,
double weightLethalityMisrepair
) {
// Create Cell
Cell cell(manySdd, 0, 2, 0, -1, false); // MUST BE FALSE. MANY SIMS REQUIRES IT
cell.repairModel = RepairMechanism(detectRate, finishRate, correctProb);
cell.thresholdForDeath = thresholdForDeath;
cell.thresholdCycleChange = thresholdCycleChange;
cell.weightLethalityMisrepair = weightLethalityMisrepair;
// Run ManySimulations
int nSims = 100;
ManySimulations manySims(cell, nSims);
manySims.manyRun(60*25, 15, false);
// Compute average number of damage sites over time
manySims.calculateAverageSurvivalAndError();
return manySims.averageSurvival;
}
// Generalized simulation runner
std::variant<
std::tuple<std::vector<double>, std::vector<double>, std::vector<double>>, // for foci (time, mean, stderr)
std::pair<double, double> // for survival (mean, stderr)
> runSimulationGeneral(
const std::string& mode, // "foci" or "survival"
int nSims,
double totalTime,
double timeStep,
double detectRate,
double finishRate,
double correctProb,
int thresholdForDeath,
int thresholdCycleChange,
double weightLethalityMisrepair,
int thresholdForNecrosis = 1000,
double constMisrepairPerNumberOfDamage = -1,
double newDose = -1
) {
// boolean for daughters
bool simulateDaughters = false;
// Create Cell
// ModelA549 myModel; // can be used
Cell cell(manySdd, 0, 2, 0, -1,
false, newDose);
// Add protracted damages if needed
if (!scheduledProtractedDamageInputCell.empty()) {
auto [times, sddPaths, doses] = ProtractedDamageInput::toVectors(scheduledProtractedDamageInputCell);
auto protractedEvents = ProtractedDamage::loadProtractedDamageSites(times, sddPaths, doses, cell);
cell.protractedDamageEvents = std::move(protractedEvents);
// The simulation now lasts totalTime (usually 24-25h) plus the time when you last added the damage
double maxTime = *std::max_element(times.begin(), times.end());
// std::cerr << totalTime << std::endl; //debug
totalTime += maxTime;
// std::cerr << totalTime << std::endl; //debug
// ProtractedDamage::printSummary(cell.protractedDamageEvents); //debug
// ProtractedDamage::printEventSchedule(cell.protractedDamageEvents); //debug
simulateDaughters = true; //in the future
}
cell.repairModel = RepairMechanism(detectRate, finishRate, correctProb);
cell.thresholdForDeath = thresholdForDeath;
cell.thresholdCycleChange = thresholdCycleChange;
cell.weightLethalityMisrepair = weightLethalityMisrepair;
cell.thresholdForNecrosis = thresholdForNecrosis;
if (constMisrepairPerNumberOfDamage > 0) {
cell.boolVariableMisrepair = true;
cell.repairModel.misrepairMechanism.constMisrepairPerNumberOfDamage = constMisrepairPerNumberOfDamage;
}
// Run simulations
ManySimulations manySims(cell, nSims);
manySims.checkManySimulationStopMode = checkManySimulationStopMode;
// std::cerr << "Cell dose: " << cell.doseInCell << std::endl; //debug
// std::cerr << cell.repairModel.repairDetectionRate << " " << cell.repairModel.repairSpeedRate
// << " " << cell.repairModel.successRepairConstant << " " << cell.thresholdForDeath
// << " " << cell.thresholdCycleChange << " " << cell.weightLethalityMisrepair << std::endl; //debug
manySims.manyRun(totalTime, timeStep, simulateDaughters);
if (mode == "foci") {
auto [timePoints, mean, stddev, stderr] =
computeStatsOverTime(
manySims.manyArraySimulationTime,
manySims.manyArrayNumberDetectedDamageSitesPerTime, true
);
return std::make_tuple(timePoints, mean, stderr);
}
else if (mode == "survival") {
manySims.calculateAverageSurvivalAndError();
return std::make_pair(manySims.averageSurvival, manySims.stderrSurvival);
}
else {
throw std::invalid_argument("Invalid mode. Use 'foci' or 'survival'.");
}
}
private:
ManySddReader manySdd;
};