123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
- // Copyright 2008-2016 National ICT Australia (NICTA)
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- // ------------------------------------------------------------------------
- //! \addtogroup gmm_misc
- //! @{
- namespace gmm_priv
- {
- template<typename eT>
- inline
- running_mean_scalar<eT>::running_mean_scalar()
- : counter(uword(0))
- , r_mean ( eT(0))
- {
- arma_extra_debug_sigprint_this(this);
- }
- template<typename eT>
- inline
- running_mean_scalar<eT>::running_mean_scalar(const running_mean_scalar<eT>& in)
- : counter(in.counter)
- , r_mean (in.r_mean )
- {
- arma_extra_debug_sigprint_this(this);
- }
- template<typename eT>
- inline
- const running_mean_scalar<eT>&
- running_mean_scalar<eT>::operator=(const running_mean_scalar<eT>& in)
- {
- arma_extra_debug_sigprint();
-
- counter = in.counter;
- r_mean = in.r_mean;
-
- return *this;
- }
- template<typename eT>
- arma_hot
- inline
- void
- running_mean_scalar<eT>::operator() (const eT X)
- {
- arma_extra_debug_sigprint();
-
- counter++;
-
- if(counter > 1)
- {
- const eT old_r_mean = r_mean;
-
- r_mean = old_r_mean + (X - old_r_mean)/counter;
- }
- else
- {
- r_mean = X;
- }
- }
- template<typename eT>
- inline
- void
- running_mean_scalar<eT>::reset()
- {
- arma_extra_debug_sigprint();
-
- counter = 0;
- r_mean = eT(0);
- }
- template<typename eT>
- inline
- uword
- running_mean_scalar<eT>::count() const
- {
- return counter;
- }
- template<typename eT>
- inline
- eT
- running_mean_scalar<eT>::mean() const
- {
- return r_mean;
- }
- //
- //
- //
- template<typename eT>
- arma_inline
- arma_hot
- eT
- distance<eT, uword(1)>::eval(const uword N, const eT* A, const eT* B, const eT*)
- {
- eT acc1 = eT(0);
- eT acc2 = eT(0);
-
- uword i,j;
- for(i=0, j=1; j<N; i+=2, j+=2)
- {
- eT tmp_i = A[i];
- eT tmp_j = A[j];
-
- tmp_i -= B[i];
- tmp_j -= B[j];
-
- acc1 += tmp_i*tmp_i;
- acc2 += tmp_j*tmp_j;
- }
-
- if(i < N)
- {
- const eT tmp_i = A[i] - B[i];
-
- acc1 += tmp_i*tmp_i;
- }
-
- return (acc1 + acc2);
- }
- template<typename eT>
- arma_inline
- arma_hot
- eT
- distance<eT, uword(2)>::eval(const uword N, const eT* A, const eT* B, const eT* C)
- {
- eT acc1 = eT(0);
- eT acc2 = eT(0);
-
- uword i,j;
- for(i=0, j=1; j<N; i+=2, j+=2)
- {
- eT tmp_i = A[i];
- eT tmp_j = A[j];
-
- tmp_i -= B[i];
- tmp_j -= B[j];
-
- acc1 += (tmp_i*tmp_i) * C[i];
- acc2 += (tmp_j*tmp_j) * C[j];
- }
-
- if(i < N)
- {
- const eT tmp_i = A[i] - B[i];
-
- acc1 += (tmp_i*tmp_i) * C[i];
- }
-
- return (acc1 + acc2);
- }
- }
- //! @}
|