void Chain_Factorial::initialise_pars(NumericMatrix w_, NumericVector transition_probs_, IntegerVector x_, int nrow_Y_){
  nrow_Y = nrow_Y_;
  // draw pi from the prior
  NumericVector pi_pars(k);
  initialise_const_vec(pi_pars, alpha, k);
  rdirichlet_vec(pi_pars, pi, k);
  
  u = NumericMatrix(nrow_Y, K);
  w = NumericMatrix(nrow_Y, K);
  for(int i=0; i<nrow_Y; i++){
    for(int k=0; k<K; k++){
      u(i, k) = w_(i, k);
      // u(i, k) = R::rgamma(1.0, 1.0);
    }
    w(i, _) = u(i, _) / sum(u(i, _));
  }
  
  mu_all = NumericMatrix(nrow_Y, k);
  update_mu_for_all_states(nrow_Y);
  
  transition_probs = clone(transition_probs_);
  FHMM_update_A(transition_probs, A, mapping);
  for(int t=0; t<n; t++){
    x[t] = x_[t];
  }
  convert_x_to_X();
}
Beispiel #2
0
NumericMatrix  Clmbr::cr4R( double CL,  int met, 
	 double incr,  int verboseR ) 
{ 
	if(Model==M3)  {
		Rcout << model_msg << endl << endl;
		return  NumericMatrix(0,0);
	}  

	if(CL <=0. || CL >=1.)  stop( CLmsg );
	const double tmp = SL;
	set_SL(1.-CL);

	METHOD MET;
	if(met==1)  MET=GEO;  else  {
		if(met==2)  MET=AF;  else  { 
			stop( methods2msg );
		}
	}

	double inc;
	if( incr == -1 )  inc= xinc;  else  inc= incr;

	const double  maxwidth = xs[ns-1] - xs[0] + 2;						
	const int  Nmax = maxwidth/inc + ns + 3;

	double*  Btmp= Calloc( Nmax*3, double );

	const bool  verbose = static_cast<bool>( verboseR );
	if( verbose )  
		stop( "dummy argument for dispatch, should be FALSE" );


	const int  nrows = cr( MET, incr, false, Btmp ); 


	set_SL(tmp);

	NumericMatrix  bds( nrows, 3 );
	for(int i=0;i<nrows;i++)  {
		bds(i,0) = *(Btmp + 0*nrows + i);
		bds(i,1) = *(Btmp + 1*nrows + i);
		bds(i,2) = *(Btmp + 2*nrows + i);
	}
	Free( Btmp );

	return bds;
}