Skip to content

Commit

Permalink
Added projct files for IntelliJ CLion
Browse files Browse the repository at this point in the history
  • Loading branch information
steffennissen committed Nov 1, 2015
1 parent cfadb67 commit 09157e5
Show file tree
Hide file tree
Showing 12 changed files with 671 additions and 140 deletions.
6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

400 changes: 400 additions & 0 deletions .idea/fann.iml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/runConfigurations/Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ project (fann_tests)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/include)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/lib/googletest/include)

ADD_EXECUTABLE(fann_tests fann_tests.cpp main.cpp)
ADD_EXECUTABLE(fann_tests create_net.cpp main.cpp fann_test.h train_data.cpp fann_test.cpp)
target_link_libraries(fann_tests gtest doublefann)
91 changes: 91 additions & 0 deletions tests/create_net.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
Fast Artificial Neural Network Library (fann)
Copyright (C) 2003-2012 Steffen Nissen (sn@leenissen.dk)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <stdio.h>
#include "gtest/gtest.h"

#include "doublefann.h"
#include "fann_cpp.h"
#include "fann_test.h"

TEST_F(FannTest, CreateStandardThreeLayers) {
ASSERT_TRUE(net.create_standard(3, 2, 3, 4));
unsigned int layers[] = {2, 3, 4};
AssertCreateAndCopy(3, layers, 11, 25);
}

TEST_F(FannTest, CreateStandardFourLayers) {
ASSERT_TRUE(net.create_standard(4, 2, 3, 4, 5));
unsigned int layers[] = {2, 3, 4, 5};
AssertCreateAndCopy(4, layers, 17, 50);
}

TEST_F(FannTest, CreateStandardFourLayersArray) {
unsigned int layers[] = {2, 3, 4, 5};
ASSERT_TRUE(net.create_standard_array(4, layers));
AssertCreateAndCopy(4, layers, 17, 50);
}

TEST_F(FannTest, CreateSparseFourLayers) {
ASSERT_TRUE(net.create_sparse(0.5f, 4, 2, 3, 4, 5));
unsigned int layers[] = {2, 3, 4, 5};
AssertCreateAndCopy(4, layers, 17, 31);
}

TEST_F(FannTest, CreateSparseArrayFourLayers) {
unsigned int layers[] = {2, 3, 4, 5};
ASSERT_TRUE(net.create_sparse_array(0.5f, 4, layers));
AssertCreateAndCopy(4, layers, 17, 31);
}

TEST_F(FannTest, CreateSparseArrayWithMinimalConnectivity) {
unsigned int layers[] = {2, 2, 2};
ASSERT_TRUE(net.create_sparse_array(0.01f, 3, layers));
AssertCreateAndCopy(3, layers, 8, 8);
}

TEST_F(FannTest, CreateShortcutFourLayers) {
ASSERT_TRUE(net.create_shortcut(4, 2, 3, 4, 5));
unsigned int layers[] = {2, 3, 4, 5};
AssertCreateAndCopy(4, layers, 15, 83);
EXPECT_EQ(FANN::SHORTCUT, net.get_network_type());
}

TEST_F(FannTest, CreateShortcutArrayFourLayers) {
unsigned int layers[] = {2, 3, 4, 5};
ASSERT_TRUE(net.create_shortcut_array(4, layers));
AssertCreateAndCopy(4, layers, 15, 83);
EXPECT_EQ(FANN::SHORTCUT, net.get_network_type());
}

TEST_F(FannTest, CreateFromFile) {
ASSERT_TRUE(net.create_standard(3, 2, 3, 4));
ASSERT_TRUE(net.save("tmpfile"));
net.destroy();
ASSERT_TRUE(net.create_from_file("tmpfile"));

unsigned int layers[] = {2, 3, 4};
AssertCreateAndCopy(3, layers, 11, 25);
}

TEST_F(FannTest, RandomizeWeights) {
net.create_standard(2, 20, 10);
net.randomize_weights(-1.0, 1.0);
AssertWeights(-1.0, 1.0, 0);
}
57 changes: 57 additions & 0 deletions tests/fann_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "fann_test.h"

void FannTest::SetUp() {
srand(0);
fann_disable_seed_rand();
}

void FannTest::TearDown() {
net.destroy();
data.destroy_train();
}

void FannTest::AssertCreate(FANN::neural_net net, unsigned int num_layers, unsigned int *layers,
unsigned int neurons, unsigned int connections) {
EXPECT_EQ(num_layers, net.get_num_layers());
EXPECT_EQ(layers[0], net.get_num_input());
EXPECT_EQ(layers[num_layers - 1], net.get_num_output());
unsigned int *layers_res = new unsigned int[num_layers];
net.get_layer_array(layers_res);
for (unsigned int i = 0; i < num_layers; i++) {
EXPECT_EQ(layers[i], layers_res[i]);
}
delete layers_res;

EXPECT_EQ(neurons, net.get_total_neurons());
EXPECT_EQ(connections, net.get_total_connections());

AssertWeights(-0.09, 0.09, 0.0);
}

void FannTest::AssertCreateAndCopy(unsigned int num_layers, unsigned int *layers, unsigned int neurons,
unsigned int connections) {
AssertCreate(net, num_layers, layers, neurons, connections);
FANN::neural_net net_copy(net);
AssertCreate(net_copy, num_layers, layers, neurons, connections);
}

void FannTest::AssertWeights(fann_type expected_min_weight, fann_type expected_max_weight,
fann_type expected_avg_weight) {
FANN::connection *connections = new FANN::connection[net.get_total_connections()];
net.get_connection_array(connections);

fann_type min_weight = connections[0].weight;
fann_type max_weight = connections[0].weight;
fann_type total_weight = 0.0;
for (int i = 1; i < net.get_total_connections(); ++i) {
if(connections[i].weight < min_weight)
min_weight = connections[i].weight;
if(connections[i].weight > max_weight)
max_weight = connections[i].weight;
total_weight += connections[i].weight;
}

EXPECT_NEAR(expected_min_weight, min_weight, 0.01);
EXPECT_NEAR(expected_max_weight, max_weight, 0.01);
EXPECT_NEAR(expected_avg_weight, total_weight/(fann_type)net.get_total_connections(), 0.1);
}
31 changes: 31 additions & 0 deletions tests/fann_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef FANN_FANN_TESTFIXTURE_H
#define FANN_FANN_TESTFIXTURE_H

#include "gtest/gtest.h"

#include "doublefann.h"
#include "fann_cpp.h"

//ensure random generator is seeded at a known value to ensure reproducible results

class FannTest : public testing::Test {
protected:
FANN::neural_net net;
FANN::training_data data;

void AssertCreateAndCopy(unsigned int num_layers, unsigned int *layers, unsigned int neurons,
unsigned int connections);

void AssertCreate(FANN::neural_net net, unsigned int num_layers, unsigned int *layers,
unsigned int neurons, unsigned int connections);

void AssertWeights(fann_type expected_min_weight, fann_type expected_max_weight,
fann_type expected_avg_weight);

virtual void SetUp();

virtual void TearDown();

};

#endif //FANN_FANN_TESTFIXTURE_H
139 changes: 0 additions & 139 deletions tests/fann_tests.cpp

This file was deleted.

Loading

0 comments on commit 09157e5

Please sign in to comment.