Skip to content

Commit

Permalink
Change to energy fraction threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
siuwuncheung committed Mar 7, 2024
1 parent 0602769 commit ba33c97
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions examples/misc/combine_samples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ int main(int argc, char* argv[])
int rom_dim = static_basis_generator->getSpatialBasis()->numColumns();
if (rank==0) std::cout << "U ROM Dimension: " << rom_dim << std::endl;
static_basis_generator->endSamples();
if (rank==0) static_basis_generator->finalSummary(0.99999999, rdim);
if (rank==0) static_basis_generator->finalSummary(1e-8, rdim);
}
else {
/*-- load data from hdf5 file to find the mean and subtract it --*/
Expand Down Expand Up @@ -209,7 +209,7 @@ int main(int argc, char* argv[])
int rom_dim = static_basis_generator2->getSpatialBasis()->numColumns();
if (rank==0) std::cout << "U ROM Dimension: " << rom_dim << std::endl;
static_basis_generator2->endSamples();
if (rank==0) static_basis_generator2->finalSummary(0.99999999, rdim);
if (rank==0) static_basis_generator2->finalSummary(1e-8, rdim);

static_basis_generator2 = nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/prom/mixed_nonlinear_diffusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void MergeBasis(const int dimFOM, const int nparam, const int max_num_snapshots,
generator.endSamples(); // save the merged basis file

int cutoff = 0;
generator.finalSummary(0.9999, cutoff, "mergedSV_" + name);
generator.finalSummary(1e-4, cutoff, "mergedSV_" + name);
}

// TODO: move this to the library?
Expand Down
2 changes: 1 addition & 1 deletion examples/prom/nonlinear_elasticity_global_rom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ void MergeBasis(const int dimFOM, const int nparam, const int max_num_snapshots,
generator.endSamples(); // save the merged basis file

int cutoff = 0;
generator.finalSummary(0.9999999, cutoff, "mergedSV_" + name + ".txt");
generator.finalSummary(1e-7, cutoff, "mergedSV_" + name + ".txt");
}

const CAROM::Matrix *GetSnapshotMatrix(const int dimFOM, const int nparam,
Expand Down
8 changes: 4 additions & 4 deletions lib/linalg/BasisGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ BasisGenerator::resetDt(

void
BasisGenerator::finalSummary(
const double energyFraction,
const double energyFractionThreshold,
int & cutoff,
const std::string cutoffOutputPath,
const int first_sv)
Expand All @@ -342,7 +342,7 @@ BasisGenerator::finalSummary(
sum += (*sing_vals)(sv);
}

int p = std::floor(-std::log10(1.0 - energyFraction));
int p = std::floor(-std::log10(energyFractionThreshold));
std::vector<double> energy_fractions(p);

for (int i = 0; i < p; ++i) {
Expand Down Expand Up @@ -379,7 +379,7 @@ BasisGenerator::finalSummary(
break;
}
}
if (!reached_cutoff && partialSum / sum > energyFraction)
if (!reached_cutoff && partialSum / sum > 1.0 - energyFractionThreshold)
{
cutoff = sv+1;
reached_cutoff = true;
Expand All @@ -388,7 +388,7 @@ BasisGenerator::finalSummary(

if (!reached_cutoff) cutoff = sing_vals->dim();
*output_stream << std::fixed << std::setprecision(p+1);
*output_stream << "For energy fraction: " << energyFraction << ", take first "
*output_stream << "For energy fraction: " << 1.0 - energyFractionThreshold << ", take first "
<< cutoff << " of " << sing_vals->dim() << " basis vectors" << std::endl;

if (!cutoffOutputPath.empty()) {
Expand Down
11 changes: 6 additions & 5 deletions lib/linalg/BasisGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,14 @@ class BasisGenerator
/**
* @brief Prints the summary of recommended numbers of basis vectors.
*
* @param[in] energyFraction Energy Fraction.
* @param[in] cutoff Number of basis vectors selected.
* @param[in] cutoffOutputPath Path of the summary file.
* @param[in] first_sv First singular vector in the calculaton of energy.
* @param[in] energyFractionThreshold Energy Fraction threshold
* (difference of energy difference from 1.0).
* @param[in] cutoff Number of basis vectors selected.
* @param[in] cutoffOutputPath Path of the summary file.
* @param[in] first_sv First singular vector in the calculaton of energy.
*/
void finalSummary(
const double energyFraction,
const double energyFractionThreshold,
int & cutoff,
const std::string cutoffOutputPath = "",
const int first_sv = 0);
Expand Down

0 comments on commit ba33c97

Please sign in to comment.