-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeanAndCenterOffMass.h
67 lines (49 loc) · 2.53 KB
/
MeanAndCenterOffMass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once
ref class MeanAndCenterOffMass
{
public:
static void Calculate(array<array<float>^> ^p_pattern, unsigned int result_index, unsigned int sdi, int start_index, int length, array<double> ^p_out_mean, array<double> ^p_out_center_off_mass)
{
int pattern_length = p_pattern->Length;
double mean = 0;
double cumulative_weighted_mass = 0;
double cumulative_mass = 0;
unsigned int element_count = 0;
for (int sample = start_index; sample < pattern_length && sample < (start_index + length); sample++) {
mean = mean + p_pattern[sample][sdi];
cumulative_weighted_mass = cumulative_weighted_mass + (sample + 1) * p_pattern[sample][sdi];
cumulative_mass = cumulative_mass + p_pattern[sample][sdi];
element_count++;
}
p_out_center_off_mass[result_index] = (cumulative_weighted_mass / cumulative_mass);
mean = mean / element_count; // Burada element_count kullaniyoruz cunku length ifadesi array boyutundan fazla girilmis olabilir
p_out_mean[result_index] = mean;
}
static void Calculate(array<array<float>^> ^p_pattern, unsigned int result_index, unsigned int sdi, array<double> ^p_out_mean, array<double> ^p_out_center_off_mass)
{
Calculate(p_pattern, result_index, sdi, 0, p_pattern->Length, p_out_mean, p_out_center_off_mass);
}
static void CenteredCalculate(array<array<float>^> ^p_pattern, unsigned int result_index, unsigned int sdi, array<double> ^p_out_mean, array<double> ^p_out_center_off_mass)
{
int pattern_length = p_pattern->Length;
double mean = 0;
double cumulative_weighted_mass = 0;
double cumulative_mass = 0;
for (int sample = 0; (sample < pattern_length && sample < pattern_length / 2); sample++) {
mean = mean + p_pattern[sample][sdi];
mean = mean + p_pattern[pattern_length - sample - 1][sdi];
cumulative_weighted_mass = cumulative_weighted_mass + (sample - pattern_length / 2) * p_pattern[sample][sdi];
cumulative_weighted_mass = cumulative_weighted_mass - (pattern_length / 2 - sample) * p_pattern[pattern_length - sample - 1][sdi];
cumulative_mass = cumulative_mass + p_pattern[sample][sdi];
cumulative_mass = cumulative_mass + p_pattern[pattern_length - sample - 1][sdi];
}
if (pattern_length % 2 != 0) {
unsigned int middle_sample_index = pattern_length / 2; // int division
mean = mean + p_pattern[middle_sample_index][sdi];
cumulative_mass = cumulative_mass + p_pattern[middle_sample_index][sdi];
}
p_out_center_off_mass[result_index] = (cumulative_weighted_mass / cumulative_mass);
mean = mean / pattern_length;
p_out_mean[result_index] = mean;
}
};