contrib/brl/bbas/bsta/io/bsta_io_mixture_fixed.h
Go to the documentation of this file.
00001 // This is brl/bbas/bsta/io/bsta_io_mixture_fixed.h
00002 #ifndef bsta_io_mixture_fixed_h_
00003 #define bsta_io_mixture_fixed_h_
00004 //:
00005 // \file
00006 // \brief Binary I/O for a fixed mixture of distributions
00007 // \author Matt Leotta (mleotta@lems.brown.edu)
00008 // \date January 18, 2008
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   <none yet>
00013 // \endverbatim
00014 
00015 #include <bsta/bsta_mixture_fixed.h>
00016 #include <vsl/vsl_binary_io.h>
00017 #include <vcl_iostream.h>
00018 
00019 //: Binary save bsta_mixture_fixed to stream.
00020 template <class comp_, unsigned s>
00021 void
00022 vsl_b_write(vsl_b_ostream &os, const bsta_mixture_fixed<comp_,s>& m)
00023 {
00024   unsigned size = m.num_components();
00025   vsl_b_write(os,size);
00026   for (unsigned i=0; i<size; ++i){
00027     vsl_b_write(os,m.weight(i));
00028     vsl_b_write(os,m.distribution(i));
00029   }
00030 }
00031 
00032 //: Binary load bsta_mixture_fixed from stream.
00033 template <class comp_, unsigned s>
00034 void
00035 vsl_b_read(vsl_b_istream &is, bsta_mixture_fixed<comp_,s>& m)
00036 {
00037   while (m.num_components()>0)
00038     m.remove_last();
00039 
00040   unsigned size;
00041   vsl_b_read(is,size);
00042   typename comp_::math_type weight;
00043   comp_ dstrb;
00044   for (unsigned i=0; i<size; ++i){
00045     vsl_b_read(is,weight);
00046     vsl_b_read(is,dstrb);
00047     m.insert(dstrb,weight);
00048   }
00049 }
00050 
00051 //: Print summary
00052 template <class comp_, unsigned s>
00053 void
00054 vsl_print_summary(vcl_ostream &os, const bsta_mixture_fixed<comp_,s>& m)
00055 {
00056   unsigned size = m.num_components();
00057   os << "mixture with "<<size<<" components\n";
00058   for (unsigned i=0; i<size; ++i){
00059     os<<"  weight:"<<m.weight(i)<<' ';
00060     vsl_print_summary(os,m.distribution(i));
00061     os <<"\n";
00062   }
00063 }
00064 
00065 
00066 #endif // bsta_io_mixture_fixed_h_