weighted sum (Descriptive Statistics)


Import

#include <archr/stats/weighted_sum.h>
#include <archr/stats/weighted_sum.hpp>
import archr.stats
atomsLoads('archr')

Synopsis

 float archr_stats_weighted_sum_f32f32(const float *first, size_t nbelem, const float *second);
(1)
 double archr_stats_weighted_sum_f64f64(const double *first, size_t nbelem, const double *second);
(2)
 int8_t archr_stats_weighted_sum_i8i8(const int8_t *first, size_t nbelem, const int8_t *second);
(3)
 int16_t archr_stats_weighted_sum_i16i16(const int16_t *first, size_t nbelem, const int16_t *second);
(4)
 int32_t archr_stats_weighted_sum_i32i32(const int32_t *first, size_t nbelem, const int32_t *second);
(5)
 int64_t archr_stats_weighted_sum_i64i64(const int64_t *first, size_t nbelem, const int64_t *second);
(6)
 uint8_t archr_stats_weighted_sum_u8u8(const uint8_t *first, size_t nbelem, const uint8_t *second);
(7)
 uint16_t archr_stats_weighted_sum_u16u16(const uint16_t *first, size_t nbelem, const uint16_t *second);
(8)
 uint32_t archr_stats_weighted_sum_u32u32(const uint32_t *first, size_t nbelem, const uint32_t *second);
(9)
 uint64_t archr_stats_weighted_sum_u64u64(const uint64_t *first, size_t nbelem, const uint64_t *second);
(10)
 float weighted_sum(const float *first, size_t nbelem, const float *second);
(1)
 double weighted_sum(const double *first, size_t nbelem, const double *second);
(2)
 int8_t weighted_sum(const int8_t *first, size_t nbelem, const int8_t *second);
(3)
 int16_t weighted_sum(const int16_t *first, size_t nbelem, const int16_t *second);
(4)
 int32_t weighted_sum(const int32_t *first, size_t nbelem, const int32_t *second);
(5)
 int64_t weighted_sum(const int64_t *first, size_t nbelem, const int64_t *second);
(6)
 uint8_t weighted_sum(const uint8_t *first, size_t nbelem, const uint8_t *second);
(7)
 uint16_t weighted_sum(const uint16_t *first, size_t nbelem, const uint16_t *second);
(8)
 uint32_t weighted_sum(const uint32_t *first, size_t nbelem, const uint32_t *second);
(9)
 uint64_t weighted_sum(const uint64_t *first, size_t nbelem, const uint64_t *second);
(10)
 float weighted_sum(const float *first1, const float *last1, const float *first2);
(11)
 double weighted_sum(const double *first1, const double *last1, const double *first2);
(12)
 int8_t weighted_sum(const int8_t *first1, const int8_t *last1, const int8_t *first2);
(13)
 int16_t weighted_sum(const int16_t *first1, const int16_t *last1, const int16_t *first2);
(14)
 int32_t weighted_sum(const int32_t *first1, const int32_t *last1, const int32_t *first2);
(15)
 int64_t weighted_sum(const int64_t *first1, const int64_t *last1, const int64_t *first2);
(16)
 uint8_t weighted_sum(const uint8_t *first1, const uint8_t *last1, const uint8_t *first2);
(17)
 uint16_t weighted_sum(const uint16_t *first1, const uint16_t *last1, const uint16_t *first2);
(18)
 uint32_t weighted_sum(const uint32_t *first1, const uint32_t *last1, const uint32_t *first2);
(19)
 uint64_t weighted_sum(const uint64_t *first1, const uint64_t *last1, const uint64_t *first2);
(20)
template <typename Range> typename Range::value_type weighted_sum(const Range& data1, const Range& data2);
(21)
subroutine archr_stats_weighted_sum_f32f32(real(4) :: r, real(4), dimension(*), parameter :: first, integer(4) :: nbelem, real(4), dimension(*), parameter :: second)
(1)
subroutine archr_stats_weighted_sum_i32i32(integer(4) :: r, integer(4), dimension(*), parameter :: first, integer(4) :: nbelem, integer(4), dimension(*), parameter :: second)
(2)
subroutine archr_stats_weighted_sum_u32u32(integer(4) :: r, integer(4), dimension(*), parameter :: first, integer(4) :: nbelem, integer(4), dimension(*), parameter :: second)
(3)
def weighted_sum(first, second):
    return r
(1)
function r = archr_stats_weighted_sum(first, second)
(1)

Description

This function computes the weighted sum of the elements stored in:

Parameters

first

the beginning of the range of elements to sum.

last

the end of the range of elements to sum.

second

the beginning of the range of weights.

nbelem

the number of elements to sum.

Return value

The weighted sum of the elements in the given range.

Example

#include <archr/stats/weighted_sum.h>
#include <stdio.h>

int main()
{
  float v[] = { 1,   2,    3,    4,   5 }
      , w[] = { 1,0.5f,1/3.f,0.25f,0.2f };

  printf("weighted_sum({1,2,3},{1,0.5,0.3}) = %f\n", archr_stats_weighted_sum_f32f32(&v[0],3,&w[0]));

  return 0;
}

Possible Output

weighted_sum({1,2,3,4,5},{1,0.5,0.3,0.25,0.2}) = 5.000000
weighted_sum({1,2,3},{1,0.5,0.3}) = 3.000000
#include <archr/stats/weighted_sum.hpp>
#include <iostream>
#include <vector>

int main()
{
  std::vector<float> v{1,2,3,4,5}, w{1,0.5f,1/3.f,0.25f,0.2f};

  std::cout << "weighted_sum({1,2,3,4,5},{1,0.5,0.3,0.25,0.2}) = " << archr::stats::weighted_sum(v,w) << "\n";
  std::cout << "weighted_sum({1,2,3},{1,0.5,0.3}) = " << archr::stats::weighted_sum(v.data(),3,w.data()) << "\n";
  std::cout << "weighted_sum({1,2,3},{1,0.5,0.3}) = " << archr::stats::weighted_sum(v.data(),v.data()+3,w.data()) << "\n";

  return 0;
}

Possible Output

weighted_sum({1,2,3,4,5},{1,0.5,0.3,0.25,0.2}) = 5
weighted_sum({1,2,3},{1,0.5,0.3}) = 3
weighted_sum({1,2,3},{1,0.5,0.3}) = 3

Possible Output