generate required metrics and plot them to one concise plot

This commit is contained in:
CDaut 2024-06-06 01:16:29 +02:00
parent 76f6bf62a4
commit c4b12e8ef2
Signed by: clara
GPG key ID: 223391B52FAD4463
18 changed files with 1056191 additions and 4239 deletions

View file

@ -1,43 +1,88 @@
#include <utk/utils/PointsetIO.hpp>
#include <utk/utils/Pointset.hpp>
#include <utk/samplers/SamplerStep.hpp>
#include "utk/metrics/PCF.hpp"
#include <utk/metrics/RadialSpectrum.hpp>
#include <utk/samplers/SamplerStep.hpp>
#include <utk/utils/Pointset.hpp>
#include <utk/utils/PointsetIO.hpp>
#define DIMENSION 1025
#define NSAMPLES 4096
#define NBINS 1000
#define SEED 8970
int main()
{
utk::Pointset<long double> points;
template <typename T>
void writeSpectrumToFile(const std::string &filename, std::vector<T> spectrum) {
std::ofstream file;
file.open(filename);
//sample points using heck
utk::SamplerStep sampler{
0.606,
8,
};
file << DIMENSION << std::endl;
std::cout << "generating samples…" << std::endl;
if(sampler.generateSamples(points, NSAMPLES))
{
std::cout << "computing spectrum…" << std::endl;
auto result = utk::Spectrum{DIMENSION, true}.compute(points);
std::ofstream pointFile;
pointFile.open("points.txt");
pointFile << NSAMPLES << std::endl;
write_text_pointset("points.txt", points);
std::ofstream file;
file.open("spectrum.txt");
file << DIMENSION << std::endl;
for(auto freq : result)
{
file << std::setprecision(std::numeric_limits<long double>::digits10 + 2) << std::fixed;
file << freq << std::endl;
}
for (auto freq : spectrum) {
file << std::setprecision(std::numeric_limits<long double>::digits10 + 2)
<< std::fixed;
file << freq << std::endl;
}
}
template <typename T>
void writePCFToFile(const std::string &filename, std::vector<T> spectrum) {
std::ofstream file;
file.open(filename);
for (auto freq : spectrum) {
file << std::setprecision(std::numeric_limits<long double>::digits10 + 2)
<< std::fixed;
file << freq << std::endl;
}
}
template <typename T>
void writeRadspecToFile(const std::string &filename,
std::pair<std::vector<T>, std::vector<T>> radspec) {
std::ofstream file;
file.open(filename);
auto xs = radspec.first;
auto ys = radspec.second;
if (xs.size() != ys.size()) {
std::cerr << "Dimensions of radial spactrum are unequal: xDim: "
<< xs.size() << " yDim: " << ys.size() << std::endl;
std::terminate();
}
for (int i = 0; i < xs.size(); ++i) {
file << std::setprecision(std::numeric_limits<long double>::digits10 + 2)
<< std::fixed;
file << xs[i] << ", " << ys[i] << std::endl;
}
}
int main() {
// load Points from file and generate metrics
auto loadedPoints =
utk::read_pointsets<long double>("../result_data/sampled.txt")[0];
auto pointView =
utk::Pointset<long double>::View(loadedPoints.Data(), NSAMPLES, 2);
// Radial spectrum
std::cout << "Calculating radial spectrum with " << NBINS
<< " bins and resolution " << DIMENSION << std::endl;
auto radSpec =
utk::RadialSpectrum(NBINS, 0.5, DIMENSION, true).compute(pointView);
writeRadspecToFile("radSpec.txt", radSpec);
// PCF
std::cout << "Calculating PCF with " << NBINS << " bins…" << std::endl;
auto pcf = utk::PCF{true, 0.01, 0.5, NBINS, 0.001}.compute(pointView);
writePCFToFile("pcf.txt", pcf);
// FFT based spectrum
std::cout << "Calculating spectrum with resolution " << DIMENSION << ""
<< std::endl;
auto spec = utk::Spectrum{DIMENSION, true}.compute(pointView);
writeSpectrumToFile("spectrum.txt", spec);
}