예제 #1
0
void MEAL::ComplexRVM::init ()
{
  if (verbose)
    cerr << "MEAL::ComplexRVM::init" << endl;

  rvm = new RotatingVectorModel;

  ScalarMath N = *(rvm->get_north());
  ScalarMath E = *(rvm->get_east ());

  ScalarMath Q = N*N - E*E;
  ScalarMath U = 2.0 * N * E;

  ChainRule<Complex>* phase = new ChainRule<Complex>;

  // Set up a complex phase function with phase equal to RVM P.A.
  phase->set_model( new ComplexCartesian );
  phase->set_constraint( 0, Q.get_expression() );
  phase->set_constraint( 1, U.get_expression() );

  gain = new VectorRule<Complex>;

  // gain->set_verbose (true);

  add_model (gain);
  add_model (phase);
}
예제 #2
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);
    }
  }
}
예제 #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] );
      // 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);
    }
  }
}