浏览代码

added FPFeature for using available Vector raw data (VectorFeature)

Johannes Ruehle 11 年之前
父节点
当前提交
4b984606fb
共有 2 个文件被更改,包括 156 次插入0 次删除
  1. 62 0
      features/fpfeatures/VectorFeature.cpp
  2. 94 0
      features/fpfeatures/VectorFeature.h

+ 62 - 0
features/fpfeatures/VectorFeature.cpp

@@ -0,0 +1,62 @@
+#include <iostream>
+
+#include "VectorFeature.h"
+#include "vislearning/cbaselib/FeaturePool.h"
+
+using namespace OBJREC;
+
+using namespace std;
+// refactor-nice.pl: check this substitution
+// old: using namespace ice;
+using namespace NICE;
+
+/** simple destructor */
+VectorFeature::~VectorFeature()
+{
+}
+
+double VectorFeature::val( const Example *example ) const
+{
+    return example->vec->get(feature_index);
+}
+
+void VectorFeature::explode ( FeaturePool & featurePool, bool variableWindow ) const
+{
+	for ( int i = 0 ; i < dimension ; i++ )
+	{
+        VectorFeature *f = new VectorFeature ( dimension , i);
+		featurePool.addFeature(f, 1.0 / dimension);
+	}
+}
+
+Feature *VectorFeature::clone() const
+{
+    VectorFeature *f = new VectorFeature( dimension, feature_index);
+	return f;
+}
+
+Feature *VectorFeature::generateFirstParameter () const
+{
+	return clone();
+}
+
+void VectorFeature::restore (istream & is, int format)
+{
+	is >> feature_index;
+}
+
+void VectorFeature::store (ostream & os, int format) const
+{
+    os << "VECTORFEATURE "
+			<< feature_index;
+}
+
+void VectorFeature::clear ()
+{
+}
+
+void VectorFeature::getStump ( int & _feature_index, int & _dimension ) const
+{
+	_feature_index = feature_index;
+	_dimension = dimension;
+}

+ 94 - 0
features/fpfeatures/VectorFeature.h

@@ -0,0 +1,94 @@
+/** 
+ * @file VectorFeature.h
+ * @brief feature class to use feature raw data stored in Examples
+ * @author Johannes Ruehle
+ * @date 04/11/2014
+
+ */
+#ifndef VectorFeatureINCLUDE
+#define VectorFeatureINCLUDE
+
+#include "vislearning/cbaselib/Feature.h"
+
+namespace OBJREC {
+
+class VectorFeature : public Feature
+{
+
+	protected:
+		//! feature dimension
+		int dimension;
+		
+		//! index of the feature
+		int feature_index;
+
+	public:
+  
+		/**
+         * internally used by VectorFeature::explode
+		 * @param _dimension new dimension
+		 * @param _feature_index new featureindex
+		 */
+        VectorFeature ( int _dimension, int _feature_index = 0 ):
+            dimension(_dimension), feature_index(_feature_index)
+        {}
+      
+		/**
+		 * simple destructor
+		 */
+        virtual ~VectorFeature();
+     
+		/**
+		 * returns the value of the sparse feature stored in example
+		 * @param example input example
+		 * @return feature value
+		 */
+		double val( const Example *example ) const;
+		
+		
+		/**
+		 * creates for each feature a own SparseVectorFeature in featurepool
+		 * @param featurePool the feature pool
+		 * @param variableWindow 
+		 */
+		void explode ( FeaturePool & featurePool, bool variableWindow = true ) const;
+		
+		
+		Feature *clone() const;
+		Feature *generateFirstParameter () const;
+
+		/**
+		 * store the data
+		 * @param is input stream
+		 * @param format 
+		 */
+		void restore (std::istream & is, int format = 0);
+		
+		
+		/**
+		 * read the data
+		 * @param os 
+		 * @param format 
+		 */
+		void store (std::ostream & os, int format = 0) const;
+		
+		
+		/**
+		 * does nothing
+		 */
+		void clear ();
+
+		
+		/**
+		 * returns the feature index and the dimension
+		 * @param feature_index 
+		 * @param dimension 
+		 */
+		void getStump ( int & feature_index, int & dimension ) const;
+
+};
+
+
+} // namespace
+
+#endif