Skip to content

Commit

Permalink
Layout fixes. And some refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
izzat5233 committed Dec 19, 2023
1 parent 03c3a7e commit fc45d06
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
15 changes: 8 additions & 7 deletions nn/src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ double Module::getLearningRate() const {
}

void Module::NormalizedData::set(const vvd_t &data) {
minMax.resize(data[0].size());
for (std::size_t i = 0; i < minMax.size(); ++i) {
minMax.clear();
minMax.reserve(data[0].size());
for (std::size_t i = 0; i < data[0].size(); ++i) {
double minParam = data[0][i];
double maxParam = data[0][i];
for (std::size_t j = 1; j < data.size(); ++j) {
minParam = std::min(minParam, data[j][i]);
maxParam = std::max(maxParam, data[j][i]);
}
minMax[i] = {minParam, maxParam};
minMax.emplace_back(minParam, maxParam);
}
normalized = normalize(data);
}
Expand All @@ -76,17 +77,17 @@ const vvd_t &Module::NormalizedData::use() const {
vvd_t Module::NormalizedData::normalize(const nn::vvd_t &original) const {
vvd_t norm;
norm.reserve(original.size());
for (std::size_t i = 0; i < original.size(); ++i) {
norm.push_back(process::minmax(original[i], minMax));
for (const vd_t &data: original) {
norm.push_back(process::minmax(data, minMax));
}
return norm;
}

vvd_t Module::NormalizedData::denormalize(const vvd_t &processed) const {
vvd_t original;
original.reserve(processed.size());
for (std::size_t i = 0; i < processed.size(); ++i) {
original.push_back(process::inverseMinmax(processed[i], minMax));
for (const vd_t &data: processed) {
original.push_back(process::inverseMinmax(data, minMax));
}
return original;
}
Expand Down
4 changes: 0 additions & 4 deletions nn/src/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ using namespace nn;

vd_t process::minmax(const vd_t &data, const vpd_t &minMaxParams) {
assert(data.size() == minMaxParams.size());
if (data.size() == 1) { return {data[0]}; } // turn off for single vectors

vd_t normalized(data.size());
for (std::size_t i = 0; i < data.size(); ++i) {
auto [minParam, maxParam] = minMaxParams[i];
Expand All @@ -22,8 +20,6 @@ vd_t process::minmax(const vd_t &data, const vpd_t &minMaxParams) {

vd_t process::inverseMinmax(const vd_t &data, const vpd_t &minMaxParams) {
assert(data.size() == minMaxParams.size());
if (data.size() == 1) { return {data[0]}; } // turn off for single vectors

vd_t denormalized(data.size());
for (std::size_t i = 0; i < data.size(); ++i) {
auto [minParam, maxParam] = minMaxParams[i];
Expand Down
20 changes: 8 additions & 12 deletions web/content/control/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@
<div class="d-flex justify-content-center">
<div class="btn-group" role="group" aria-label="Get Outputs">
<button type="button" class="btn btn-lg btn-primary fs-5" onclick="getTestOutputs()">
Get Test Outputs
Get Predictions
</button>
<button type="button" class="btn btn-lg btn-outline-primary bi bi-download fs-5" disabled
id="downloadOutputsButton" onclick="network.downloadPredictedOutputs()"> Download
<button type="button" class="btn btn-lg btn-outline-primary bi bi-x-lg fs-5"
id="clearOutputsButton" onclick="clearPredictedTable()"> Clear
</button>
<button type="button" class="btn btn-lg btn-outline-primary bi bi-download fs-5"
id="downloadWeightsButton" onclick="network.downloadNetwork()"> Download Network Data
</button>
<button type="button" class="btn btn-lg btn-outline-primary fs-5"
id="clearOutputsButton" onclick="clearPredictedTable()">Clear
<button type="button" class="btn btn-lg btn-outline-primary bi bi-download fs-5" disabled
id="downloadOutputsButton" onclick="network.downloadPredictedOutputs()"> Download Predictions
</button>
</div>
</div>
</div>
<div class="col">
<div class="d-flex justify-content-center">
<button type="button" class="btn btn-lg btn-primary bi bi-download fs-5" id="downloadWeightsButton"
onclick="network.downloadNetwork()"> Download Network Weights
</button>
</div>
</div>
</div>
<hr class="my-4">
<div class="container">
Expand Down

0 comments on commit fc45d06

Please sign in to comment.