Skip to content

Commit 23987ef

Browse files
committed
Changes from review:
- Renamed FANN_LINEAR_PIECE_LEAKY to FANN_LINEAR_PIECE_RECT_LEAKY - Added test case for FANN_LINEAR_PIECE_RECT_LEAKY
1 parent 0c95d0d commit 23987ef

File tree

7 files changed

+38
-26
lines changed

7 files changed

+38
-26
lines changed

src/fann.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,12 @@ FANN_EXTERNAL fann_type *FANN_API fann_run(struct fann *ann, fann_type *input) {
692692
: (neuron_sum > multiplier) ? multiplier
693693
: neuron_sum);
694694
break;
695-
case FANN_LINEAR_PIECE_LEAKY:
696-
neuron_it->value = (fann_type)((neuron_sum < 0) ? 0.01 * neuron_sum : neuron_sum);
697-
break;
698695
case FANN_LINEAR_PIECE_RECT:
699696
neuron_it->value = (fann_type)((neuron_sum < 0) ? 0 : neuron_sum);
700697
break;
698+
case FANN_LINEAR_PIECE_RECT_LEAKY:
699+
neuron_it->value = (fann_type)((neuron_sum < 0) ? 0.01 * neuron_sum : neuron_sum);
700+
break;
701701
case FANN_ELLIOT:
702702
case FANN_ELLIOT_SYMMETRIC:
703703
case FANN_GAUSSIAN:

