예제 #1
0
// Test correlation coefficient for template iterators
void test_correlation_coefficient_iterator() {

  // Substitution with double array
  double a[5] = {1.0, 2.0, 3.0, 4.0, 5.0};
  double r1 = correlation_coefficient(std::begin(a), std::end(a),
                                      std::begin(a), std::end(a), 0);
  if (!equalWithEpsilon(r1, 1.0))
    throw failed;

  // Substitution with float array
  float b[5] = {1.0, 2.0, 3.0, 4.0, 5.0};
  float r2 = correlation_coefficient(std::begin(b), std::end(b),
                                     std::begin(b), std::end(b), 0);
  if (!equalWithEpsilon(r2, 1.0))
    throw failed;

  // Substitution with double vector
  std::vector<double> v1;
  v1.push_back(1.0);
  v1.push_back(2.0);
  v1.push_back(3.0);
  v1.push_back(4.0);
  v1.push_back(5.0);
  double r3 = correlation_coefficient(v1.begin(), v1.end(),
                                      v1.begin(), v1.end(), 0);
  if (!equalWithEpsilon(r3, 1.0))
    throw failed;
}
예제 #2
0
// Tests correlation coefficient for doubles
void test_correlation_coefficient_double() {
  int n = 5;
  double a[5] = {1.0, 2.0, 3.0, 4.0, 5.0};
  double r = correlation_coefficient(a, a, n);
  if (!equalWithEpsilon(r, 1.0))
    throw failed;
}
예제 #3
0
파일: fraud.hpp 프로젝트: hmm34/fraud
triple<I, I, Value_type<I>>
strongest_correlation(I firstA, I lastA, I firstB, I lastB,
                    Value_type<I> minR, N minLength, T id) {
  typedef Value_type<I> R;
  N maxLength = minLength;
  R maxR = minR;
  I startIter = lastA;
  I endIter = lastA;

  N len = N(id);
  I tempFirstA = firstA;
  while (tempFirstA != lastA) {
    ++tempFirstA;
    ++len;
  }

  I tempFirstB = firstB;
  tempFirstA = firstA;

  for (N count1 = N(0); count1 <= len - minLength; ++count1) {
    for (N count2 = count1 + minLength; count2 <= len; ++count2) {
      // Increase ending iterators to their appropriate location
      I tempLastB = tempFirstB;
      I tempLastA = tempFirstA;
      N dist = count2 - count1;
      for (N count3 = 0; count3 < dist; ++count3){
        ++tempLastA;
        ++tempLastB;
      }

      // Determine correlation coefficient
      I temp1A = tempFirstA;
      I temp2A = tempLastA;
      I temp1B = tempFirstB;
      I temp2B = tempLastB;
      R r = correlation_coefficient(temp1A, temp2A, temp1B, temp2B, id);

      if ((std::abs(r) > std::abs(maxR)) ||
          (std::abs(r) >= std::abs(maxR) && (dist >= maxLength)))
      {
        startIter = tempFirstA;
        endIter   = tempLastA;
        maxR      = r;
        maxLength = dist;
      }
    }

    // Increase beginning iterators
    ++tempFirstA;
    ++tempFirstB;
  }
  return triple<I, I, R>(startIter, endIter, maxR);
}
예제 #4
0
파일: fraud.hpp 프로젝트: hmm34/fraud
// Calculate the location of the both longest subsequence in an ordered list of
// numbers that has the strongest correlation coefficient, meeting the 
// threshhold minumum sub-sequence length and minumum correlation coefficient
// across the sub-sequence.
triple<int, int, double>
strongest_correlation(double a[], double b[], int n,
                      double minR, int minLength) {
  int startIndex = -1;
  int lastIndex = -1;
  double maxR = minR;
  for (int i = 0; i < n - minLength; ++i) {          // O(n - minLength)
    for (int j = i + minLength; j < n; ++j) {        // O(n - minLength)
      double r = correlation_coefficient(a, b, j-i); // O(5n)
      if ((std::abs(r) > std::abs(maxR)) || 
          (std::abs(r) >= std::abs(maxR) && (j - i) > (lastIndex - startIndex)))
      {
        startIndex = i;
        lastIndex = j;
        maxR = r;
      }
    }
  }
  return triple<int, int, double>(startIndex, lastIndex, maxR);
}
예제 #5
0
파일: main.cpp 프로젝트: ywis/PHY1610
int main() {
    int Num_of_detections 32;
    
    // Read the prediction signal and times
    file_detection prediction = readingfile("data/GWprediction.rat");
    signal = prediction.signal;
    times  = prediction.times;

    str::string dir = 'data/';
    // Do the Fourier transform of the signal calculating the power spectrum of the prediction
    rarray <std::complex<double>,1> signal_hat = fft_fast(signal01);
    rarray <double,1> ps = power_spectrum(rarray <std::complex<double>,1> signal_hat01);

    // Read the prediction file sequently
    //for (i=01; i <= Num_of_detections; i++) {
        // read one of the GW signal from observations
    int i=1;
    fname = "detection"+"01"+".rat";
    file_detection detection01 = readingfile("data/detection01.rat");
    signal01 = detection01.signal;
    times01 = detection01.times;
        
        rarray <std::complex<double>,1> signal_hat01 = fft_fast(signal01);

        rarray <double,1> ps01 = power_spectrum(rarray <std::complex<double>,1> signal_hat01);

        double co_ef_01=correlation_coefficient(ps01, ps);
        
        vector <double> co_ef(Num_of_detections);
        co_ef[0] = co_ef;
    
    std::sort(co_ef.begin(), co_ef.end());
    std::cout<<co_ef[0]<<co_ef[-1]<<std::endl;
    
    //}

    return 0;

}