예제 #1
0
void Pulsar::ComponentModel::evaluate (float *vals,
				       unsigned nvals, int icomp_selected) 
{
  //Construct the summed model
  SumRule< Univariate<Scalar> > m; 
  if (icomp_selected >= 0)
  {
    check ("evaluate", icomp_selected);
    m += components[icomp_selected];
  }
  else
  {
    for (unsigned icomp=0; icomp < components.size(); icomp++)
      m += components[icomp];
  }

  // evaluate
  Axis<double> argument;  
  m.set_argument (0, &argument);

  for (unsigned i=0; i < nvals; i++)
  { 
    argument.set_value( (i+0.5)/nvals * 2*M_PI );
    vals[i] = m.evaluate();
  }
}
예제 #2
0
void Pulsar::ComponentModel::evaluate (float *vals,
				       unsigned nvals, int icomp_selected) 
{
  double phase_offset = 0;
  if (report_absolute_phases)
    phase_offset = phase->get_value().val;

  if (verbose)
    cerr << "Pulsar::ComponentModel::evaluate"
      " phase_offset=" << phase_offset/(2*M_PI) << " turns" << endl;
  
  //Construct the summed model
  SumRule< Univariate<Scalar> > m; 
  if (icomp_selected >= 0)
  {
    check ("evaluate", icomp_selected);
    m += components[icomp_selected];
  }
  else
  {
    for (unsigned icomp=0; icomp < components.size(); icomp++)
      m += components[icomp];
  }

  // evaluate
  Axis<double> argument;  
  m.set_argument (0, &argument);

  for (unsigned i=0; i < nvals; i++)
  { 
    argument.set_value( (i+0.5)/nvals * 2*M_PI + phase_offset );
    vals[i] = m.evaluate();
  }
}
예제 #3
0
void Pulsar::ComponentModel::build () const
{
  if (model)
    return;

  SumRule< Univariate<Scalar> >* sum = new SumRule< Univariate<Scalar> >; 
  model = sum;

  if (fit_derivative)
  {
    derivative.resize (components.size());

    // setup model using derivative components
    for (unsigned icomp=0; icomp < components.size(); icomp++)
    {
      derivative[icomp] = new ScaledVonMisesDeriv;

      derivative[icomp]->set_centre(components[icomp]->get_centre());
      derivative[icomp]->set_concentration
	(components[icomp]->get_concentration());
      derivative[icomp]->set_height(components[icomp]->get_height());
      sum->add_model( derivative[icomp] );
    }
  }
  else
  {
    for (unsigned icomp=0; icomp < components.size(); icomp++)
      sum->add_model( components[icomp] );
  }

  if (phase)
  {
    if (verbose)
      cerr << "Pulsar::ComponentModel::build single phase" << endl;

    backup.resize (components.size());

    ChainRule<Univariate<Scalar> >* chain = new ChainRule<Univariate<Scalar> >;
    chain->set_model (sum);

    model = chain;

    for (unsigned icomp=0; icomp < components.size(); icomp++)
    {
      if (sum->get_param_name(icomp*3) != "centre")
	throw Error (InvalidState, "Pulsar::ComponentModel::fit",
		     "iparam=%u name='%s'", icomp*3,
		     sum->get_param_name(icomp*3).c_str());

      if (sum->get_param_name(icomp*3+1) != "concentration")
	throw Error (InvalidState, "Pulsar::ComponentModel::fit",
		     "iparam=%u name='%s'", icomp*3,
		     sum->get_param_name(icomp*3).c_str());

      // don't allow the widths to vary
      sum->set_infit(icomp*3+1, false);

      backup[icomp] = components[icomp]->clone();

      SumRule<Scalar>* psum = new SumRule<Scalar>;
      psum->add_model (phase);
      psum->add_model (new ScalarConstant (sum->get_param(icomp*3)));

      chain->set_constraint (icomp*3, psum);
    }
  }
}
예제 #4
0
void Pulsar::ComponentModel::build () const
{
  if (model)
    return;

  SumRule< Univariate<Scalar> >* sum = new SumRule< Univariate<Scalar> >; 
  model = sum;

  if (fit_derivative)
  {
    derivative.resize (components.size());

    // setup model using derivative components
    for (unsigned icomp=0; icomp < components.size(); icomp++)
    {
      derivative[icomp] = new ScaledVonMisesDeriv;

      derivative[icomp]->set_centre(components[icomp]->get_centre());
      derivative[icomp]->set_concentration
	(components[icomp]->get_concentration());
      derivative[icomp]->set_height(components[icomp]->get_height());
      sum->add_model( derivative[icomp] );
    }
  }
  else
  {
    for (unsigned icomp=0; icomp < components.size(); icomp++)
    {
      sum->add_model( components[icomp] );
      // don't allow the widths to vary
      if (fix_widths)
	components[icomp]->set_infit(1, false);
    }
  }

  if (phase)
  {
    if (verbose)
      cerr << "Pulsar::ComponentModel::build single phase" << endl;

    backup.resize (components.size());

    ChainRule<Univariate<Scalar> >* chain = new ChainRule<Univariate<Scalar> >;
    chain->set_model (sum);

    model = chain;

    for (unsigned icomp=0; icomp < components.size(); icomp++)
    {
#if _DEBUG
      cerr << "BEFORE CLONE fits:";
      unsigned nparam = components[icomp]->get_nparam ();
      for (unsigned ip=0; ip < nparam; ip++)
	cerr << " " << components[icomp]->get_infit(ip);
      cerr << endl;
#endif

      backup[icomp] = components[icomp]->clone();

#if _DEBUG
      cerr << "AFTER CLONE fits:";
      nparam = components[icomp]->get_nparam ();
      for (unsigned ip=0; ip < nparam; ip++)
	cerr << " " << backup[icomp]->get_infit(ip);
      cerr << endl;
#endif

      SumRule<Scalar>* psum = new SumRule<Scalar>;
      psum->add_model (phase);
      psum->add_model (new ScalarConstant (sum->get_param(icomp*3)));

      // verify that iparam=icomp*3 corresponds to component centre
      if (chain->get_param_name(icomp*3) != "centre")
	throw Error (InvalidState, "Pulsar::ComponentModel::build",
		     "iparam=%u name='%s'", icomp*3,
		     sum->get_param_name(icomp*3).c_str());

      chain->set_constraint (icomp*3, psum);
    }
  }
}