Skip to content

Commit

Permalink
update min max voltages and stead_state_voltage
Browse files Browse the repository at this point in the history
  • Loading branch information
anilbey committed Apr 30, 2024
1 parent 4c3a86c commit 8c8d859
Showing 1 changed file with 25 additions and 35 deletions.
60 changes: 25 additions & 35 deletions efel/cppcore/LibV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,9 +719,8 @@ int LibV1::ohmic_input_resistance(mapStr2intVec& IntFeatureData,
return 1;
}

static int __maxmin_voltage(const vector<double>& v, const vector<double>& t,
double stimStart, double stimEnd,
vector<double>& maxV, vector<double>& minV) {
static std::pair<double, double> __maxmin_voltage(const vector<double>& v, const vector<double>& t,
double stimStart, double stimEnd) {
if (stimStart > t[t.size() - 1])
throw FeatureComputationError("Stimulus start larger than max time in trace");

Expand All @@ -743,25 +742,23 @@ static int __maxmin_voltage(const vector<double>& v, const vector<double>& t,
throw FeatureComputationError("Stimulus end index not found");
}

maxV.push_back(*max_element(&v[stimstartindex], &v[stimendindex]));
minV.push_back(*min_element(&v[stimstartindex], &v[stimendindex]));
double maxV = *max_element(&v[stimstartindex], &v[stimendindex]);
double minV = *min_element(&v[stimstartindex], &v[stimendindex]);

return 1;
return std::make_pair(maxV, minV);
}

int LibV1::maximum_voltage(mapStr2intVec& IntFeatureData,
mapStr2doubleVec& DoubleFeatureData,
mapStr2Str& StringData) {
const auto& doubleFeatures =
getFeatures(DoubleFeatureData, {"V", "T", "stim_start", "stim_end"});
vector<double> maxV, minV;
int retVal = __maxmin_voltage(doubleFeatures.at("V"), doubleFeatures.at("T"),
doubleFeatures.at("stim_start")[0],
doubleFeatures.at("stim_end")[0], maxV, minV);
if (retVal > 0) {
setVec(DoubleFeatureData, StringData, "maximum_voltage", maxV);
}
return retVal;
std::pair<double, double> maxminV = __maxmin_voltage(doubleFeatures.at("V"), doubleFeatures.at("T"),
doubleFeatures.at("stim_start")[0],
doubleFeatures.at("stim_end")[0]);

setVec(DoubleFeatureData, StringData, "maximum_voltage", {maxminV.first});
return 1;
}

// *** maximum voltage ***
Expand All @@ -771,29 +768,26 @@ int LibV1::minimum_voltage(mapStr2intVec& IntFeatureData,
mapStr2Str& StringData) {
const auto& doubleFeatures =
getFeatures(DoubleFeatureData, {"V", "T", "stim_start", "stim_end"});
vector<double> maxV, minV;
int retVal = __maxmin_voltage(doubleFeatures.at("V"), doubleFeatures.at("T"),
doubleFeatures.at("stim_start")[0],
doubleFeatures.at("stim_end")[0], maxV, minV);
if (retVal > 0) {
setVec(DoubleFeatureData, StringData, "minimum_voltage", minV);
}
return retVal;

std::pair<double, double> maxminV = __maxmin_voltage(doubleFeatures.at("V"), doubleFeatures.at("T"),
doubleFeatures.at("stim_start")[0],
doubleFeatures.at("stim_end")[0]);

setVec(DoubleFeatureData, StringData, "minimum_voltage", {maxminV.second});
return 1;
}

// *** steady state voltage ***
static int __steady_state_voltage(const vector<double>& v,
const vector<double>& t, double stimEnd,
vector<double>& ssv) {
static double __steady_state_voltage(const vector<double>& v,
const vector<double>& t, double stimEnd) {
int mean_size = 0;
double mean = 0;
for (int i = t.size() - 1; t[i] > stimEnd; i--) {
mean += v[i];
mean_size++;
}
mean /= mean_size;
ssv.push_back(mean);
return 1;
return mean;
}

int LibV1::steady_state_voltage(mapStr2intVec& IntFeatureData,
Expand All @@ -803,14 +797,10 @@ int LibV1::steady_state_voltage(mapStr2intVec& IntFeatureData,
getFeatures(DoubleFeatureData, {"V", "T", "stim_end"});
if (doubleFeatures.at("stim_end").size() != 1) return -1;

vector<double> ssv;
int retVal =
__steady_state_voltage(doubleFeatures.at("V"), doubleFeatures.at("T"),
doubleFeatures.at("stim_end")[0], ssv);
if (retVal > 0) {
setVec(DoubleFeatureData, StringData, "steady_state_voltage", ssv);
}
return retVal;
double ssv = __steady_state_voltage(doubleFeatures.at("V"), doubleFeatures.at("T"),
doubleFeatures.at("stim_end")[0]);
setVec(DoubleFeatureData, StringData, "steady_state_voltage", {ssv});
return 1;
}


Expand Down

0 comments on commit 8c8d859

Please sign in to comment.