MostCommonValue.hpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
44 #ifndef GNSSTK_MOST_COMMON_VALUE_INCLUDE
45 #define GNSSTK_MOST_COMMON_VALUE_INCLUDE
46 
47 #include <math.h>
48 
49 namespace gnsstk
50 {
51  //--------------------------------------------------------------------------------
60  {
61  int N;
62  double tol;
63  std::vector<int> counts;
64  std::vector<double> values;
65 #define DEFAULT_DIM 9
66 #define DEFAULT_TOL 0.00095 // less than a millisecond
67 
68  public:
74 
76  void reset(int i = DEFAULT_DIM)
77  {
78  N = i;
79  counts.clear();
80  values.clear();
81  }
82 
84  inline void add(double dt)
85  {
86  for (int j = 0; j < N; j++)
87  {
88  // first time this value has been seen, and there is room to
89  // consider it
90  if (j >= counts.size())
91  {
92  counts.push_back(1);
93  values.push_back(dt);
94  break;
95  }
96  // match j?
97  if (::fabs(dt - values[j]) < tol)
98  {
99  counts[j]++;
100  break;
101  }
102  // running out of room
103  if (j == N - 1)
104  {
105  // find the least common dt and replace it
106  int jj, kk, nl;
107  for (jj = 1, kk = 0, nl = counts[0]; jj < counts.size(); jj++)
108  {
109  if (counts[jj] <= nl)
110  {
111  kk = jj;
112  nl = counts[jj];
113  }
114  }
115  counts[kk] = 1;
116  values[kk] = dt; // replace it
117  }
118  }
119  }
120 
122  inline double bestDT()
123  {
124  if (counts.size() == 0)
125  {
126  return 0.0;
127  }
128  int i, j(0);
129  for (i = 1; i < counts.size(); i++)
130  if (counts[i] > counts[j])
131  {
132  j = i;
133  }
134  return values[j];
135  }
136 
138  inline int bestN()
139  {
140  if (counts.size() == 0)
141  {
142  return 0;
143  }
144  int i, j(0);
145  for (i = 1; i < counts.size(); i++)
146  if (counts[i] > counts[j])
147  {
148  j = i;
149  }
150  return counts[j];
151  }
152 
154  inline double getTol() { return tol; }
155 
157  inline void setTol(double t) { tol = t; }
158 
160  void getResults(std::vector<int>& out_counts,
161  std::vector<double>& out_values)
162  {
163  out_counts = counts;
164  out_values = values;
165  }
166 
168  void dump(std::ostream& os, int prec = 3)
169  {
170  os << " MostCommonValue::dump(); tolerance is " << std::fixed
171  << std::setprecision(prec) << tol << std::endl;
172  os << " Table of counts and values from class MostCommonValue:\n";
173  int n(counts.size());
174  if (values.size() < n)
175  {
176  n = values.size();
177  }
178 
179  for (int j = 0; j < counts.size(); j++)
180  os << " " << std::setw(3) << counts[j] << " " << std::fixed
181  << std::setprecision(prec) << values[j] << std::endl;
182  }
183 
184 #undef DEFAULT_DIM
185 #undef DEFAULT_TOL
186  }; // end class MostCommonValue
187 } // namespace gnsstk
188 #endif // GNSSTK_MOST_COMMON_VALUE_INCLUDE
gnsstk::MostCommonValue
Definition: MostCommonValue.hpp:59
gnsstk::MostCommonValue::values
std::vector< double > values
value being considered - parallel to counts
Definition: MostCommonValue.hpp:64
gnsstk::MostCommonValue::dump
void dump(std::ostream &os, int prec=3)
dump the table of values and counts
Definition: MostCommonValue.hpp:168
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::MostCommonValue::MostCommonValue
MostCommonValue(int i=DEFAULT_DIM)
Definition: MostCommonValue.hpp:73
nl
int nl
Definition: IERS1996NutationData.hpp:44
gnsstk::MostCommonValue::setTol
void setTol(double t)
set the tolerance used in comparing timesteps
Definition: MostCommonValue.hpp:157
gnsstk::MostCommonValue::getResults
void getResults(std::vector< int > &out_counts, std::vector< double > &out_values)
get the table of all the values and the number of times seen
Definition: MostCommonValue.hpp:160
gnsstk::MostCommonValue::N
int N
number of different values to be considered
Definition: MostCommonValue.hpp:61
gnsstk::MostCommonValue::counts
std::vector< int > counts
number of times this value has been seen
Definition: MostCommonValue.hpp:63
DEFAULT_TOL
#define DEFAULT_TOL
Definition: MostCommonValue.hpp:66
gnsstk::MostCommonValue::bestN
int bestN()
return count for best estimate
Definition: MostCommonValue.hpp:138
gnsstk::MostCommonValue::tol
double tol
tolerance in comparing input to values[]
Definition: MostCommonValue.hpp:62
gnsstk::MostCommonValue::add
void add(double dt)
add a measured timestep to the analysis
Definition: MostCommonValue.hpp:84
gnsstk::MostCommonValue::reset
void reset(int i=DEFAULT_DIM)
reset
Definition: MostCommonValue.hpp:76
gnsstk::MostCommonValue::getTol
double getTol()
access the tolerance used in comparing timesteps
Definition: MostCommonValue.hpp:154
gnsstk::MostCommonValue::bestDT
double bestDT()
return the best estimate of timestep
Definition: MostCommonValue.hpp:122
DEFAULT_DIM
#define DEFAULT_DIM
Definition: MostCommonValue.hpp:65


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:40