Pattern.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _OPENCOG_HDEMO_PATTERN_MATRIX_H
00023 #define _OPENCOG_HDEMO_PATTERN_MATRIX_H
00024
00025 #include <vector>
00026
00027 #include <opencog/atomspace/AttentionValue.h>
00028 #include <opencog/util/RandGen.h>
00029
00030 namespace opencog
00031 {
00032
00033 extern RandGen* patternRng;
00034
00035 class Pattern : public std::vector< int >
00036 {
00037
00038 private:
00039
00040 int width;
00041 int height;
00042
00043 opencog::RandGen *rng;
00044 std::vector<bool> *mask;
00045
00046 public:
00047
00055 Pattern(int w, int h, float density = 0.0f);
00056
00057 Pattern(const Pattern &src) : std::vector<int>(src),
00058 width(src.width), height(src.height), rng(patternRng), mask(NULL) {
00059 if (src.mask) mask = new std::vector<bool>(*(src.mask));
00060 };
00061
00062 ~Pattern();
00063
00064 Pattern & operator = (const Pattern & other) {
00065 if (this != &other) {
00066
00067 width = other.width;
00068 height = other.height;
00069 rng = patternRng;
00070 mask = NULL;
00071 if (other.mask) mask = new std::vector<bool>(*(other.mask));
00072 std::vector<int>::operator=(other);
00073 }
00074 return *this;
00075 }
00076
00084 float hammingSimilarity(const Pattern &p);
00085
00092 int bitErrors(const Pattern &p);
00093
00100 Pattern binarisePattern(AttentionValue::sti_t threshold);
00101
00109 Pattern mutatePattern(float error);
00110
00117 Pattern mutatePattern(unsigned int error);
00118
00119 int getWidth();
00120 int getHeight();
00121 bool isEmpty();
00122 void setMask(const std::vector<bool>& _mask);
00123 bool isMasked(uint i) const;
00124
00125 int activity();
00126
00136 static std::vector< Pattern > generateRandomPatterns(int amount, int w, int h, float density);
00137
00145 static std::vector< Pattern > mutatePatterns( std::vector< Pattern > &patterns, float error);
00146
00156 static std::vector< Pattern > loadPatterns( std::string fn, int size);
00157
00158 bool operator==(const Pattern& b) const;
00159 };
00160
00161 }
00162
00163 #endif // _OPENCOG_HDEMO_PATTERN_MATRIX_H