This example shows how to use Yeppp! library to compute the entropy of a distribution given by its probabilities:
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
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
12 s = yeplibrary_gettimerfrequency(frequency)
15 s = yeplibrary_gettimerticks(ticksstart)
16 s = yepmath_log_v64f_v64f(p, logp, n)
17 s = yepcore_dotproduct_v64fv64f_s64f(p, logp, h, n)
19 s = yeplibrary_gettimerticks(ticksend)
21 print*,
" Entropy =", h
22 print*,
" Time =",
REAL(ticksEnd - ticksStart) /
REAL(frequency)
24 s = yeplibrary_gettimerticks(ticksstart)
25 h = -dot_product(p, log(p))
26 s = yeplibrary_gettimerticks(ticksend)
28 print*,
" Entropy =", h
29 print*,
" Time =",
REAL(ticksEnd - ticksStart) /
REAL(frequency)
30 s = yeplibrary_release()