Skip to content

Commit

Permalink
Merge Pull Request #4730 from trilinos/Trilinos/csiefer-2069c43
Browse files Browse the repository at this point in the history
Automatically Merged using Trilinos Pull Request AutoTester
PR Title: MueLu: More fixes to the Avatar interface
PR Author: csiefer2
  • Loading branch information
trilinos-autotester authored Mar 27, 2019
2 parents cdc5782 + 2069c43 commit 75eec6e
Showing 1 changed file with 45 additions and 46 deletions.
91 changes: 45 additions & 46 deletions packages/muelu/src/Utils/MueLu_AvatarInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,17 @@ RCP<const ParameterList> AvatarInterface::GetValidParameterList() const {
validParamList->set<int>("avatar: good class",int_dummy,"Numeric code for class Avatar considers to be good");

// Which drop tol choice heuristic to use
validParamList->set<int>("avatar: heuristic",int_dummy,"Numeric code for which heurisitc we want to use");
validParamList->set<int>("avatar: heuristic",int_dummy,"Numeric code for which heuristic we want to use");

// Bounds file for extrapolation risk
validParamList->set<Teuchos::Array<std::string> >("avatar: bounds file",ar_dummy,"Bounds file for Avatar extrapolation risk");

// Add dummy variables at the start
validParamList->set<int>("avatar: initial dummy variables",int_dummy,"Number of dummy variables to add at the start");

// Add dummy variables before the class
validParamList->set<int>("avatar: pre-class dummy variables",int_dummy,"Number of dummy variables to add at the before the class");

return validParamList;
}

Expand Down Expand Up @@ -163,7 +169,9 @@ void AvatarInterface::Setup() {
// Get the avatar strings (NOTE: Only exist on proc 0)
avatarStrings_ = ReadFromFiles("avatar: decision tree files");
namesStrings_ = ReadFromFiles("avatar: names files");
boundsString_ = ReadFromFiles("avatar: bounds file");
if(params_.isParameter("avatar: bounds file"))
boundsString_ = ReadFromFiles("avatar: bounds file");

filestem_ = params_.get<Teuchos::Array<std::string>>("avatar: filestem");


Expand Down Expand Up @@ -197,6 +205,14 @@ void AvatarInterface::Cleanup() {
void AvatarInterface::GenerateFeatureString(const Teuchos::ParameterList & problemFeatures, std::string & featureString) const {
// NOTE: Assumes that the features are in the same order Avatar wants them.
std::stringstream ss;

// Initial Dummy Variables
if (params_.isParameter("avatar: initial dummy variables")) {
int num_dummy = params_.get<int>("avatar: initial dummy variables");
for(int i=0; i<num_dummy; i++)
ss<<"666,";
}

for(Teuchos::ParameterList::ConstIterator i=problemFeatures.begin(); i != problemFeatures.end(); i++) {
// const std::string& name = problemFeatures.name(i);
const Teuchos::ParameterEntry& entry = problemFeatures.entry(i);
Expand Down Expand Up @@ -251,6 +267,14 @@ std::string AvatarInterface::ParamsToString(const std::vector<int> & indices) co
for(Teuchos_Ordinal i=0; i<avatarParameterValues_.size(); i++) {
ss << "," << avatarParameterValues_[i][indices[i]];
}

// Pre-Class dummy variables
if (params_.isParameter("avatar: pre-class dummy variables")) {
int num_dummy = params_.get<int>("avatar: pre-class dummy variables");
for(int i=0; i<num_dummy; i++)
ss<<",666";
}

return ss.str();
}

Expand Down Expand Up @@ -322,7 +346,9 @@ void AvatarInterface::SetMueLuParameters(const Teuchos::ParameterList & problemF

std::cout<<"** Avatar TestString ***\n"<<testString<<std::endl;//DEBUG

int bound_check = checkBounds(testString, boundsString_);
int bound_check = true;
if(params_.isParameter("avatar: bounds file"))
bound_check = checkBounds(testString, boundsString_);

// FIXME: Only send in first tree's string
//int* avatar_test(Avatar_handle* a, char* test_data_file, int test_data_is_a_string);
Expand Down Expand Up @@ -395,56 +421,29 @@ void AvatarInterface::SetMueLuParameters(const Teuchos::ParameterList & problemF

int AvatarInterface::checkBounds(std::string trialString, Teuchos::ArrayRCP<std::string> boundsString) const {
std::stringstream ss(trialString);
std::vector<float> vect;
std::vector<double> vect;

int useNewFeatures = 0;

float i;

while (ss >> i)
{
vect.push_back(i);

if (ss.peek() == ',')
ss.ignore();
double b;
while (ss >> b) {
vect.push_back(b);
if (ss.peek() == ',') ss.ignore();
}

std::stringstream ssBounds(boundsString[0]);
std::vector<double> boundsVect;

std::string bounds = const_cast<char*>(boundsString[0].c_str());

std::stringstream ssBounds(bounds);
std::vector<float> boundsVect;

float b;

while (ssBounds >> b)
{
boundsVect.push_back(b);

if (ssBounds.peek() == ',')
ssBounds.ignore();
while (ssBounds >> b) {
boundsVect.push_back(b);
if (ssBounds.peek() == ',') ssBounds.ignore();
}

if (vect.at(3) > boundsVect.at(0) || vect.at(3) < boundsVect.at(1))
return 0;

if (vect.at(4) > boundsVect.at(2) || vect.at(4) < boundsVect.at(3))
return 0;

if (vect.at(5) > boundsVect.at(4) || vect.at(5) < boundsVect.at(5))
return 0;

if (vect.at(6) > boundsVect.at(6) || vect.at(6) < boundsVect.at(7))
return 0;
int min_idx = (int) std::min(vect.size(),boundsVect.size()/2);

if (useNewFeatures == 1){
if (vect.at(8) > boundsVect.at(8) || vect.at(8) < boundsVect.at(9))
return 0;

if (vect.at(9) > boundsVect.at(10) || vect.at(9) < boundsVect.at(11))
return 0;
}
bool inbounds=true;
for(int i=0; inbounds && i<min_idx; i++)
inbounds = boundsVect[2*i] <= vect[i] && vect[i] <= boundsVect[2*i+1];

return 1;
return (int) inbounds;
}

int AvatarInterface::hybrid(float * probabilities, std::vector<int> acceptableCombos) const{
Expand Down

0 comments on commit 75eec6e

Please sign in to comment.