00001 /* 00002 * Copyright (c) 2009 Yahoo! Inc. All rights reserved. The copyrights 00003 * embodied in the content of this file are licensed under the BSD 00004 * (revised) open source license. 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * Written (W) 2011 Shashwat Lal Das 00012 * Adaptation of Vowpal Wabbit v5.1. 00013 * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society. 00014 */ 00015 00016 #ifndef _VW_CACHEREAD_H__ 00017 #define _VW_CACHEREAD_H__ 00018 00019 #include <shogun/base/SGObject.h> 00020 #include <shogun/lib/common.h> 00021 #include <shogun/io/IOBuffer.h> 00022 #include <shogun/classifier/vw/vw_common.h> 00023 00024 namespace shogun 00025 { 00026 00029 enum EVwCacheType 00030 { 00031 C_NATIVE = 0, 00032 C_PROTOBUF = 1 00033 }; 00034 00043 class CVwCacheReader: public CSGObject 00044 { 00045 public: 00049 CVwCacheReader(); 00050 00057 CVwCacheReader(char * fname, CVwEnvironment* env_to_use); 00058 00066 CVwCacheReader(int32_t f, CVwEnvironment* env_to_use); 00067 00071 virtual ~CVwCacheReader(); 00072 00078 virtual void set_file(int32_t f); 00079 00085 virtual void set_env(CVwEnvironment* env_to_use); 00086 00092 virtual CVwEnvironment* get_env(); 00093 00099 virtual void set_mm(float64_t label) 00100 { 00101 env->min_label = CMath::min(env->min_label, label); 00102 if (label != FLT_MAX) 00103 env->max_label = CMath::max(env->max_label, label); 00104 } 00105 00112 virtual void noop_mm(float64_t label) { } 00113 00120 virtual void set_minmax(float64_t label) 00121 { 00122 set_mm(label); 00123 } 00124 00130 virtual bool read_cached_example(VwExample* const ae) = 0; 00131 00137 virtual const char* get_name() const { return "VwCacheReader"; } 00138 00139 protected: 00141 int32_t fd; 00142 00144 CVwEnvironment* env; 00145 }; 00146 00147 } 00148 #endif // _VW_CACHEREAD_H__