-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4addff4
commit effc8b7
Showing
61 changed files
with
55,040 additions
and
608 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
#find_package(Boost REQUIRED COMPONENTS random) | ||
find_package(Boost REQUIRED COMPONENTS random) | ||
|
||
if (Boost_FOUND) | ||
message(STATUS "Boost found: ${Boost_VERSION}") | ||
else() | ||
message(FATAL_ERROR "Boost not found!") | ||
endif() | ||
|
||
add_executable(sobol generate_sobol.cpp | ||
generate_sobol.cpp) | ||
|
||
target_link_libraries(sobol Boost::random) | ||
|
||
set_target_properties(sobol PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,82 @@ | ||
#include <iostream> | ||
#include <filesystem> | ||
#include <fstream> | ||
#include <iomanip> | ||
#include <iostream> | ||
#include <vector> | ||
#include <fstream> | ||
#include <filesystem> | ||
#include <boost/lexical_cast.hpp> | ||
#include <boost/random/faure.hpp> | ||
#include <boost/random/mersenne_twister.hpp> | ||
#include <boost/random/sobol.hpp> | ||
#include <boost/random/uniform_01.hpp> | ||
|
||
std::filesystem::path createOutputDir() { | ||
std::filesystem::path outputDir = "output"; | ||
std::filesystem::path sourceDir = std::filesystem::current_path(); | ||
std::filesystem::path destDir = sourceDir.parent_path().parent_path() / "examples" / outputDir; | ||
if (!exists(destDir)) { | ||
create_directory(destDir); | ||
std::cout << "Directory created: " << destDir << "\n"; | ||
} | ||
return destDir; | ||
} | ||
|
||
int main() { | ||
std::filesystem::path path = ""; | ||
|
||
std::ofstream csvFile("sobol_sequence_5.csv"); | ||
unsigned int N = 0, s = 0; | ||
do { | ||
std::cout << "Enter the number of samples (N): "; | ||
std::cin >> N; | ||
std::cout << "Enter the number of dimensions (s): "; | ||
std::cin >> s; | ||
} while (N <= 0 || s <= 0); | ||
|
||
std::string endFileName = boost::lexical_cast<std::string>(s) + ".csv"; | ||
std::filesystem::path csvPath = createOutputDir() / ("sequences_" + endFileName); | ||
|
||
std::ofstream csvFile(csvPath); | ||
|
||
if (!csvFile.is_open()) { | ||
std::cerr << "Failed to open file for writing." << std::endl; | ||
return 1; | ||
} | ||
|
||
boost::random::sobol qrng(2); // 3-dimensional Sobol sequence | ||
qrng.seed(42); | ||
unsigned int seed = 42; | ||
boost::mt19937 unifRng(seed); // Mersenne Twister Pseudo-Random Number Generator (PRNG) | ||
boost::random::uniform_01<> uniformGen; | ||
|
||
boost::random::sobol sobolQrng(s); // s-dimensional Sobol Quasi Random Number Generator (QRNG) | ||
boost::random::faure faureQrng(s); // s-dimensional Faure Quasi Random Number Generator (QRNG) | ||
|
||
std::vector<double> point(2); | ||
sobolQrng.seed(seed); | ||
faureQrng.seed(seed); | ||
|
||
csvFile << "x,y\n"; | ||
std::vector<double> sobolPoint(s); | ||
std::vector<double> faurePoint(s); | ||
|
||
std::cout << "Sobol sequence using Boost:" << std::endl; | ||
for (int i = 0; i < 5; ++i) { | ||
qrng.generate(point.begin(), point.end()); | ||
for (auto& coord : point) | ||
coord /= static_cast<double>(boost::random::sobol::max()); | ||
// Write header to CSV file | ||
csvFile << "Sample,Dimension,Sobol,Faure,Uniform\n"; | ||
|
||
csvFile << std::fixed << std::setprecision(8) << point[0] << "," << point[1] << "\n"; | ||
std::cout << std::endl; | ||
for (unsigned int i = 1; i <= N; ++i) { | ||
// Generate Sobol and Faure sequences for this sample | ||
sobolQrng.generate(sobolPoint.begin(), sobolPoint.end()); | ||
faureQrng.generate(faurePoint.begin(), faurePoint.end()); | ||
|
||
for (unsigned int d = 1; d <= s; ++d) { | ||
// Normalize Sobol and Faure values to [0, 1) | ||
double sobolVal = sobolPoint[d - 1] / static_cast<double>(boost::random::sobol::max()); | ||
double faureVal = faurePoint[d - 1] / static_cast<double>(boost::random::faure::max()); | ||
double uniformVal = uniformGen(unifRng); | ||
|
||
// Write values to CSV | ||
csvFile << i << "," << d << "," | ||
<< std::fixed << std::setprecision(8) | ||
<< sobolVal << "," | ||
<< faureVal << "," | ||
<< uniformVal << "\n"; | ||
} | ||
} | ||
|
||
csvFile.close(); | ||
std::cout << "Sequences exported to " << csvPath << std::endl; | ||
|
||
return 0; | ||
} | ||
} |
Oops, something went wrong.