src/fann_cascade.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,8 @@ fann_type fann_train_candidates_epoch(struct fann *ann, struct fann_train_data *
680680
case FANN_GAUSSIAN_STEPWISE:
681681
case FANN_ELLIOT:
682682
case FANN_LINEAR_PIECE:
683-
case FANN_LINEAR_PIECE_LEAKY:
684683
case FANN_LINEAR_PIECE_RECT:
684+
case FANN_LINEAR_PIECE_RECT_LEAKY:
685685
case FANN_SIN:
686686
case FANN_COS:
687687
break;

src/fann_train.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ fann_type fann_activation_derived(unsigned int activation_function, fann_type st
4040
case FANN_LINEAR_PIECE:
4141
case FANN_LINEAR_PIECE_SYMMETRIC:
4242
return (fann_type)fann_linear_derive(steepness, value);
43-
case FANN_LINEAR_PIECE_LEAKY:
44-
return (fann_type)((value < 0) ? steepness * 0.01 : steepness);
4543
case FANN_LINEAR_PIECE_RECT:
4644
return (fann_type)((value < 0) ? 0 : steepness);
45+
case FANN_LINEAR_PIECE_RECT_LEAKY:
46+
return (fann_type)((value < 0) ? steepness * 0.01 : steepness);
4747
case FANN_SIGMOID:
4848
case FANN_SIGMOID_STEPWISE:
4949
value = fann_clip(value, 0.01f, 0.99f);
@@ -129,8 +129,8 @@ fann_type fann_update_MSE(struct fann *ann, struct fann_neuron *neuron, fann_typ
129129
case FANN_GAUSSIAN_STEPWISE:
130130
case FANN_ELLIOT:
131131
case FANN_LINEAR_PIECE:
132-
case FANN_LINEAR_PIECE_LEAKY:
133132
case FANN_LINEAR_PIECE_RECT:
133+
case FANN_LINEAR_PIECE_RECT_LEAKY:
134134
case FANN_SIN:
135135
case FANN_COS:
136136
break;

src/include/fann_activation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ __doublefann_h__ is not defined
178178
case FANN_GAUSSIAN_STEPWISE: \
179179
result = 0; \
180180
break; \
181-
case FANN_LINEAR_PIECE_LEAKY: \
182-
result = (fann_type)((value < 0) ? value * 0.01 : value); \
183-
break; \
184181
case FANN_LINEAR_PIECE_RECT: \
185182
result = (fann_type)((value < 0) ? 0 : value); \
186183
break; \
184+
case FANN_LINEAR_PIECE_RECT_LEAKY: \
185+
result = (fann_type)((value < 0) ? value * 0.01 : value); \
186+
break; \
187187
}
188188

189189
#endif

src/include/fann_data.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,16 @@ static char const *const FANN_TRAIN_NAMES[] = {"FANN_TRAIN_INCREMENTAL", "FANN_T
196196
* y = cos(x*s)/2+0.5
197197
* d = s*-sin(x*s)/2
198198
199-
FANN_LINEAR_PIECE_LEAKY - leaky ReLU
200-
* span: -inf < y < inf
201-
* y = x<0? 0.01*x: x
202-
* d = x<0? 0.01: 1
203-
204199
FANN_LINEAR_PIECE_RECT - ReLU
205200
* span: -inf < y < inf
206201
* y = x<0? 0: x
207202
* d = x<0? 0: 1
208203
204+
FANN_LINEAR_PIECE_RECT_LEAKY - leaky ReLU
205+
* span: -inf < y < inf
206+
* y = x<0? 0.01*x: x
207+
* d = x<0? 0.01: 1
208+
209209
See also:
210210
<fann_set_activation_function_layer>, <fann_set_activation_function_hidden>,
211211
<fann_set_activation_function_output>, <fann_set_activation_steepness>,
@@ -234,8 +234,8 @@ enum fann_activationfunc_enum {
234234
FANN_COS_SYMMETRIC,
235235
FANN_SIN,
236236
FANN_COS,
237-
FANN_LINEAR_PIECE_LEAKY,
238-
FANN_LINEAR_PIECE_RECT
237+
FANN_LINEAR_PIECE_RECT,
238+
FANN_LINEAR_PIECE_RECT_LEAKY
239239
};
240240

241241
/* Constant: FANN_ACTIVATIONFUNC_NAMES
@@ -267,8 +267,8 @@ static char const *const FANN_ACTIVATIONFUNC_NAMES[] = {"FANN_LINEAR",
267267
"FANN_COS_SYMMETRIC",
268268
"FANN_SIN",
269269
"FANN_COS",
270-
"FANN_LINEAR_PIECE_LEAKY",
271-
"FANN_LINEAR_PIECE_RECT"};
270+
"FANN_LINEAR_PIECE_RECT",
271+
"FANN_LINEAR_PIECE_RECT_LEAKY"};
272272

273273
/* Enum: fann_errorfunc_enum
274274
Error function used during training.

src/include/fann_data_cpp.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,16 @@ enum training_algorithm_enum {
200200
* y = cos(x*s)
201201
* d = s*-sin(x*s)
202202
203-
FANN_LINEAR_PIECE_LEAKY - leaky ReLU
204-
* span: -inf < y < inf
205-
* y = x<0? 0.01*x: x
206-
* d = x<0? 0.01: 1
207-
208203
FANN_LINEAR_PIECE_RECT - ReLU
209204
* span: -inf < y < inf
210205
* y = x<0? 0: x
211206
* d = x<0? 0: 1
212207
208+
FANN_LINEAR_PIECE_RECT_LEAKY - leaky ReLU
209+
* span: -inf < y < inf
210+
* y = x<0? 0.01*x: x
211+
* d = x<0? 0.01: 1
212+
213213
See also:
214214
<neural_net::set_activation_function_hidden>,
215215
<neural_net::set_activation_function_output>
@@ -231,8 +231,8 @@ enum activation_function_enum {
231231
LINEAR_PIECE_SYMMETRIC,
232232
SIN_SYMMETRIC,
233233
COS_SYMMETRIC,
234-
LINEAR_PIECE_LEAKY,
235-
LINEAR_PIECE_RECT
234+
LINEAR_PIECE_RECT,
235+
LINEAR_PIECE_RECT_LEAKY
236236
};
237237

238238
/* Enum: network_type_enum

tests/fann_test_train.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ TEST_F(FannTestTrain, TrainOnReLUSimpleXor) {
3333
EXPECT_LT(net.test_data(data), 0.001);
3434
}
3535

36+
TEST_F(FannTestTrain, TrainOnReLULeakySimpleXor) {
37+
neural_net net(LAYER, 3, 2, 3, 1);
38+
39+
data.set_train_data(4, 2, xorInput, 1, xorOutput);
40+
net.set_activation_function_hidden(FANN::LINEAR_PIECE_RECT_LEAKY);
41+
net.set_activation_steepness_hidden(1.0);
42+
net.train_on_data(data, 100, 100, 0.001);
43+
44+
EXPECT_LT(net.get_MSE(), 0.001);
45+
EXPECT_LT(net.test_data(data), 0.001);
46+
}
47+
3648
TEST_F(FannTestTrain, TrainSimpleIncrementalXor) {
3749
neural_net net(LAYER, 3, 2, 3, 1);
3850

0 commit comments

Comments
 (0)