Yeppp!
 All Classes Groups Pages
Entropy.f90

This example shows how to use Yeppp! library to compute the entropy of a distribution given by its probabilities:

1 program entropy
2  USE yeplibrary, ONLY: yeplibrary_init, yeplibrary_release, yeplibrary_gettimerfrequency, yeplibrary_gettimerticks
3  USE yepcore, ONLY: yepcore_dotproduct_v64fv64f_s64f
4  USE yepmath, ONLY: yepmath_log_v64f_v64f
5  USE iso_c_binding, ONLY : c_size_t, c_int64_t, c_int, c_double
6  implicit none
7  INTEGER(C_SIZE_T), PARAMETER :: n = 1024*1024*16
8  INTEGER(C_INT64_T) :: ticksstart, ticksend, frequency
9  real(C_DOUBLE) :: p(n), logp(n), h
10  integer(C_INT) :: s
11  s = yeplibrary_init()
12  s = yeplibrary_gettimerfrequency(frequency)
13  call random_number(p)
14 
15  s = yeplibrary_gettimerticks(ticksstart)
16  s = yepmath_log_v64f_v64f(p, logp, n)
17  s = yepcore_dotproduct_v64fv64f_s64f(p, logp, h, n)
18  h = -h
19  s = yeplibrary_gettimerticks(ticksend)
20  print*, "Yeppp!"
21  print*, " Entropy =", h
22  print*, " Time =", REAL(ticksEnd - ticksStart) / REAL(frequency)
23 
24  s = yeplibrary_gettimerticks(ticksstart)
25  h = -dot_product(p, log(p))
26  s = yeplibrary_gettimerticks(ticksend)
27  print*, "Naive"
28  print*, " Entropy =", h
29  print*, " Time =", REAL(ticksEnd - ticksStart) / REAL(frequency)
30  s = yeplibrary_release()
31 end