#ifndef __FILE_GSMUSR_H_SEEN__
#define __FILE_GSMUSR_H_SEEN__

/*-----------------------------------------------------------------------------

Copyright (C) 2004, 2006.

A. Ronald Gallant
Post Office Box 659
Chapel Hill NC 27514-0659
USA   

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

-----------------------------------------------------------------------------*/

#include "libsnp.h"
#include "snp.h"
#include "libgsm.h"

namespace gsm {
    
  using scl::intvec;
  using scl::realmat;
  using scl::kronprd;

  class sv_sci_mod;
  class snp_stat_mod;

  typedef sv_sci_mod   sci_mod_type;
  typedef snp_stat_mod stat_mod_type;

  class sv_sci_mod : public libgsm::sci_mod_base {
  private:
    realmat theta;
    INTEGER slen;
    INTEGER spin;
    const INTEGER ltheta;
    const INTEGER lfunc;
  public:
    sv_sci_mod
      (const realmat* dat_ptr, const std::vector<std::string>& pfvec,
       const std::vector<std::string>& alvec, std::ostream& detail);
    INTEGER len_parm() {return ltheta;}
    INTEGER len_func() {return lfunc;}
    void get_parm(realmat& parm) { parm = theta; }
    void set_parm(const realmat& parm) { theta = parm; }
    bool support(const realmat& parm);
    scl::den_val prior(const realmat& parm, const realmat& func);
    bool gen_sim(realmat& sim, realmat& func);
  };

  class snp_stat_mod : public libgsm::stat_mod_base {
  private:
    realmat Xlags;           // First few transformed and squashed
    realmat Ylags;           // observations to get lags for gen_sim
    realmat X;               // Transformed and squashed data or simulation
    realmat Y;               // maintained by set_data_ptr for use by logl, 
    snp::trnfrm tr;
    snp::snpll ll;
    INTEGER lsim;
    INTEGER spin;
    INTEGER lrho;
    INTEGER lstats;
    bool snp_simulate(INT_32BIT& iseed, realmat& sim);
  public:
    snp_stat_mod
      (const realmat* dat_ptr, const std::vector<std::string>& pfvec,
       const std::vector<std::string>& alvec, std::ostream& detail);
    INTEGER len_parm() {return lrho;}
    INTEGER len_func() {return lstats;}
    INTEGER num_obs() {return Y.get_cols();}
    void    get_parm(realmat& rho);
    void    set_parm(const realmat& rho);
    void    set_data_ptr(const realmat* dat_ptr);
    bool    support(const realmat& rho);
    scl::den_val prior(const realmat& rho, const realmat& stats);
    bool    gen_sim(realmat& sim, realmat& stats);
    scl::den_val loglikelihood();
    scl::den_val loglikelihood(realmat& dlogl);
    REAL    penalty(realmat& dpenalty);
  };
  
}
#endif
