From 85b4941ca80c09cc8ff872f0a5001ff95bdfd2af Mon Sep 17 00:00:00 2001 From: Axel Wickman Date: Tue, 10 Sep 2019 12:13:43 -0300 Subject: [PATCH] Changed graph downsampling' --- Agent.cpp | 2 + GUI.cpp | 159 ++++++++++++++++++++++++++++++------------------------ 2 files changed, 92 insertions(+), 69 deletions(-) diff --git a/Agent.cpp b/Agent.cpp index a665971..25b533c 100644 --- a/Agent.cpp +++ b/Agent.cpp @@ -709,6 +709,8 @@ std::vector Agent::getRegressionActions(unsigned id) const { if (p[i] != p[i]){ // Nan-check p[i] = 0.f; } + // Increase the strength of the correlations + p[i] = 2.5f*p[i]; } return p; } diff --git a/GUI.cpp b/GUI.cpp index 4766860..3005c43 100644 --- a/GUI.cpp +++ b/GUI.cpp @@ -690,9 +690,18 @@ void GUI::Spectrogram::update(const World *world) { for (std::size_t y = 0; y < std::ceil(newSpec.getM()/2)-1; y++) { unsigned r = 0, g = 0, b = 0, a = 0; float total = 0; - std::vector colors = {spectrogram.at(x, y*2)}; + std::vector colors; + try { + colors = {spectrogram.at(x, y*2)}; + } catch (const std::out_of_range &e){ + printf("Is outarange a\n"); + } if (y*2+1 < spectrogram.getM()){ - colors.push_back(spectrogram.at(x, y*2+1)); + try { + colors.push_back(spectrogram.at(x, y * 2 + 1)); + } catch (const std::out_of_range &e) { + printf("Outarange b\n"); + } } for (auto &c : colors){ if (c.r == 0 && c.g == 0 && c.b == 0 && c.a == 0){ @@ -708,9 +717,12 @@ void GUI::Spectrogram::update(const World *world) { } r /= total; g /= total; b /= total; a /= total; - newSpec.at(x, y) = sf::Color(r, g, b, a); + try { + newSpec.at(x, y) = sf::Color(r, g, b, a); + } catch (const std::out_of_range &e){ + printf("IS outarange b\n"); + } } - printf("c"); } spectrogram = newSpec; @@ -718,83 +730,92 @@ void GUI::Spectrogram::update(const World *world) { currentSize.y = std::ceil(downsamplingTriggerH/2.0); } - std::vector> column(currentY); + try { + std::vector> column(currentY); + + std::vector totals(column.size(), 0.f); + // Global color column has to be of sufficient size + if (colorColumn.size() < column.size()) { + colorColumn.resize(column.size(), sf::Color(0, 0, 0, 0)); + colorColumnCount.resize(column.size(), 0); + } - std::vector totals(column.size(), 0.f); - // Global color column has to be of sufficient size - if (colorColumn.size() < column.size()){ - colorColumn.resize(column.size(), sf::Color(0, 0, 0, 0)); - colorColumnCount.resize(column.size(), 0); - } + // Draw values to column + for (const auto &value : values) { + std::size_t ind = (value.value - minVal) * (float) stride / (float) perRow; + mark(column, totals, ind, value.color, .8f, markerWidth); + } - // Draw values to column - for (const auto &value : values){ - std::size_t ind = (value.value - minVal)*(float) stride / (float) perRow; - mark(column, totals, ind, value.color, .8f, markerWidth); - } + // Divide in column to average colors + for (std::size_t i = 0; i < column.size(); i++) { + column.at(i).at(0) /= totals.at(i); + column.at(i).at(1) /= totals.at(i); + column.at(i).at(2) /= totals.at(i); + column.at(i).at(3) /= totals.at(i); + colorColumnCount.at(i)++; + } - // Divide in column to average colors - for (std::size_t i = 0; i < column.size(); i++){ - column.at(i).at(0) /= totals.at(i); column.at(i).at(1) /= totals.at(i); - column.at(i).at(2) /= totals.at(i); column.at(i).at(3) /= totals.at(i); - colorColumnCount.at(i)++; - } + // Add to spectrogram + columnCounter++; + if (columnCounter == perColumn) { + // Rescale the column if it too big + for (std::size_t i = 0; i < column.size(); i++) { + if (colorColumnCount.at(i) != 0) { + colorColumn.at(i).r += column.at(i).at(0); + colorColumn.at(i).g += column.at(i).at(1); + colorColumn.at(i).b += column.at(i).at(2); + colorColumn.at(i).a += column.at(i).at(3); + colorColumnCount.at(i) = 0; + } + } - // Add to spectrogram - columnCounter++; - if (columnCounter == perColumn){ - // Rescale the column if it too big - for (std::size_t i = 0; i < column.size(); i++){ - if (colorColumnCount.at(i) != 0){ - colorColumn.at(i).r += column.at(i).at(0); - colorColumn.at(i).g += column.at(i).at(1); - colorColumn.at(i).b += column.at(i).at(2); - colorColumn.at(i).a += column.at(i).at(3); - colorColumnCount.at(i) = 0; + auto p = spectrogram.at(currentSize.x); + auto itCol = p.first; + for (auto it = std::begin(colorColumn); it != std::end(colorColumn); it++) { + *itCol = *it; + itCol++; } - } - auto p = spectrogram.at(currentSize.x); - auto itCol = p.first; - for (auto it = std::begin(colorColumn); it != std::end(colorColumn); it++){ - *itCol = *it; - itCol++; + currentSize.x += 1; + currentSize.y = std::max((std::size_t) currentSize.y, colorColumn.size()); + colorColumn.clear(); + colorColumnCount.clear(); + columnCounter = 0; } - currentSize.x += 1; - currentSize.y = std::max((std::size_t) currentSize.y, colorColumn.size()); - colorColumn.clear(); colorColumnCount.clear(); columnCounter = 0; - } - - // Check if spectrogram is too wide - if (spectrogram.getN() <= currentSize.x){ - // Half width - auto newSpec = Contiguous2dVector(spectrogram.getN(), spectrogram.getM(), spectrogram.getFillValue()); - for (std::size_t x = 0; x < std::ceil(newSpec.getN()/2.0); x++) { - for (std::size_t y = 0; y < newSpec.getM(); y++) { - unsigned r = 0, g = 0, b = 0, a = 0; - float total = 0; - for (auto &c : {spectrogram.at(x*2, y), spectrogram.at(x*2+1, y)}){ - if (c.r == 0 && c.g == 0 && c.b == 0 && c.a == 0){ - total += 0; - } - else { - r += c.r; - g += c.g; - b += c.b; - a += c.a; - total += 1; + // Check if spectrogram is too wide + if (spectrogram.getN() <= currentSize.x) { + // Half width + auto newSpec = Contiguous2dVector(spectrogram.getN(), spectrogram.getM(), spectrogram.getFillValue()); + for (std::size_t x = 0; x < std::ceil(newSpec.getN() / 2.0); x++) { + for (std::size_t y = 0; y < newSpec.getM(); y++) { + unsigned r = 0, g = 0, b = 0, a = 0; + float total = 0; + for (auto &c : {spectrogram.at(x * 2, y), spectrogram.at(x * 2 + 1, y)}) { + if (c.r == 0 && c.g == 0 && c.b == 0 && c.a == 0) { + total += 0; + } else { + r += c.r; + g += c.g; + b += c.b; + a += c.a; + total += 1; + } } + r /= total; + g /= total; + b /= total; + a /= total; + newSpec.at(x, y) = sf::Color(r, g, b, a); } - r /= total; g /= total; - b /= total; a /= total; - newSpec.at(x, y) = sf::Color(r, g, b, a); } - } - spectrogram = newSpec; - perColumn *= 2; - currentSize.x = std::ceil(currentSize.x/2.0); + spectrogram = newSpec; + perColumn *= 2; + currentSize.x = std::ceil(currentSize.x / 2.0); + } + } catch (const std::out_of_range &e){ + printf("Other outarange\n"); } }