File: coding_efficiency.c

package info (click to toggle)
schroedinger 1.0.11-2.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,480 kB
  • ctags: 6,139
  • sloc: ansic: 97,380; sh: 11,238; xml: 6,509; makefile: 387
file content (59 lines) | stat: -rw-r--r-- 1,379 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <schroedinger/schro.h>
#include <schroedinger/schroarith.h>
#include <math.h>

#include "arith.h"

#define N 100000


int efficiency_arith_dirac (int x, unsigned char *data, int n);
int efficiency_arith_exp (int x, unsigned char *data, int n);
int efficiency_arith_dirac_byte (int x, unsigned char *data, int n);
int efficiency_arith_dirac_stats (int x, unsigned char *data, int n);
int efficiency_arith_dirac_both (int x, unsigned char *data, int n);
int efficiency_arith_qm (int x, unsigned char *data, int n);


double
efficiency_entropy (double x)
{
  if (x == 0 || x == 1) return 0;

  return (x*log(x) + (1-x)*log(1-x))/log(0.5);
}


unsigned char data[N];

int
main (int argc, char *argv[])
{
  int x;
  double a, b, c, d, e, f;
  double y;

  schro_init();

  for(x = 0; x <= 256; x += 1) {
    y = efficiency_entropy (x/256.0);
    a = efficiency_arith_dirac (x, data, N) / (double)N / y;
    b = efficiency_arith_qm (x, data, N) / (double)N / y;
    c = efficiency_arith_dirac_byte (x, data, N) / (double)N / y;
    d = efficiency_arith_dirac_stats (x, data, N) / (double)N / y;
    e = efficiency_arith_dirac_both (x, data, N) / (double)N / y;
    f = efficiency_arith_exp (x, data, N) / (double)N / y;

    printf("%g %g %g %g %g %g %g\n", x/256.0, a, b, c, d, e, f);
  }

  return 0;
}