File indexing completed on 2025-09-18 09:32:32
0001 #pragma once
0002
0003 #include <cstddef> // for size_t
0004 #include <utility>
0005 #include <vector>
0006
0007
0008 class Pattern
0009 {
0010 public:
0011
0012 typedef typename std::vector<double>::iterator iterator;
0013 typedef typename std::vector<double>::const_iterator const_iterator;
0014
0015 Pattern ()
0016 : m_weight (0)
0017 {
0018 }
0019
0020 ~Pattern ()
0021 {
0022 }
0023
0024 Pattern (const Pattern& other)
0025 {
0026 m_input.assign (std::begin (other.m_input), std::end (other.m_input));
0027 m_output.assign (std::begin (other.m_output), std::end (other.m_output));
0028 m_weight = other.m_weight;
0029 }
0030
0031 Pattern (Pattern&& other)
0032 {
0033 m_input = std::move (other.m_input);
0034 m_output = std::move (other.m_output);
0035 m_weight = other.m_weight;
0036 }
0037
0038 Pattern& operator= (const Pattern& other)
0039 {
0040 m_input.assign (std::begin (other.input ()), std::end (other.input ()));
0041 m_output.assign (std::begin (other.output ()), std::end (other.output ()));
0042 m_weight = other.m_weight;
0043 return *this;
0044 }
0045
0046 template <typename ItValue>
0047 Pattern (ItValue inputBegin, ItValue inputEnd, ItValue outputBegin, ItValue outputEnd, double _weight = 1.0)
0048 : m_input (inputBegin, inputEnd)
0049 , m_output (outputBegin, outputEnd)
0050 , m_weight (_weight)
0051 {
0052 }
0053
0054 template <typename ItValue>
0055 Pattern (ItValue inputBegin, ItValue inputEnd, double outputValue, double _weight = 1.0)
0056 : m_input (inputBegin, inputEnd)
0057 , m_weight (_weight)
0058 {
0059 m_output.push_back (outputValue);
0060 }
0061
0062 template <typename InputContainer, typename OutputContainer>
0063 Pattern (InputContainer& _input, OutputContainer& _output, double _weight = 1.0)
0064 : m_input (std::begin (_input), std::end (_input))
0065 , m_output (std::begin (_output), std::end (_output))
0066 , m_weight (_weight)
0067 {
0068 }
0069
0070 const_iterator beginInput () const { return m_input.begin (); }
0071 const_iterator endInput () const { return m_input.end (); }
0072 const_iterator beginOutput () const { return m_output.begin (); }
0073 const_iterator endOutput () const { return m_output.end (); }
0074
0075 double weight () const { return m_weight; }
0076 void weight (double w) { m_weight = w; }
0077
0078 size_t inputSize () const { return m_input.size (); }
0079 size_t outputSize () const { return m_output.size (); }
0080
0081 void addInput (double value) { m_input.push_back (value); }
0082 void addOutput (double value) { m_output.push_back (value); }
0083
0084 std::vector<double>& input () { return m_input; }
0085 std::vector<double>& output () { return m_output; }
0086 const std::vector<double>& input () const { return m_input; }
0087 const std::vector<double>& output () const { return m_output; }
0088
0089 private:
0090 std::vector<double> m_input;
0091 std::vector<double> m_output;
0092 double m_weight;
0093 };