Skip to content

Commit 99b6f8f

Browse files
committed
Smaller changes to fix bugs caused by multi-threaded analysis and invalid data access.
1 parent d303a55 commit 99b6f8f

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

Src/Analysis/AnalysisManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,16 +464,16 @@ int AnalysisManager::process_quantitative_analysis_requests_for_all_files() {
464464
if (intervals_of_interest.count(file) != 0) {
465465
intervals_to_investigate = intervals_of_interest[file];
466466
}
467-
getThreadPool().submit_task([this, &file, &meta_information, &intervals_to_investigate]{this->process_quantitative_analysis_requests_for_file(file,
467+
getThreadPool().submit_task([this, file, meta_information, intervals_to_investigate]{this->process_quantitative_analysis_requests_for_file(file,
468468
meta_information, intervals_to_investigate);});
469469
}
470470

471471
return 0;
472472
}
473473

474-
void AnalysisManager::process_quantitative_analysis_requests_for_file(const std::string &file,
475-
MetaInformation &meta_information,
476-
const std::vector<TimeInterval> &intervals_of_interest) const {
474+
void AnalysisManager::process_quantitative_analysis_requests_for_file(std::string file,
475+
MetaInformation meta_information,
476+
std::vector<TimeInterval> intervals_of_interest) const {
477477
MetaInformation current_meta_information{file + ".recordmeta"};
478478

479479
std::fstream out;

Src/Analysis/AnalysisManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class AnalysisManager {
9393

9494
int process_quantitative_analysis_requests_for_all_files();
9595

96-
void process_quantitative_analysis_requests_for_file(const std::string &file, MetaInformation& meta_information, const std::vector<TimeInterval> &intervals_of_interest) const;
96+
void process_quantitative_analysis_requests_for_file(std::string file, MetaInformation meta_information, std::vector<TimeInterval> intervals_of_interest) const;
9797

9898
int process_quantitative_analysis_requests_for_primary_file(int analysis_id, float* values, std::vector<TimeInterval> intervals_of_interest);
9999

Src/Analysis/QuantitativeAnalysis/TransformAnalysis/QuantitativeSynchronyAnalysisRequest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ void QuantitativeSynchronyAnalysisRequest::process_request(std::shared_ptr<Trans
3030

3131
if (t_data->time > current_t) {
3232
current_t = t_data->time;
33-
while (recent_data_a.front().time < current_t - temporal_sampling_rate) {
33+
while (recent_data_a.size() > 0 &&recent_data_a.front().time < current_t - temporal_sampling_rate) {
3434
recent_data_a.pop_front();
3535
}
36-
while (recent_data_b.front().time < current_t - temporal_sampling_rate) {
36+
while (recent_data_b.size() > 0 && recent_data_b.front().time < current_t - temporal_sampling_rate) {
3737
recent_data_b.pop_front();
3838
}
3939
std::vector<float> a_velocities;
@@ -96,7 +96,7 @@ TransformAnalysisType QuantitativeSynchronyAnalysisRequest::get_type() const {
9696
// see: https://www.geeksforgeeks.org/program-spearmans-rank-correlation/
9797
std::vector<float> QuantitativeSynchronyAnalysisRequest::rank_data(std::vector<float> const &data) {
9898
std::vector<float> ranks(data.size());
99-
float threshold = 0.1f;
99+
float threshold = 0.00001f;
100100
for (int i = 0; i < data.size(); i++) {
101101
int rank = 1, same = 1;
102102

@@ -116,11 +116,11 @@ std::vector<float> QuantitativeSynchronyAnalysisRequest::rank_data(std::vector<f
116116
}
117117

118118
float QuantitativeSynchronyAnalysisRequest::correlation(const std::vector<float> &a, const std::vector<float> &b) {
119-
if(a.size() != b.size()) {
120-
Debug::Log("Error: Cannot calculate correlation between vectors of different sizes");
119+
if(a.size() != b.size() || a.empty()) {
120+
//Debug::Log("Error: Cannot calculate correlation between vectors of different sizes");
121121
return 0;
122122
}
123-
float sum_a, sum_b, sum_ab, square_sum_a, square_sum_b = 0;
123+
float sum_a = 0, sum_b = 0, sum_ab = 0, square_sum_a = 0, square_sum_b = 0;
124124

125125
for (int i = 0; i < a.size(); i++) {
126126
sum_a = sum_a + a[i];

0 commit comments

Comments
 (0)