Pattern.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 by Singularity Institute for Artificial Intelligence
00003  * Written by Joel Pitt <joel@fruitionnz.com>
00004  * All Rights Reserved
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Affero General Public License v3 as
00008  * published by the Free Software Foundation and including the exceptions
00009  * at http://opencog.org/wiki/Licenses
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Affero General Public License
00017  * along with this program; if not, write to:
00018  * Free Software Foundation, Inc.,
00019  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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     // Height and width of pattern
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             // protect against invalid self-assignment
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 } // namespace opencog
00162 
00163 #endif // _OPENCOG_HDEMO_PATTERN_MATRIX_H

Generated on Fri Dec 4 23:23:25 2009 for OpenCog Framework by  doxygen 1.5.6