Skip to content

Commit a77b6ac

Browse files
committed
[BugFixes] Fix bugs in sampen2d.
1 parent 8c194c0 commit a77b6ac

File tree

3 files changed

+14
-54
lines changed

3 files changed

+14
-54
lines changed

Readme.md

+4-43
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# fast_sampen: Fast Computation of Sample Entropy
22

3-
This repository includes a library and a program for fast computation of Sample Entropy, based on kd tree and randomly
4-
sample (Monte Carlo and quasi-Monte Carlo) method.
3+
This repository includes a library and a program for fast computation of Sample Entropy, based on kd tree, Range-kd tree and randomly sample (Monte Carlo and quasi-Monte Carlo) method.
54

65
## Requirements
76

87
- Linux, macOS or other UNIX-like OS
98
- C++ compiler supporting C++11
109
- CMake (version >= 3.5)
10+
- GSL (for quasi-random number generation)
11+
- Magick++7 (for image manipulation such as io and resize)
1112

1213
## Compile
1314

@@ -71,44 +72,4 @@ The built binary will be located in `bin` directory in the building directory.
7172

7273
## Usage
7374

74-
```
75-
Usage: build/fast_sampen --input <INPUT> --input-type {simple, multirecord}\
76-
-r <THRESHOLD> -m <TEMPLATE_LENGTH>\
77-
-n <N> [-output-level {1,2,3}]\
78-
--sample-size <SAMPLE_SIZE> --sample-num <SAMPLE_NUM>
79-
80-
Options and arguments:
81-
--input <INPUT> The file name of the input file.
82-
--input-format <FORMAT> The format of the input file. Should be either simple
83-
or multirecord. If set to simple, then each line of the
84-
input file contains exactly one column; if set to
85-
multirecord, then each line contains <NUM_RECORD> + 1
86-
columns, of which the first indicates the line number
87-
and the remaining columns are instances of the records.
88-
The default value is simple.
89-
--input-type <TYPE> The data type of the input data, either int or float.
90-
Default: double.
91-
-r <R> The threshold argument in sample entropy.
92-
-m <M> The template length argument of sample entropy. Note
93-
that this program only supports 2 <= m <= 10.
94-
-n <N> If the length of the signal specified by <FILENAME> is
95-
greater than <N>, then it would be truncated to be of
96-
length <N>. If <N> is 0, then the the original length
97-
is employed. The default value is 0.
98-
--sample-size <N0> The number of points to sample.
99-
--sample-num <N1> The number of computations where the average is taken.
100-
--random If this option is enabled, the random seed will be set
101-
randomly.
102-
-q If this option is enabled, the quasi-Monte Carlo based
103-
method is conducted.
104-
--variance If this option is enabled, then the variance of the
105-
results of sampling methods will be computed.
106-
--quasi-type <TYPE> The type of the quasi-random sequence for sampling,
107-
can be one of the following: sobol, halton,
108-
reversehalton, niederreiter_2 or grid. Default: sobol.
109-
-u If this option is enabled, the Monte Carlo based
110-
using uniform distribution is conducted.
111-
--output-level <LEVEL> The amount of information printed. Should be one of
112-
{0,1,2}. Level 0 is most silent while level 2 is for
113-
debugging.
114-
```
75+
Run programs with `--help` for usage.

include/sample_entropy_calculator2d.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SampleEntropyCalculator2D {
3030
_dilation_factor(dilation_factor),
3131
_window_size(_dilation_factor * K + 1),
3232
_num_steps_x((_width - _window_size + 1) / _moving_step_size),
33-
_num_steps_y((_width - _window_size + 1) / _moving_step_size),
33+
_num_steps_y((_height - _window_size + 1) / _moving_step_size),
3434
_num_templates(_num_steps_x * _num_steps_y),
3535
_output_level(output_level) {
3636
if (K == 0) {

src/sampen2d.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,19 @@ int main(int argc, char *argv[]) {
212212
data[i] = static_cast<int>(pixels[i * num_channels]);
213213
}
214214
auto var = sampen::ComputeVariance(data);
215-
std::cout << "\n\tstandard deviation: " << sqrt(var) << std::endl;
216215
arg.r = sqrt(var) * arg.r;
217216

217+
sampen::SampleEntropyCalculator2DDirect<int> sec2dd(
218+
data.begin(), data.end(), arg.m, arg.r, arg.width, arg.height,
219+
arg.moving_step_size, arg.dilation_factor, arg.output_level);
220+
sec2dd.ComputeSampleEntropy();
221+
std::cout << sec2dd.get_result_str();
222+
223+
double sampen2d = sec2dd.get_entropy();
224+
double a_norm = sec2dd.get_a_norm();
225+
double b_norm = sec2dd.get_b_norm();
218226

219227
if (arg.sampling1) {
220-
sampen::SampleEntropyCalculator2DDirect<int> sec2dd(
221-
data.begin(), data.end(), arg.m, arg.r, arg.width, arg.height,
222-
arg.moving_step_size, arg.dilation_factor, arg.output_level);
223-
sec2dd.ComputeSampleEntropy();
224-
std::cout << sec2dd.get_result_str();
225-
226-
double sampen2d = sec2dd.get_entropy();
227-
double a_norm = sec2dd.get_a_norm();
228-
double b_norm = sec2dd.get_b_norm();
229228
sampen::SampleEntropyCalculator2DSamplingDirect<int> sec2dds(
230229
data.cbegin(), data.cend(), arg.m, arg.r, arg.width, arg.height,
231230
arg.moving_step_size, arg.dilation_factor, arg.sample_size,

0 commit comments

Comments
 (0)