Skip to content

Commit

Permalink
inplace scale and use std::numeric_limits
Browse files Browse the repository at this point in the history
  • Loading branch information
vigsterkr committed May 30, 2018
1 parent 4a1299e commit 15624ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/shogun/machine/BaggingMachine.cpp
@@ -1,7 +1,7 @@
/*
* This software is distributed under BSD 3-clause license (see LICENSE file).
*
* Authors: Viktor Gal, Saurabh Mahindre, Heiko Strathmann, Thoralf Klein,
* Authors: Viktor Gal, Saurabh Mahindre, Heiko Strathmann, Thoralf Klein,
* Olivier NGuyen, Bjoern Esser, Weijie Lin
*/

Expand Down Expand Up @@ -89,7 +89,7 @@ CMulticlassLabels* CBaggingMachine::apply_multiclass(CFeatures* data)
}
}

class_probabilities = linalg::scale(class_probabilities, 1.0 / m_num_bags);
linalg::scale(class_probabilities, class_probabilities, 1.0 / m_num_bags);

for (auto i = 0; i < num_samples; ++i)
pred->set_multiclass_confidences(i, class_probabilities.get_column(i));
Expand Down
5 changes: 3 additions & 2 deletions src/shogun/preprocessor/KernelPCA.cpp
@@ -1,14 +1,15 @@
/*
* This software is distributed under BSD 3-clause license (see LICENSE file).
*
* Authors: Soeren Sonnenburg, Sergey Lisitsyn, Michele Mazzoni, Evan Shelhamer,
* Authors: Soeren Sonnenburg, Sergey Lisitsyn, Michele Mazzoni, Evan Shelhamer,
* Heiko Strathmann, Evgeniy Andreev, Thoralf Klein, Giovanni De Toni
*/

#include <shogun/preprocessor/KernelPCA.h>
#include <shogun/lib/config.h>
#include <shogun/mathematics/Math.h>

#include <limits>
#include <string.h>
#include <stdlib.h>

Expand Down Expand Up @@ -106,7 +107,7 @@ bool CKernelPCA::init(CFeatures* features)
auto idx = m_target_dim - i - 1;
auto vec = eigenvectors.get_column(idx);
linalg::scale(
vec, vec, 1.0 / std::sqrt(CMath::max(1e-16, eigenvalues[idx])));
vec, vec, 1.0 / std::sqrt(std::max(std::numeric_limits<float64_t>::epsilon(), eigenvalues[idx])));
m_transformation_matrix.set_column(i, vec);
}

Expand Down

0 comments on commit 15624ba

Please sign in to comment.