diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 12:08:18 +0000 |
commit | 5da14042f70711ea5cf66e034699730335462f66 (patch) | |
tree | 0f6354ccac934ed87a2d555f45be4c831cf92f4a /ml/dlib/dlib/svm/simplify_linear_decision_function.h | |
parent | Releasing debian version 1.44.3-2. (diff) | |
download | netdata-5da14042f70711ea5cf66e034699730335462f66.tar.xz netdata-5da14042f70711ea5cf66e034699730335462f66.zip |
Merging upstream version 1.45.3+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ml/dlib/dlib/svm/simplify_linear_decision_function.h')
-rw-r--r-- | ml/dlib/dlib/svm/simplify_linear_decision_function.h | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/ml/dlib/dlib/svm/simplify_linear_decision_function.h b/ml/dlib/dlib/svm/simplify_linear_decision_function.h deleted file mode 100644 index 4f5bef6f3..000000000 --- a/ml/dlib/dlib/svm/simplify_linear_decision_function.h +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (C) 2010 Davis E. King (davis@dlib.net) -// License: Boost Software License See LICENSE.txt for the full license. -#ifndef DLIB_SIMPLIFY_LINEAR_DECiSION_FUNCTION_Hh_ -#define DLIB_SIMPLIFY_LINEAR_DECiSION_FUNCTION_Hh_ - -#include "simplify_linear_decision_function_abstract.h" -#include "../algs.h" -#include "function.h" -#include "sparse_kernel.h" -#include "kernel.h" -#include <map> -#include <vector> - -namespace dlib -{ - -// ---------------------------------------------------------------------------------------- - - template < - typename T - > - decision_function<sparse_linear_kernel<T> > simplify_linear_decision_function ( - const decision_function<sparse_linear_kernel<T> >& df - ) - { - // don't do anything if we don't have to - if (df.basis_vectors.size() <= 1) - return df; - - decision_function<sparse_linear_kernel<T> > new_df; - - new_df.b = df.b; - new_df.basis_vectors.set_size(1); - new_df.alpha.set_size(1); - new_df.alpha(0) = 1; - - // now compute the weighted sum of all the sparse basis_vectors in df - typedef typename T::value_type pair_type; - typedef typename pair_type::first_type key_type; - typedef typename pair_type::second_type value_type; - std::map<key_type, value_type> accum; - for (long i = 0; i < df.basis_vectors.size(); ++i) - { - typename T::const_iterator j = df.basis_vectors(i).begin(); - const typename T::const_iterator end = df.basis_vectors(i).end(); - for (; j != end; ++j) - { - accum[j->first] += df.alpha(i) * (j->second); - } - } - - new_df.basis_vectors(0) = T(accum.begin(), accum.end()); - - return new_df; - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T - > - decision_function<linear_kernel<T> > simplify_linear_decision_function ( - const decision_function<linear_kernel<T> >& df - ) - { - // don't do anything if we don't have to - if (df.basis_vectors.size() <= 1) - return df; - - decision_function<linear_kernel<T> > new_df; - - new_df.b = df.b; - new_df.basis_vectors.set_size(1); - new_df.alpha.set_size(1); - new_df.alpha(0) = 1; - - // now compute the weighted sum of all the basis_vectors in df - new_df.basis_vectors(0) = 0; - for (long i = 0; i < df.basis_vectors.size(); ++i) - { - new_df.basis_vectors(0) += df.alpha(i) * df.basis_vectors(i); - } - - return new_df; - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T - > - decision_function<linear_kernel<T> > simplify_linear_decision_function ( - const normalized_function<decision_function<linear_kernel<T> >, vector_normalizer<T> >& df - ) - { - decision_function<linear_kernel<T> > new_df = simplify_linear_decision_function(df.function); - - // now incorporate the normalization stuff into new_df - new_df.basis_vectors(0) = pointwise_multiply(new_df.basis_vectors(0), df.normalizer.std_devs()); - new_df.b += dot(new_df.basis_vectors(0), df.normalizer.means()); - - return new_df; - } - -// ---------------------------------------------------------------------------------------- - -} - -#endif // DLIB_SIMPLIFY_LINEAR_DECiSION_FUNCTION_Hh_ - |