Beispiel #1
0
//------------------------------------------------------------------------------
// copy constructor
//------------------------------------------------------------------------------
CCSDSEMSegment::CCSDSEMSegment(const CCSDSEMSegment &copy) :
   segmentNumber       (copy.segmentNumber),
   dataSize            (copy.dataSize),
   dataType            (copy.dataType),
   timeSystem          (copy.timeSystem),
   startTime           (copy.startTime),
   stopTime            (copy.stopTime),
   usableStartTime     (copy.usableStartTime),
   usableStopTime      (copy.usableStopTime),
   interpolationMethod (copy.interpolationMethod),
   interpolationDegree (copy.interpolationDegree),
   objectName          (copy.objectName),
   objectID            (copy.objectID),
   centerName          (copy.centerName),
   usesUsableTimes     (copy.usesUsableTimes),
   checkLagrangeOrder  (copy.checkLagrangeOrder),
   firstUsable         (copy.firstUsable),
   lastUsable          (copy.lastUsable)
{
   EpochAndData *ed;
   for (Integer jj = 0; jj < (Integer) copy.dataStore.size(); jj++)
   {
      ed = new EpochAndData();
      ed->epoch = (copy.dataStore.at(jj))->epoch;
      Rvector itsData = (copy.dataStore.at(jj))->data;
      ed->data  = Rvector(itsData);
      dataStore.push_back(ed);
   }

   dataComments = copy.dataComments;
   metaComments = copy.metaComments;
}
Beispiel #2
0
// Reset the Kalman Filter for a CARMA(p,q) process
void KalmanFilterp::Reset() {
    
    // Initialize the matrix of Eigenvectors. We will work with the state vector
	// in the space spanned by the Eigenvectors because in this space the state
	// transition matrix is diagonal, so the calculation of the matrix exponential
	// is fast.
    arma::cx_mat EigenMat(p_,p_);
	EigenMat.row(0) = arma::ones<arma::cx_rowvec>(p_);
	EigenMat.row(1) = omega_.st();
	for (int i=2; i<p_; i++) {
		EigenMat.row(i) = strans(arma::pow(omega_, i));
	}
    
	// Input vector under original state space representation
	arma::cx_vec Rvector = arma::zeros<arma::cx_vec>(p_);
	Rvector(p_-1) = 1.0;
    
	// Transform the input vector to the rotated state space representation.
	// The notation R and J comes from Belcher et al. (1994).
	arma::cx_vec Jvector(p_);
	Jvector = arma::solve(EigenMat, Rvector);
	
	// Transform the moving average coefficients to the space spanned by EigenMat.

    rotated_ma_coefs_ = ma_coefs_ * EigenMat;
	
	// Calculate the stationary covariance matrix of the state vector.
	for (int i=0; i<p_; i++) {
		for (int j=i; j<p_; j++) {
			// Only fill in upper triangle of StateVar because of symmetry
			StateVar_(i,j) = -sigsqr_ * Jvector(i) * std::conj(Jvector(j)) /
            (omega_(i) + std::conj(omega_(j)));
		}
	}
	StateVar_ = arma::symmatu(StateVar_); // StateVar is symmetric
	PredictionVar_ = StateVar_; // One-step state prediction error
	
	state_vector_.zeros(); // Initial state is set to zero
	
	// Initialize the Kalman mean and variance. These are the forecasted value
	// for the measured time series values and its variance, conditional on the
	// previous measurements
	mean(0) = 0.0;
    var(0) = std::real( arma::as_scalar(rotated_ma_coefs_ * StateVar_ * rotated_ma_coefs_.t()) );
    var(0) += yerr_(0) * yerr_(0); // Add in measurement error contribution

	innovation_ = y_(0); // The innovation
    current_index_ = 1;
}
Beispiel #3
0
//------------------------------------------------------------------------------
// operator=
//------------------------------------------------------------------------------
CCSDSEMSegment& CCSDSEMSegment::operator=(const CCSDSEMSegment &copy)
{
   if (&copy == this)
      return *this;

   segmentNumber       = copy.segmentNumber;
   dataSize            = copy.dataSize;
   dataType            = copy.dataType;
   timeSystem          = copy.timeSystem;
   startTime           = copy.startTime;
   stopTime            = copy.stopTime;
   usableStartTime     = copy.usableStartTime;
   usableStopTime      = copy.usableStopTime;
   interpolationMethod = copy.interpolationMethod;
   interpolationDegree = copy.interpolationDegree;
   objectName          = copy.objectName;
   objectID            = copy.objectID;
   centerName          = copy.centerName;
   usesUsableTimes     = copy.usesUsableTimes;
   checkLagrangeOrder  = copy.checkLagrangeOrder;
   firstUsable         = copy.firstUsable;
   lastUsable          = copy.lastUsable;

   for (Integer ii = 0; ii < (Integer) dataStore.size(); ii++)
   {
      delete dataStore.at(ii);
   }
   dataStore.clear();
   dataComments.clear();
   metaComments.clear();

   EpochAndData *ed;
   for (Integer jj = 0; jj < (Integer) copy.dataStore.size(); jj++)
   {
      ed = new EpochAndData();
      ed->epoch = (copy.dataStore.at(jj))->epoch;
      ed->data  = Rvector((copy.dataStore.at(jj))->data);
      dataStore.push_back(ed);
   }

   dataComments = copy.dataComments;
   metaComments = copy.metaComments;

   return *this;
}
Beispiel #4
0
void Normalize(Real **vf, const Real *b,int sides)
/* Normalize a symmetric matrix F (vf) by solving a diagonal 
   matrix D (diag) so that the row sums in matrix DFD coincides 
   with those given in vector b. The Newton method 
   is used to solve the diagonal matrix D. 
*/
{
  /* Criteria for ending the iteration */
  int itmax = 10;
  Real eps = 1e-20;
  Real **jac,*rest,*diag,sum;
  int i,j,k,it;
  int *indx;

  printf("Normalization of matrices is currently not supported\n");
  printf("If you want to reactivate it, rewrite the LU decomposition\n");
  return;

  jac = Rmatrix(1,sides,1,sides);
  rest = Rvector(1,sides);
  diag = Rvector(1,sides);
  indx = Ivector(1,sides);

  for (i=1;i<=sides;i++) diag[i] = 1.;


  for(it=1;it<=itmax;it++) {

    /* Calculate the residual sum(DAD)-b. */
    for (i=1; i<=sides; i++) {
      sum = 0.;
      for (j=1; j<=sides; j++) 
        sum += diag[j] * vf[i][j];
      sum *= diag[i];
      rest[i] = sum - b[i];
    }
    sum = 0.;
    for (i=1; i<=sides; i++) 
      sum += rest[i]*rest[i]/b[i];
    sum /= sides;
    
    if(sum < eps) break;

    /* Make the Jacobian matrix. */
    for (i=1; i<=sides; i++) {
      jac[i][i] = 0.;
      for(j=1; j<=sides; j++)
	jac[i][j] = diag[i]*vf[i][j];
      for(k=1; k<=sides;k++)
        jac[i][i] += diag[k]*vf[i][k];
    }

    /* Solve the equation jac * x = rest using Numerical Recipes routines. */     
    /* These have been removed due to copyright violiation */

    /* New approximation. */
    for (i=1; i<=sides; i++)
      diag[i] -= rest[i];    
  } 

  /* Normalize the viewfactors. */
  for (i=1; i<=sides; i++)
    for (j=1; j<=sides; j++)
      vf[i][j] *= diag[i] * diag[j];

  free_Rmatrix(jac,1,sides,1,sides);
  free_Rvector(rest,1,sides);
  free_Rvector(diag,1,sides);
  free_Ivector(indx,1,sides);
}