contrib/mul/mcal/mcal_sparse_basis_cost.h
Go to the documentation of this file.
00001 #ifndef mcal_sparse_basis_cost_h
00002 #define mcal_sparse_basis_cost_h
00003 //:
00004 // \file
00005 // \author Tim Cootes
00006 // \brief Cost function to promote sparse basis vectors
00007 
00008 #include <mcal/mcal_single_basis_cost.h>
00009 #include <vnl/io/vnl_io_vector.h>
00010 #include <vnl/io/vnl_io_matrix.h>
00011 #include <vcl_iosfwd.h>
00012 
00013 //: Cost function to promote sparse basis vectors
00014 //  Cost is log(variance) + alpha sum |e_i|, which encourages concentration
00015 //  in non-zero elements of the basis vector
00016 class mcal_sparse_basis_cost : public mcal_single_basis_cost
00017 {
00018  private:
00019   //: Weighting for sparseness penalty
00020   double alpha_;
00021 
00022  public:
00023 
00024   //: Dflt ctor
00025   mcal_sparse_basis_cost();
00026 
00027   //: Destructor
00028   virtual ~mcal_sparse_basis_cost();
00029 
00030   //: Weighting for sparseness penalty
00031   double alpha() const { return alpha_; }
00032 
00033   //: Weighting for sparseness penalty
00034   void set_alpha(double a);
00035 
00036   //: Returns true since cost can be computed from the variance.
00037   virtual bool can_use_variance() const;
00038 
00039   //: Compute component of the cost function from given basis vector
00040   // \param[in] unit_basis   Unit vector defining basis direction
00041   // \param[in] projections  Projections of the dataset onto this basis vector
00042   virtual double cost(const vnl_vector<double>& unit_basis,
00043                       const vnl_vector<double>& projections);
00044 
00045   //: Compute component of the cost function from given basis vector
00046   // Cost is log(variance) + alpha sum |e_i|.
00047   // \param[in] unit_basis Unit vector defining basis direction
00048   // \param[in] variance   Variance of projections of the dataset onto this basis vector
00049   virtual double cost_from_variance(const vnl_vector<double>& unit_basis,
00050                                     double variance);
00051 
00052   //: Version number for I/O
00053   short version_no() const;
00054 
00055   //: Name of the class
00056   virtual vcl_string is_a() const;
00057 
00058   //: Create a copy on the heap and return base class pointer
00059   virtual  mcal_single_basis_cost*  clone()  const;
00060 
00061   //: Print class to os
00062   virtual void print_summary(vcl_ostream& os) const;
00063 
00064   //: Save class to binary file stream
00065   virtual void b_write(vsl_b_ostream& bfs) const;
00066 
00067   //: Load class from binary file stream
00068   virtual void b_read(vsl_b_istream& bfs);
00069 
00070   //: Read initialisation settings from a stream.
00071   // Parameters:
00072   // \verbatim
00073   // {
00074   //   alpha: 1.0
00075   // }
00076   // \endverbatim
00077   // \throw mbl_exception_parse_error if the parse fails.
00078   virtual void config_from_stream(vcl_istream & is);
00079 };
00080 
00081 #endif // mcal_sparse_basis_cost_h