diff options
author | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 19:04:34 +0100 |
---|---|---|
committer | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 19:16:14 +0100 |
commit | e6ab4a8ed100d5d5b7611c74cf3ccd556f1f1d71 (patch) | |
tree | 129cf13c2f9b3eae54402300db4570815789a02a /include/HyperNeat/Utils |
Diffstat (limited to 'include/HyperNeat/Utils')
-rw-r--r-- | include/HyperNeat/Utils/Atomic.hpp | 12 | ||||
-rw-r--r-- | include/HyperNeat/Utils/Function.hpp | 12 | ||||
-rw-r--r-- | include/HyperNeat/Utils/LoadFile.hpp | 40 | ||||
-rw-r--r-- | include/HyperNeat/Utils/Map.hpp | 12 | ||||
-rw-r--r-- | include/HyperNeat/Utils/NodeTypes.hpp | 22 | ||||
-rw-r--r-- | include/HyperNeat/Utils/Pi.hpp | 9 | ||||
-rw-r--r-- | include/HyperNeat/Utils/Point.hpp | 21 | ||||
-rw-r--r-- | include/HyperNeat/Utils/Pointer.hpp | 12 | ||||
-rw-r--r-- | include/HyperNeat/Utils/Random.hpp | 14 | ||||
-rw-r--r-- | include/HyperNeat/Utils/SaveFile.hpp | 45 | ||||
-rw-r--r-- | include/HyperNeat/Utils/Set.hpp | 12 | ||||
-rw-r--r-- | include/HyperNeat/Utils/Size.hpp | 12 | ||||
-rw-r--r-- | include/HyperNeat/Utils/String.hpp | 11 | ||||
-rw-r--r-- | include/HyperNeat/Utils/Thread.hpp | 11 | ||||
-rw-r--r-- | include/HyperNeat/Utils/ValueMap.hpp | 12 | ||||
-rw-r--r-- | include/HyperNeat/Utils/ValuePoint.hpp | 19 | ||||
-rw-r--r-- | include/HyperNeat/Utils/Vector.hpp | 12 | ||||
-rw-r--r-- | include/HyperNeat/Utils/Vector2D.hpp | 12 |
18 files changed, 300 insertions, 0 deletions
diff --git a/include/HyperNeat/Utils/Atomic.hpp b/include/HyperNeat/Utils/Atomic.hpp new file mode 100644 index 0000000..850a06e --- /dev/null +++ b/include/HyperNeat/Utils/Atomic.hpp @@ -0,0 +1,12 @@ +#ifndef __HYPERNEAT_ATOM_HPP__ +#define __HYPERNEAT_ATOM_HPP__ + +#include <atomic> + +namespace hyperneat +{ + template <class T> + using Atomic = std::atomic<T>; +} + +#endif diff --git a/include/HyperNeat/Utils/Function.hpp b/include/HyperNeat/Utils/Function.hpp new file mode 100644 index 0000000..ebcb27b --- /dev/null +++ b/include/HyperNeat/Utils/Function.hpp @@ -0,0 +1,12 @@ +#ifndef __HYPERNEAT_FUNCTION_HPP__ +#define __HYPERNEAT_FUNCTION_HPP__ + +#include <functional> + +namespace hyperneat +{ + template <class F> + using Function = std::function<F>; +} + +#endif diff --git a/include/HyperNeat/Utils/LoadFile.hpp b/include/HyperNeat/Utils/LoadFile.hpp new file mode 100644 index 0000000..1960e90 --- /dev/null +++ b/include/HyperNeat/Utils/LoadFile.hpp @@ -0,0 +1,40 @@ +#ifndef __HYPERNEAT_LOADFILE_HPP__ +#define __HYPERNEAT_LOADFILE_HPP__ + +#include <iostream> +#include <HyperNeat/Utils/String.hpp> +#include <HyperNeat/Utils/Vector.hpp> + +namespace hyperneat +{ + using Istream = std::istream; + + class Genome; + class Organism; + class Population; + class NoveltyMetric; + class PopulationPrms; + class NoveltyMetricPrms; + + class LoadFile + { + public: + LoadFile(Istream& stream); + + void loadPopulation(Population& population); + void loadPopulationPrms(PopulationPrms& prms); + void loadNeuralNetPrms(NeuralNetPrms& prms); + void loadNoveltyMetric(NoveltyMetric& noveltyMetric); + void loadNoveltyMetricPrms(NoveltyMetricPrms& prms); + void loadOrganism(Organism& organism); + void loadGenome(Genome& genome); + + private: + Istream& nextPrm(bool arrayVal = false); + Istream& nextArrayValue(); + + Istream& _stream; + }; +} + +#endif diff --git a/include/HyperNeat/Utils/Map.hpp b/include/HyperNeat/Utils/Map.hpp new file mode 100644 index 0000000..c735ab3 --- /dev/null +++ b/include/HyperNeat/Utils/Map.hpp @@ -0,0 +1,12 @@ +#ifndef __HYPERNEAT_MAP_HPP__ +#define __HYPERNEAT_MAP_HPP__ + +#include <map> + +namespace hyperneat +{ + template <class K, class V> + using Map = std::map<K, V>; +} + +#endif diff --git a/include/HyperNeat/Utils/NodeTypes.hpp b/include/HyperNeat/Utils/NodeTypes.hpp new file mode 100644 index 0000000..815214e --- /dev/null +++ b/include/HyperNeat/Utils/NodeTypes.hpp @@ -0,0 +1,22 @@ +#ifndef __HYPERNEAT_NODETYPES_HPP__ +#define __HYPERNEAT_NODETYPES_HPP__ + +#include <HyperNeat/Utils/String.hpp> + +namespace hyperneat +{ + enum class NodeType { + NULL_TYPE = -1, + SIGMOID = 0, + GAUSSIAN = 1, + SINE = 2, + ABSOLUTE = 3, + }; + + String nodeToString(NodeType type); + NodeType stringToNode(const String& str); + + const size_t NODE_TYPES_COUNT = 4; +} + +#endif diff --git a/include/HyperNeat/Utils/Pi.hpp b/include/HyperNeat/Utils/Pi.hpp new file mode 100644 index 0000000..00a3df2 --- /dev/null +++ b/include/HyperNeat/Utils/Pi.hpp @@ -0,0 +1,9 @@ +#ifndef __HYPERNEAT_PI_HPP__ +#define __HYPERNEAT_PI_HPP__ + +namespace hyperneat +{ + const double PI = 3.14159265359; +} + +#endif diff --git a/include/HyperNeat/Utils/Point.hpp b/include/HyperNeat/Utils/Point.hpp new file mode 100644 index 0000000..ba51bac --- /dev/null +++ b/include/HyperNeat/Utils/Point.hpp @@ -0,0 +1,21 @@ +#ifndef __HYPERNEAT_POINT_HPP__ +#define __HYPERNEAT_POINT_HPP__ + +namespace hyperneat +{ + class Point + { + public: + Point() = default; + Point(double x, double y); + + double distance(const Point& other) const; + bool operator== (const Point& other) const; + bool operator< (const Point& other) const; + + double _x = 0.0; + double _y = 0.0; + }; +} + +#endif diff --git a/include/HyperNeat/Utils/Pointer.hpp b/include/HyperNeat/Utils/Pointer.hpp new file mode 100644 index 0000000..f02e853 --- /dev/null +++ b/include/HyperNeat/Utils/Pointer.hpp @@ -0,0 +1,12 @@ +#ifndef __HYPERNEAT_POINTER_HPP__ +#define __HYPERNEAT_POINTER_HPP__ + +#include <memory> + +namespace hyperneat +{ + template <class T> + using Pointer = std::unique_ptr<T>; +} + +#endif diff --git a/include/HyperNeat/Utils/Random.hpp b/include/HyperNeat/Utils/Random.hpp new file mode 100644 index 0000000..4a4d979 --- /dev/null +++ b/include/HyperNeat/Utils/Random.hpp @@ -0,0 +1,14 @@ +#ifndef __HYPERNEAT_RANDOM_HPP__ +#define __HYPERNEAT_RANDOM_HPP__ + +#include <random> + +namespace hyperneat +{ + using RandGen = std::mt19937_64; + using IntDist = std::uniform_int_distribution<size_t>; + using RealDist = std::uniform_real_distribution<double>; + using BellDist = std::normal_distribution<double>; +} + +#endif diff --git a/include/HyperNeat/Utils/SaveFile.hpp b/include/HyperNeat/Utils/SaveFile.hpp new file mode 100644 index 0000000..18cad38 --- /dev/null +++ b/include/HyperNeat/Utils/SaveFile.hpp @@ -0,0 +1,45 @@ +#ifndef __HYPERNEAT_SAVEFILE_HPP__ +#define __HYPERNEAT_SAVEFILE_HPP__ + +#include <iostream> +#include <HyperNeat/Utils/String.hpp> +#include <HyperNeat/Utils/Vector.hpp> + +namespace hyperneat +{ + using Ostream = std::ostream; + + class Genome; + class Organism; + class Population; + class NoveltyMetric; + class NeuralNetPrms; + class PopulationPrms; + class NoveltyMetricPrms; + + class SaveFile + { + public: + SaveFile(Ostream& stream); + + void savePopulation(Population& population, bool shuttedDown = false, size_t tabs = 0, + const String& prefix = ""); + void savePopulationPrms(const PopulationPrms& prms, size_t tabs = 0, const String& prefix = ""); + void saveNeuralNetPrms(const NeuralNetPrms& prms, size_t tabs = 0, const String& prefix = ""); + void saveOrganism(const Organism& organism, bool shuttedDown = false, size_t tabs = 0, + const String& prefix = ""); + void saveGenome(const Genome& genome, size_t tabs = 0, const String& prefix = ""); + void saveNoveltyMetric(const NoveltyMetric& noveltyMetric, bool shuttedDown = false, size_t tabs = 0, + const String& prefix = ""); + void saveNoveltyMetricPrms(const NoveltyMetricPrms& noveltyMetricPrms, size_t tabs = 0, + const String& prefix = ""); + + private: + Ostream& print(size_t tabs = 0); + String newl(size_t lines = 1); + + Ostream& _stream; + }; +} + +#endif diff --git a/include/HyperNeat/Utils/Set.hpp b/include/HyperNeat/Utils/Set.hpp new file mode 100644 index 0000000..d403e6b --- /dev/null +++ b/include/HyperNeat/Utils/Set.hpp @@ -0,0 +1,12 @@ +#ifndef __HYPERNEAT_SET_HPP__ +#define __HYPERNEAT_SET_HPP__ + +#include <set> + +namespace hyperneat +{ + template <class V> + using Set = std::set<V>; +} + +#endif diff --git a/include/HyperNeat/Utils/Size.hpp b/include/HyperNeat/Utils/Size.hpp new file mode 100644 index 0000000..0ef5616 --- /dev/null +++ b/include/HyperNeat/Utils/Size.hpp @@ -0,0 +1,12 @@ +#ifndef __HYPERNEAT_SIZE_HPP__ +#define __HYPERNEAT_SIZE_HPP__ + +#include <cstddef> +#include <climits> + +namespace hyperneat +{ + using std::size_t; +} + +#endif diff --git a/include/HyperNeat/Utils/String.hpp b/include/HyperNeat/Utils/String.hpp new file mode 100644 index 0000000..ab74d45 --- /dev/null +++ b/include/HyperNeat/Utils/String.hpp @@ -0,0 +1,11 @@ +#ifndef HYPERNEAT_STRING_HPP +#define HYPERNEAT_STRING_HPP + +#include <string> + +namespace hyperneat +{ + using String = std::string; +} + +#endif diff --git a/include/HyperNeat/Utils/Thread.hpp b/include/HyperNeat/Utils/Thread.hpp new file mode 100644 index 0000000..4b861e3 --- /dev/null +++ b/include/HyperNeat/Utils/Thread.hpp @@ -0,0 +1,11 @@ +#ifndef __HYPERNEAT_THREAD_HPP__ +#define __HYPERNEAT_THREAD_HPP__ + +#include <thread> + +namespace hyperneat +{ + using Thread = std::thread; +} + +#endif diff --git a/include/HyperNeat/Utils/ValueMap.hpp b/include/HyperNeat/Utils/ValueMap.hpp new file mode 100644 index 0000000..c2910b5 --- /dev/null +++ b/include/HyperNeat/Utils/ValueMap.hpp @@ -0,0 +1,12 @@ +#ifndef __HYPERNEAT_VALUEMAP_HPP__ +#define __HYPERNEAT_VALUEMAP_HPP__ + +#include <HyperNeat/Utils/Vector.hpp> +#include <HyperNeat/Utils/ValuePoint.hpp> + +namespace hyperneat +{ + using ValueMap = Vector<ValuePoint>; +} + +#endif diff --git a/include/HyperNeat/Utils/ValuePoint.hpp b/include/HyperNeat/Utils/ValuePoint.hpp new file mode 100644 index 0000000..b9e15ab --- /dev/null +++ b/include/HyperNeat/Utils/ValuePoint.hpp @@ -0,0 +1,19 @@ +#ifndef __HYPERNEAT_VALUEPOINT_HPP__ +#define __HYPERNEAT_VALUEPOINT_HPP__ + +#include <HyperNeat/Utils/Point.hpp> + +namespace hyperneat +{ + class ValuePoint : public Point + { + public: + ValuePoint() = default; + ValuePoint(double x, double y, double value, double segment); + + double _value = 0.0; + double _segment = 0.0; + }; +} + +#endif diff --git a/include/HyperNeat/Utils/Vector.hpp b/include/HyperNeat/Utils/Vector.hpp new file mode 100644 index 0000000..f7352e4 --- /dev/null +++ b/include/HyperNeat/Utils/Vector.hpp @@ -0,0 +1,12 @@ +#ifndef __HYPERNEAT_VECTOR_HPP__ +#define __HYPERNEAT_VECTOR_HPP__ + +#include <vector> + +namespace hyperneat +{ + template <class V> + using Vector = std::vector<V>; +} + +#endif diff --git a/include/HyperNeat/Utils/Vector2D.hpp b/include/HyperNeat/Utils/Vector2D.hpp new file mode 100644 index 0000000..257dbe6 --- /dev/null +++ b/include/HyperNeat/Utils/Vector2D.hpp @@ -0,0 +1,12 @@ +#ifndef __HYPERNEAT_VECTOR2D_HPP__ +#define __HYPERNEAT_VECTOR2D_HPP__ + +#include <Hyperneat/Utils/Vector.hpp> + +namespace hyperneat +{ + template <class V> + using Vector2D = Vector<Vector<V>>; +} + +#endif |