1 // This is brl/bbas/bsta/io/bsta_io_mixture_fixed.h
2 #ifndef bsta_io_mixture_fixed_h_
3 #define bsta_io_mixture_fixed_h_
4 //:
5 // \file
6 // \brief Binary I/O for a fixed mixture of distributions
7 // \author Matt Leotta (mleotta@lems.brown.edu)
8 // \date January 18, 2008
9 //
10 // \verbatim
11 // Modifications
12 // <none yet>
13 // \endverbatim
14
15 #include <iostream>
16 #include <bsta/bsta_mixture_fixed.h>
17 #include <vsl/vsl_binary_io.h>
18 #ifdef _MSC_VER
19 # include <vcl_msvc_warnings.h>
20 #endif
21
22 //: Binary save bsta_mixture_fixed to stream.
23 template <class comp_, unsigned s>
24 void
vsl_b_write(vsl_b_ostream & os,const bsta_mixture_fixed<comp_,s> & m)25 vsl_b_write(vsl_b_ostream &os, const bsta_mixture_fixed<comp_,s>& m)
26 {
27 unsigned size = m.num_components();
28 vsl_b_write(os,size);
29 for (unsigned i=0; i<size; ++i){
30 vsl_b_write(os,m.weight(i));
31 vsl_b_write(os,m.distribution(i));
32 }
33 }
34
35 //: Binary load bsta_mixture_fixed from stream.
36 template <class comp_, unsigned s>
37 void
vsl_b_read(vsl_b_istream & is,bsta_mixture_fixed<comp_,s> & m)38 vsl_b_read(vsl_b_istream &is, bsta_mixture_fixed<comp_,s>& m)
39 {
40 while (m.num_components()>0)
41 m.remove_last();
42
43 unsigned size;
44 vsl_b_read(is,size);
45 typename comp_::math_type weight;
46 comp_ dstrb;
47 for (unsigned i=0; i<size; ++i){
48 vsl_b_read(is,weight);
49 vsl_b_read(is,dstrb);
50 m.insert(dstrb,weight);
51 }
52 }
53
54 //: Print summary
55 template <class comp_, unsigned s>
56 void
vsl_print_summary(std::ostream & os,const bsta_mixture_fixed<comp_,s> & m)57 vsl_print_summary(std::ostream &os, const bsta_mixture_fixed<comp_,s>& m)
58 {
59 unsigned size = m.num_components();
60 os << "mixture with "<<size<<" components\n";
61 for (unsigned i=0; i<size; ++i){
62 os<<" weight:"<<m.weight(i)<<' ';
63 vsl_print_summary(os,m.distribution(i));
64 os <<"\n";
65 }
66 }
67
68
69 #endif // bsta_io_mixture_fixed_h_
70