Skip to content

Commit f4fad73

Browse files
author
CVH95
committed
modified pattern
1 parent cf67cb3 commit f4fad73

12 files changed

+1319
-1
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,11 @@ target_link_libraries(test_psn transfer_function neuron so2_cpg psn)
4646
add_executable(test_vrn tests/test_vrn.cpp)
4747
target_link_libraries(test_vrn transfer_function neuron so2_cpg psn vrn)
4848

49+
add_executable(test_sine_rectification tests/test_sine_rectification.cpp)
50+
target_link_libraries(test_sine_rectification transfer_function)
51+
52+
add_executable(test_so2_rectification tests/test_so2_rectification.cpp)
53+
target_link_libraries(test_so2_rectification transfer_function neuron so2_cpg)
54+
4955
# Output end message
5056
MESSAGE(${PROJECT_NAME} " done!")

SO2/include/so2_cpg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class so2{
4242
vector<float> timeSpace(float t0, float tf, int sample);
4343
tuple<float, float, float> intraLegCoordination(float ti, vector<float> weights, vector<float> biases, float hz, float o1, float o2);
4444
vector<float> get_output();
45+
float threshold_so2_signal(float oi, float oi_prev);
4546
void udpate_output(float x, float y);
4647

4748
private:

SO2/src/so2_cpg.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,33 @@ vector<float> so2::get_output()
7272
return output;
7373
}
7474

75+
// Threshold SO2 signal (dung beetle)
76+
float so2::threshold_so2_signal(float oi, float oi_prev)
77+
{
78+
float _oi;
79+
// First threshold, on y(x)
80+
if(oi >= 0.0)
81+
{
82+
// Approximating derivative
83+
float diff = oi - oi_prev;
84+
// Second threshold, on y'(x)
85+
if(diff >= 0.0)
86+
{
87+
_oi = oi;
88+
}
89+
else
90+
{
91+
_oi = 0;
92+
}
93+
}
94+
else
95+
{
96+
_oi = 0;
97+
}
98+
99+
return _oi;
100+
}
101+
75102
// Update output value (positional)
76103
void so2::udpate_output(float x, float y)
77104
{

TransferFunction/include/transfer_function.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,20 @@ class transfer_function{
2525
public:
2626

2727
// Functions
28+
float cosine(float amp, float f, float x);
2829
float gaussian(float x, float std);
2930
float linear(float x);
3031
float linear_biased(float x, float m, float n);
3132
float sigmoid(float x);
33+
float sine(float amp, float f, float rad);
3234
float step_threshold(float x, float threshold);
3335
float tanh(float x);
34-
36+
tuple<float, float> thresholded_sine(float amp, float f, float rad, float z_prev);
37+
38+
private:
39+
40+
// For approximating the derivative
41+
float resolution = 0.001;
3542
};
3643

3744
#endif /* TRANSFER_FUNCTION_H_ */

TransferFunction/src/transfer_function.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#include <transfer_function.h>
22

3+
// Cosine function (x must be in radians)
4+
float transfer_function::cosine(float amp, float f, float rad)
5+
{
6+
float w = 2*PI*f;
7+
float y = amp*cos(w*rad);
8+
return y;
9+
}
310

411
// Gaussian transfer function
512
float transfer_function::gaussian(float x, float std)
@@ -31,6 +38,14 @@ float transfer_function::sigmoid(float x)
3138
return y;
3239
}
3340

41+
// Sine function (x must be in radians)
42+
float transfer_function::sine(float amp, float f, float rad)
43+
{
44+
float w = 2*PI*f;
45+
float y = amp*sin(w*rad);
46+
return y;
47+
}
48+
3449
// Step function
3550
float transfer_function::step_threshold(float x, float threshold)
3651
{
@@ -53,4 +68,31 @@ float transfer_function::tanh(float x)
5368
{
5469
float y = ((2.0/ (1.0 + exp(-2.0 * x))) - 1.0);
5570
return y;
71+
}
72+
73+
// Thresholded sine
74+
tuple<float, float> transfer_function::thresholded_sine(float amp, float f, float rad, float z_prev)
75+
{
76+
float w = 2*PI*f;
77+
float y;
78+
float z = amp*sin(w*rad);
79+
// First threshold, on F(x)
80+
if(z >= 0.0)
81+
{
82+
// Second threshold, on F'(x)
83+
float diff = z - z_prev;
84+
if(diff >= 0.0)
85+
{
86+
y = z;
87+
}
88+
else
89+
{
90+
y = 0;
91+
}
92+
}
93+
else
94+
{
95+
y = 0.0;
96+
}
97+
return make_tuple(y, z);
5698
}

0 commit comments

Comments
 (0)