Verified Commit b70aaac9 authored by Thomas Almeida's avatar Thomas Almeida
Browse files

Add modifications from running clang-format

parent a7d18a0d
/*
* Copyright (C) 2015 Qi Chu <qi.chu@uwa.edu.au>
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
......@@ -28,33 +28,35 @@
#ifndef __BACKGROUND_STATS_H__
#define __BACKGROUND_STATS_H__
#include <gsl/gsl_vector.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <pipe_macro.h>
#define NSTATS_TO_PROMPT 50 //deprecated. supposed to be used to collect last 50 seconds of background stats.
#define NSTATS_TO_PROMPT \
50 // deprecated. supposed to be used to collect last 50 seconds of
// background stats.
typedef struct {
double cmin;
double cmax;
int nbin;
double step;
double step_2;
void *data; // gsl_vector_long
double cmin;
double cmax;
int nbin;
double step;
double step_2;
void *data; // gsl_vector_long
} Bins1D;
typedef struct {
double cmin_x;
double cmax_x;
int nbin_x;
double step_x;
double step_x_2;
double cmin_y;
double cmax_y;
int nbin_y;
double step_y;
double step_y_2;
void *data; //gsl_matrix or gsl_matrix_long
double cmin_x;
double cmax_x;
int nbin_x;
double step_x;
double step_x_2;
double cmin_y;
double cmax_y;
int nbin_y;
double step_y;
double step_y_2;
void *data; // gsl_matrix or gsl_matrix_long
} Bins2D;
/*
......@@ -62,48 +64,46 @@ typedef struct {
*/
typedef struct {
Bins1D *rank_pdf;
Bins1D *rank_fap;
Bins1D *rank_rate;
Bins2D *rank_map; // map of the lgsnr-lgchisq value to rank value
Bins1D *rank_pdf;
Bins1D *rank_fap;
Bins1D *rank_rate;
Bins2D *rank_map; // map of the lgsnr-lgchisq value to rank value
} RankingStats;
// FIXME: extend to 3D to include null-snr
typedef struct {
Bins1D *lgsnr_rate; // dimension 1 rates, lgsnr
Bins1D *lgchisq_rate; // dimension 2 rates, lgchisq
Bins2D *lgsnr_lgchisq_rate; // histogram of the (lgsnr,lgchisq) from background
Bins2D *lgsnr_lgchisq_pdf;
Bins1D *lgsnr_rate; // dimension 1 rates, lgsnr
Bins1D *lgchisq_rate; // dimension 2 rates, lgchisq
Bins2D
*lgsnr_lgchisq_rate; // histogram of the (lgsnr,lgchisq) from background
Bins2D *lgsnr_lgchisq_pdf;
} FeatureStats;
/*
* background or foreground (zerolag) statistics
*/
typedef struct {
char *ifos;
RankingStats *rank;
FeatureStats *feature;
int hist_trials;
long nevent;
long livetime;
char *ifos;
RankingStats *rank;
FeatureStats *feature;
int hist_trials;
long nevent;
long livetime;
} TriggerStats;
typedef struct {
TriggerStats ** multistats;
GString *rank_xmlname;
GString *feature_xmlname;
TriggerStats **multistats;
GString *rank_xmlname;
GString *feature_xmlname;
int ncombo;
} TriggerStatsXML;
typedef TriggerStats** TriggerStatsPointer;
typedef TriggerStats **TriggerStatsPointer;
typedef struct {
TriggerStatsPointer *plist;
int size;
int pos;
} TriggerStatsPointerList;
TriggerStatsPointer *plist;
int size;
int pos;
} TriggerStatsPointerList;
#endif /* __BACKGROUND_STATS_H__ */
/*
* Copyright (C) 2015 Qi Chu <qi.chu@uwa.edu.au>
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
......@@ -28,53 +28,56 @@
#ifndef __BACKGROUND_STATS_UTILS_H__
#define __BACKGROUND_STATS_UTILS_H__
#include <glib.h>
#include <cohfar/background_stats.h>
#include <LIGOLwHeader.h>
#include <cohfar/background_stats.h>
#include <glib.h>
Bins1D *
bins1D_create_long(double cmin, double cmax, int nbin);
Bins1D *bins1D_create_long(double cmin, double cmax, int nbin);
Bins2D *
bins2D_create(double cmin_x, double cmax_x, int nbin_x, double cmin_y, double cmax_y, int nbin_y);
Bins2D *bins2D_create(double cmin_x,
double cmax_x,
int nbin_x,
double cmin_y,
double cmax_y,
int nbin_y);
Bins2D *
bins2D_create_long(double cmin_x, double cmax_x, int nbin_x, double cmin_y, double cmax_y, int nbin_y);
Bins2D *bins2D_create_long(double cmin_x,
double cmax_x,
int nbin_x,
double cmin_y,
double cmax_y,
int nbin_y);
TriggerStats **
trigger_stats_create(int ncombo);
TriggerStats **trigger_stats_create(int ncombo);
int
bins1D_get_idx(double val, Bins1D *bins);
int bins1D_get_idx(double val, Bins1D *bins);
void
trigger_stats_feature_rates_update(double snr, double chisq, FeatureStats *feature, TriggerStats *cur_stats);
void
trigger_stats_feature_rates_add(FeatureStats *feature1, FeatureStats *feature2, TriggerStats *cur_stats);
void trigger_stats_feature_rates_update(double snr,
double chisq,
FeatureStats *feature,
TriggerStats *cur_stats);
void
trigger_stats_feature_rates_to_pdf(FeatureStats *feature);
void trigger_stats_feature_rates_add(FeatureStats *feature1,
FeatureStats *feature2,
TriggerStats *cur_stats);
void trigger_stats_feature_rates_to_pdf(FeatureStats *feature);
double
bins2D_get_val(double snr, double chisq, Bins2D *bins);
double bins2D_get_val(double snr, double chisq, Bins2D *bins);
gboolean
trigger_stats_xml_from_xml(TriggerStatsXML *stats, int *hist_trials, const char *filename);
gboolean trigger_stats_xml_from_xml(TriggerStatsXML *stats,
int *hist_trials,
const char *filename);
gboolean
trigger_stats_xml_dump(TriggerStatsXML *stats, int hist_trials, const char *filename, int write_status, xmlTextWriterPtr *pwriter);
gboolean trigger_stats_xml_dump(TriggerStatsXML *stats,
int hist_trials,
const char *filename,
int write_status,
xmlTextWriterPtr *pwriter);
TriggerStatsXML *
trigger_stats_xml_create(char *ifos, int stats_type);
TriggerStatsXML *trigger_stats_xml_create(char *ifos, int stats_type);
void
trigger_stats_xml_destroy(TriggerStatsXML * stats);
void trigger_stats_xml_destroy(TriggerStatsXML *stats);
float
gen_fap_from_feature(double snr, double chisq, TriggerStats *stats);
float gen_fap_from_feature(double snr, double chisq, TriggerStats *stats);
#endif /* __BACKGROUND_STATS_UTILS_H__ */
/*
* Copyright (C) 2015 Qi Chu <qi.chu@uwa.edu.au>
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
......@@ -25,68 +25,62 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __COHFAR_ACCUMBACKGROUND_H__
#define __COHFAR_ACCUMBACKGROUND_H__
#include <cohfar/background_stats.h>
#include <glib.h>
#include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
#include <gst/gst.h>
#include <postcohtable.h>
#include <cohfar/background_stats.h>
G_BEGIN_DECLS
#define COHFAR_ACCUMBACKGROUND_TYPE \
(cohfar_accumbackground_get_type())
#define COHFAR_ACCUMBACKGROUND(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), COHFAR_ACCUMBACKGROUND_TYPE, CohfarAccumbackground))
#define COHFAR_ACCUMBACKGROUND_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), COHFAR_ACCUMBACKGROUND_TYPE, CohfarAccumbackgroundClass))
#define GST_IS_COHFAR_ACCUMBACKGROUND(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), COHFAR_ACCUMBACKGROUND_TYPE))
#define GST_IS_COHFAR_ACCUMBACKGROUND_CLASS(klass) \
(G_type_CHECK_CLASS_TYPE((klass), COHFAR_ACCUMBACKGROUND_TYPE))
#define COHFAR_ACCUMBACKGROUND_TYPE (cohfar_accumbackground_get_type())
#define COHFAR_ACCUMBACKGROUND(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), COHFAR_ACCUMBACKGROUND_TYPE, \
CohfarAccumbackground))
#define COHFAR_ACCUMBACKGROUND_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), COHFAR_ACCUMBACKGROUND_TYPE, \
CohfarAccumbackgroundClass))
#define GST_IS_COHFAR_ACCUMBACKGROUND(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), COHFAR_ACCUMBACKGROUND_TYPE))
#define GST_IS_COHFAR_ACCUMBACKGROUND_CLASS(klass) \
(G_type_CHECK_CLASS_TYPE((klass), COHFAR_ACCUMBACKGROUND_TYPE))
typedef struct {
GstElementClass parent_class;
GstElementClass parent_class;
} CohfarAccumbackgroundClass;
typedef struct {
GstElement element;
GstPad *sinkpad, *srcpad;
char *ifos;
int nifo;
int ncombo; // ifo combination
int write_ifo_mapping[MAX_NIFO];
TriggerStatsXML *bgstats;
TriggerStatsXML *zlstats;
TriggerStatsXML *sgstats;
int source_type; // BNS, NSBH, or BBH
GstElement element;
GstPad *sinkpad, *srcpad;
char *ifos;
int nifo;
int ncombo; // ifo combination
int write_ifo_mapping[MAX_NIFO];
TriggerStatsXML *bgstats;
TriggerStatsXML *zlstats;
TriggerStatsXML *sgstats;
int source_type; // BNS, NSBH, or BBH
xmlTextWriterPtr stats_writer;
int snapshot_interval;
int hist_trials;
gchar *history_fname;
gchar *output_prefix;
gchar *output_name;
/*
* timestamp book-keeping
*/
GstClockTime t_end;
GstClockTime t_roll_start;
int snapshot_interval;
int hist_trials;
gchar *history_fname;
gchar *output_prefix;
gchar *output_name;
/*
* timestamp book-keeping
*/
GstClockTime t_end;
GstClockTime t_roll_start;
} CohfarAccumbackground;
GType cohfar_accumbackground_get_type(void);
G_END_DECLS
#endif /* __COHFAR_ACCUMBACKGROUND_H__ */
#endif /* __COHFAR_ACCUMBACKGROUND_H__ */
/*
* Copyright (C) 2015 Qi Chu <qi.chu@uwa.edu.au>
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
......@@ -25,64 +25,57 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __COHFAR_ASSIGNFAR_H__
#define __COHFAR_ASSIGNFAR_H__
#include <cohfar/background_stats.h>
#include <glib.h>
#include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
#include <cohfar/background_stats.h>
#include <gst/gst.h>
G_BEGIN_DECLS
#define COHFAR_ASSIGNFAR_TYPE \
(cohfar_assignfar_get_type())
#define COHFAR_ASSIGNFAR(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), COHFAR_ASSIGNFAR_TYPE, CohfarAssignfar))
#define COHFAR_ASSIGNFAR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), COHFAR_ASSIGNFAR_TYPE, CohfarAssignfarClass))
#define GST_IS_COHFAR_ASSIGNFAR(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), COHFAR_ASSIGNFAR_TYPE))
#define GST_IS_COHFAR_ASSIGNFAR_CLASS(klass) \
(G_type_CHECK_CLASS_TYPE((klass), COHFAR_ASSIGNFAR_TYPE))
#define COHFAR_ASSIGNFAR_TYPE (cohfar_assignfar_get_type())
#define COHFAR_ASSIGNFAR(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), COHFAR_ASSIGNFAR_TYPE, CohfarAssignfar))
#define COHFAR_ASSIGNFAR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), COHFAR_ASSIGNFAR_TYPE, \
CohfarAssignfarClass))
#define GST_IS_COHFAR_ASSIGNFAR(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), COHFAR_ASSIGNFAR_TYPE))
#define GST_IS_COHFAR_ASSIGNFAR_CLASS(klass) \
(G_type_CHECK_CLASS_TYPE((klass), COHFAR_ASSIGNFAR_TYPE))
typedef struct {
GstBaseTransformClass parent_class;
GstBaseTransformClass parent_class;
} CohfarAssignfarClass;
typedef struct {
GstBaseTransform element;
char *ifos;
int nifo;
int ncombo; // ifo combination
int hist_trials;
TriggerStatsXML *bgstats_2h;
TriggerStatsXML *bgstats_1d;
TriggerStatsXML *bgstats_1w;
int silent_time;
gboolean pass_silent_time;
int refresh_interval;
gchar **input_fnames;
int ninput;
/*
* timestamp book-keeping
*/
GstClockTime t_start;
GstClockTime t_roll_start;
GstBaseTransform element;
char *ifos;
int nifo;
int ncombo; // ifo combination
int hist_trials;
TriggerStatsXML *bgstats_2h;
TriggerStatsXML *bgstats_1d;
TriggerStatsXML *bgstats_1w;
int silent_time;
gboolean pass_silent_time;
int refresh_interval;
gchar **input_fnames;
int ninput;
/*
* timestamp book-keeping
*/
GstClockTime t_start;
GstClockTime t_roll_start;
} CohfarAssignfar;
GType cohfar_assignfar_get_type(void);
G_END_DECLS
#endif /* __COHFAR_ASSIGNFAR_H__ */
#endif /* __COHFAR_ASSIGNFAR_H__ */
/*
* Copyright (C) 2017 Teresa, Xingjiang Zhu, Qi Chu <qi.chu@ligo.org>
*
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
......@@ -25,188 +25,195 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <math.h>
#include <cohfar/knn_kde.h>
#include <cohfar/ssvkernel.h>
#include <math.h>
static int get_num_nonzero(gsl_matrix_long *histogram)
{
int i = 0,j = 0,num_nonzero = 0;
int x_nbin = histogram->size1, y_nbin = histogram->size1;
for(i=0;i<x_nbin;i++) {
for(j=0;j<y_nbin;j++) {
if (gsl_matrix_long_get(histogram, i, j) > 0)
{
num_nonzero++;
}
}
}
return num_nonzero;
}
static int get_num_nonzero(gsl_matrix_long *histogram) {
static void find_nonzero_idx(gsl_matrix_long *histogram, gsl_matrix_long * nonzero_idx)
{
// This loop should generate an array that looks something like this
// 0 1
// 0 3
// ...
// 1 0
// 1 2
// ...
// ...
int i = 0,j = 0;
int x_nbin = histogram->size1, y_nbin = histogram->size1;
int inonzero = 0;
for(i=0;i<x_nbin;i++) {
for(j=0;j<y_nbin;j++) {
if (gsl_matrix_long_get(histogram, i, j) > 0)
{
gsl_matrix_long_set(nonzero_idx, inonzero, 0, i);
gsl_matrix_long_set(nonzero_idx, inonzero, 1, j);
inonzero++;
}
}
}
int i = 0, j = 0, num_nonzero = 0;
int x_nbin = histogram->size1, y_nbin = histogram->size1;
for (i = 0; i < x_nbin; i++) {
for (j = 0; j < y_nbin; j++) {
if (gsl_matrix_long_get(histogram, i, j) > 0) { num_nonzero++; }
}
}
return num_nonzero;
}
static double get_kth_value_gsl(double *all_dist, int len, int knn_k)
{
double *small = (double*) malloc(sizeof(double)*knn_k);
gsl_sort_smallest(small, knn_k, all_dist, 1, len);
double kth_value = small[knn_k-1];
free(small);
return kth_value;
static void find_nonzero_idx(gsl_matrix_long *histogram,
gsl_matrix_long *nonzero_idx) {
// This loop should generate an array that looks something like this
// 0 1
// 0 3
// ...
// 1 0
// 1 2
// ...
// ...
int i = 0, j = 0;
int x_nbin = histogram->size1, y_nbin = histogram->size1;
int inonzero = 0;
for (i = 0; i < x_nbin; i++) {
for (j = 0; j < y_nbin; j++) {
if (gsl_matrix_long_get(histogram, i, j) > 0) {
gsl_matrix_long_set(nonzero_idx, inonzero, 0, i);
gsl_matrix_long_set(nonzero_idx, inonzero, 1, j);
inonzero++;
}
}
}
}
static double get_kth_value_gsl(double *all_dist, int len, int knn_k) {
double *small = (double *)malloc(sizeof(double) * knn_k);
gsl_sort_smallest(small, knn_k, all_dist, 1, len);
double kth_value = small[knn_k - 1];
free(small);
return kth_value;
}
/* deprecated: takes too long */
static double get_kth_value(double * all_dist, int len, int knn_k)// Puts the distances from reference point to all data points into ascending order
static double
get_kth_value(double *all_dist,
int len,
int knn_k) // Puts the distances from reference point to all
// data points into ascending order
{
int i=0;
int j=0;
for (i=0; i<len; i++)
{
for (j=0; j<len; j++)
{
if (all_dist[i] < all_dist[j])
{
double t = all_dist[i];
all_dist[i] = all_dist[j];
all_dist[j] = t;
}
}
}
double kthVal = all_dist[knn_k-1];
return kthVal;
int i = 0;
int j = 0;
for (i = 0; i < len; i++) {
for (j = 0; j < len; j++) {