00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <stdio.h>
00024 #include <it/io.h>
00025 #include <it/vec.h>
00026 #include <it/vlc.h>
00027 #include <it/source.h>
00028
00029 int main (int argc, char **argv)
00030 {
00031 vlc_t *vlc;
00032 vec nodes_pdf;
00033 vec nodes_expectation;
00034 vec pdf = vec_new_string ("0.5 0.3 0.1 0.1");
00035 vec v1N = vec_new_1N (5);
00036 ivec S;
00037 bvec B;
00038 ivec D;
00039 int N = 20;
00040
00041 it_printf ("pdf = $v\n", pdf);
00042 it_printf ("symbols = $v\n", v1N);
00043
00044 vlc = vlc_hu_tucker (pdf);
00045 printf ("\n[ Hu-Tucker ]\n");
00046 vlc_print (vlc);
00047 printf ("\nmdl( vlc ) = %g\n", vlc_mdl (vlc, pdf));
00048
00049 nodes_pdf = vlc_nodes_pdf (vlc, pdf);
00050 nodes_expectation = vlc_nodes_expectation (vlc, pdf, v1N);
00051 it_printf ("\nP(nodes)=$v\nE(nodes)=$v\n", nodes_pdf, nodes_expectation);
00052 vlc_delete (vlc);
00053
00054 vlc = vlc_huffman (pdf);
00055 printf ("\n[ Huffman code ]\n");
00056 vlc_print (vlc);
00057 printf ("\nmdl( vlc ) = %g\n", vlc_mdl (vlc, pdf));
00058
00059 vlc_quasi_lexicographic (vlc, pdf, v1N);
00060 printf ("\n[ p-lex Huffman code ]\n");
00061 vlc_print_all (vlc, pdf, v1N);
00062 printf ("\nmdl( vlc ) = %g\n", vlc_mdl (vlc, pdf));
00063 printf ("minh( vlc ) = %d\n", vlc_minh (vlc));
00064 printf ("maxh( vlc ) = %d\n", vlc_maxh (vlc));
00065
00066 S = source_memoryless (N, pdf);
00067 printf ("Length( S ) = %d\n", ivec_length (S));
00068
00069 B = vlc_encode_concat (vlc, S);
00070
00071 D = vlc_decode_concat (vlc, B);
00072
00073 it_printf ("\n[Coding and Decoding]\nS = $d\nB = $b\nD = $d\n", S, B, D);
00074
00075
00076 vlc_delete (vlc);
00077 vlc = vlc_read ("{0 11 101 100}");
00078 printf ("Custom Code = ");
00079 vlc_print (vlc);
00080 printf ("\n");
00081
00082
00083 vlc_delete (vlc);
00084 vec_delete (pdf);
00085 vec_delete (v1N);
00086 ivec_delete (S);
00087 bvec_delete (B);
00088 ivec_delete (D);
00089 return 0;
00090 }