41 template<>
void CSGObject::set_generic<bool>()
46 template<>
void CSGObject::set_generic<char>()
51 template<>
void CSGObject::set_generic<int8_t>()
56 template<>
void CSGObject::set_generic<uint8_t>()
61 template<>
void CSGObject::set_generic<int16_t>()
66 template<>
void CSGObject::set_generic<uint16_t>()
68 m_generic = PT_UINT16;
71 template<>
void CSGObject::set_generic<int32_t>()
76 template<>
void CSGObject::set_generic<uint32_t>()
78 m_generic = PT_UINT32;
81 template<>
void CSGObject::set_generic<int64_t>()
86 template<>
void CSGObject::set_generic<uint64_t>()
88 m_generic = PT_UINT64;
91 template<>
void CSGObject::set_generic<float32_t>()
93 m_generic = PT_FLOAT32;
96 template<>
void CSGObject::set_generic<float64_t>()
98 m_generic = PT_FLOAT64;
101 template<>
void CSGObject::set_generic<floatmax_t>()
103 m_generic = PT_FLOATMAX;
106 template<>
void CSGObject::set_generic<CSGObject*>()
108 m_generic = PT_SGOBJECT;
111 template<>
void CSGObject::set_generic<complex128_t>()
113 m_generic = PT_COMPLEX128;
118 using namespace shogun;
124 set_global_objects();
128 :
SGRefObject(orig), io(orig.io), parallel(orig.parallel), version(orig.version)
131 set_global_objects();
136 unset_global_objects();
143 void CSGObject::set_global_objects()
147 fprintf(stderr,
"call init_shogun() before using the library, dying.\n");
160 void CSGObject::unset_global_objects()
194 get_parameter_incremental_hash(
m_hash, carry, length);
208 get_parameter_incremental_hash(hash, carry, length);
236 *
generic = m_generic;
248 SG_PRINT(
"\n%s\n================================================================================\n",
get_name())
253 const char* prefix, int32_t param_version)
262 SG_SWARNING(
"%s%s::save_serializable_pre(): ShogunException: "
268 if (!m_save_pre_called)
270 SG_SWARNING(
"%s%s::save_serializable_pre(): Implementation "
271 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
277 if (!save_parameter_version(file, prefix, param_version))
289 SG_SWARNING(
"%s%s::save_serializable_post(): ShogunException: "
295 if (!m_save_post_called)
297 SG_SWARNING(
"%s%s::save_serializable_post(): Implementation "
298 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
303 if (prefix == NULL || *prefix ==
'\0')
312 const char* prefix, int32_t param_version)
321 SG_SWARNING(
"%s%s::load_serializable_pre(): ShogunException: "
326 if (!m_load_pre_called)
328 SG_SWARNING(
"%s%s::load_serializable_pre(): Implementation "
329 "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
335 int32_t file_version=load_parameter_version(file, prefix);
336 SG_DEBUG(
"file_version=%d, current_version=%d\n", file_version, param_version)
340 SG_WARNING(
"%s%s::load_serializable(): File contains no parameter "
341 "version. Seems like your file is from the days before this "
342 "was introduced. Ignore warning or serialize with this version "
343 "of shogun to get rid of above and this warnings.\n",
347 if (file_version>param_version)
351 SG_WARNING(
"%s%s::load_serializable(): parameter version of file "
352 "larger than the one of shogun. Try with a more recent"
353 "version of shogun.\n", prefix,
get_name());
357 SG_WARNING(
"%s%s::load_serializable(): parameter version of file "
358 "larger than the current. This is probably an implementation"
364 if (file_version==param_version)
375 if (is_param_new(
SGParamInfo(current, param_version)))
378 if (!current->
load(file, prefix))
386 param_version, file, prefix);
396 if (is_param_new(
SGParamInfo(current, param_version)))
417 SG_DEBUG(
"replacing parameter data by loaded/mapped values\n")
421 char* s=SG_MALLOC(
char, 200);
427 if (is_param_new(
SGParamInfo(current, param_version)))
441 SG_DEBUG(
"copying migrated data into parameter\n")
446 SG_DEBUG(
"deleting old parameter base\n")
462 SG_SWARNING(
"%s%s::load_serializable_post(): ShogunException: "
468 if (!m_load_post_called)
470 SG_SWARNING(
"%s%s::load_serializable_post(): Implementation "
471 "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
481 const SGParamInfo* param_info, int32_t file_version,
488 SG_SERROR(
"parameter version of \"%s\" in file (%d) is more recent than"
489 " provided %d!\n", param_info->
m_name, file_version,
497 SG_SDEBUG(
"try to get mapping for: %s\n", s)
501 bool free_mapped=
false;
512 if (file_version<param_info->m_param_version)
550 SG_SDEBUG(
"recursion stop, loading from file\n")
578 if (!loaded->
load(file, prefix))
581 SG_ERROR(
"Could not load %s. The reason for this might be wrong "
582 "parameter mappings\n", s);
586 SG_DEBUG(
"loaded lengths: y=%d, x=%d\n",
604 SG_SDEBUG(
"starting recursion over %s\n", s)
614 SG_SDEBUG(
"appending all results to current result\n")
619 delete recursion_array;
652 if (is_param_new(*info))
685 SG_DEBUG(
"no target parameter infos\n")
699 SG_DEBUG(
"trying to get parameter mapping for %s\n", s)
720 SG_DEBUG(
"no mapping found, using %s\n", s)
739 if (mapped_version>base_version)
751 ASSERT(base_version==mapped_version)
758 SG_DEBUG(
"migrating one step to target: %s\n", s)
765 SG_DEBUG(
"deleting parameters base version %d\n", base_version)
769 SG_DEBUG(
"replacing old parameter base\n")
770 *param_base=*new_base;
771 base_version=mapped_version+1;
783 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
796 SG_DEBUG(
"(%d:) \"%s\": sgobject \"%s\" at %p\n", i,
804 char* s=SG_MALLOC(
char, 200);
828 SG_DEBUG(
"CSGObject::entering CSGObject::one_to_one_migration_prepare() for "
829 "\"%s\"\n", target->
m_name);
836 char* name=target->
m_name;
873 SG_DEBUG(
"copied and SG_REF sgobject pointer for \"%s\" at %p\n",
880 SG_DEBUG(
"CSGObject::leaving CSGObject::one_to_one_migration_prepare() for "
881 "\"%s\"\n", target->
m_name);
912 SG_ERROR(
"Name change for parameter that has to be mapped to \"%s\","
913 " and to no migration method available\n", target->
m_name);
921 char* s=SG_MALLOC(
char, 200);
923 SG_DEBUG(
"nothing changed, using old data: %s\n", s)
953 SG_DEBUG(
"copying content of poitner for non-scalar data\n")
960 SG_ERROR(
"No migration method available for %s!\n", s)
970 const char* prefix, int32_t param_version)
973 TParameter p(&t, ¶m_version,
"version_parameter",
974 "Version of parameters of this object");
975 return p.save(file, prefix);
983 TParameter tp(&t, &v,
"version_parameter",
"");
984 if (tp.load(file, prefix))
992 m_load_pre_called =
true;
997 m_load_post_called =
true;
1002 m_save_pre_called =
true;
1007 m_save_post_called =
true;
1010 #ifdef TRACE_MEMORY_ALLOCS
1015 void CSGObject::init()
1017 #ifdef TRACE_MEMORY_ALLOCS
1020 int32_t idx=sg_mallocs->
index_of(
this);
1023 MemoryBlock* b=sg_mallocs->get_element_ptr(idx);
1037 m_load_pre_called =
false;
1038 m_load_post_called =
false;
1051 for (
index_t i=0; i<num_param; i++)
1055 char* type=SG_MALLOC(
char, l);
1074 for (
index_t i=0; i<num_param; i++)
1081 if (len>max_string_length)
1082 max_string_length=len;
1096 SG_ERROR(
"There is no model selection parameter called \"%s\" for %s",
1114 if (!strcmp(param_name, current->
m_name))
1124 bool CSGObject::is_param_new(
const SGParamInfo param_info)
const
1133 void CSGObject::get_parameter_incremental_hash(uint32_t& hash, uint32_t& carry,
1134 uint32_t& total_length)
1150 child->get_parameter_incremental_hash(hash, carry,
1163 child[j]->get_parameter_incremental_hash(hash, carry,
1216 SG_INFO(
"leaving %s::equals(): name of other object differs\n",
get_name());
1224 SG_INFO(
"leaving %s::equals(): number of parameters of other object "
1231 SG_DEBUG(
"comparing parameter %d\n", i);
1238 if (!this_param && !other_param)
1241 if (!this_param && other_param)
1243 SG_DEBUG(
"leaving %s::equals(): parameter %d is NULL where other's "
1248 if (this_param && !other_param)
1250 SG_DEBUG(
"leaving %s::equals(): parameter %d is \"%s\" where other's "
1255 SG_DEBUG(
"comparing parameter \"%s\" to other's \"%s\"\n",
1259 if (!strcmp(
"DynamicObjectArray",
get_name()) &&
1260 !strcmp(this_param->
m_name,
"num_elements") &&
1261 !strcmp(other_param->
m_name,
"num_elements"))
1263 SG_DEBUG(
"Ignoring DynamicObjectArray::num_elements field\n");
1268 if (!strcmp(
"DynamicArray",
get_name()) &&
1269 !strcmp(this_param->
m_name,
"num_elements") &&
1270 !strcmp(other_param->
m_name,
"num_elements"))
1272 SG_DEBUG(
"Ignoring DynamicArray::num_elements field\n");
1277 if (!this_param->
equals(other_param, accuracy, tolerant))
1279 SG_INFO(
"leaving %s::equals(): parameters at position %d with name"
1280 " \"%s\" differs from other object parameter with name "
1300 REQUIRE(copy,
"Could not create empty instance of \"%s\". The reason for "
1301 "this usually is that get_name() of the class returns something "
1302 "wrong, or that a class has a wrongly set generic type.\n",
1307 SG_DEBUG(
"cloning parameter \"%s\" at index %d\n",
1312 SG_DEBUG(
"leaving %s::clone(): Clone failed. Returning NULL\n",
virtual const char * get_name() const =0
SGStringList< char > get_modelsel_names()
T get_element(int32_t index) const
Parallel * get_global_parallel()
virtual bool save_serializable(CSerializableFile *file, const char *prefix="", int32_t param_version=Version::get_version_parameter())
virtual void update_parameter_hash()
Class that holds informations about a certain parameter of an CSGObject. Contains name...
Class SGRefObject is a reference count based memory management class.
ParameterMap * m_parameter_map
virtual TParameter * migrate(DynArray< TParameter * > *param_base, const SGParamInfo *target)
bool append_element(T element)
virtual int32_t get_num_parameters()
virtual CSGObject * clone()
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
static int32_t binary_search(T *output, int32_t size, T elem)
TParameter * get_parameter(int32_t idx)
DynArray< const SGParamInfo * > * get(const SGParamInfo) const
Version * get_global_version()
virtual void save_serializable_pre()
virtual bool is_generic(EPrimitiveType *generic) const
virtual void print(const char *prefix="")
static uint32_t FinalizeIncrementalMurmurHash3(uint32_t h, uint32_t carry, uint32_t total_length)
int32_t get_num_elements() const
static int32_t get_version_parameter()
SGParamInfo * duplicate() const
Implements a map of ParameterMapElement instances Maps one key to a set of values.
Datatypes that shogun supports.
static void qsort(T *output, int32_t size)
char * get_modsel_param_descr(const char *param_name)
bool equals(TParameter *other, float64_t accuracy=0.0, bool tolerant=false)
DynArray< TParameter * > * load_file_parameters(const SGParamInfo *param_info, int32_t file_version, CSerializableFile *file, const char *prefix="")
Class SGObject is the base class of all shogun objects.
void build_gradient_parameter_dictionary(CMap< TParameter *, CSGObject * > *dict)
Template Dynamic array class that creates an array that can be used like a list or an array...
virtual bool load_serializable(CSerializableFile *file, const char *prefix="", int32_t param_version=Version::get_version_parameter())
DynArray< TParameter * > * load_all_file_parameters(int32_t file_version, int32_t current_version, CSerializableFile *file, const char *prefix="")
virtual bool save(CSerializableFile *file, const char *prefix="")
index_t max_string_length
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
virtual void save_serializable_post()
void print_modsel_params()
CSGObject * new_sgserializable(const char *sgserializable_name, EPrimitiveType generic)
Class Version provides version information.
Parameter * m_model_selection_parameters
void get_incremental_hash(uint32_t &hash, uint32_t &carry, uint32_t &total_length)
virtual bool equals(CSGObject *other, float64_t accuracy=0.0, bool tolerant=false)
void set_global_parallel(Parallel *parallel)
void to_string(char *dest, size_t n) const
virtual void load_serializable_pre()
virtual void load_serializable_post()
Class Parallel provides helper functions for multithreading.
int32_t index_of(const K &key)
virtual void one_to_one_migration_prepare(DynArray< TParameter * > *param_base, const SGParamInfo *target, TParameter *&replacement, TParameter *&to_migrate, char *old_name=NULL)
const char * get_exception_string()
bool load(CSerializableFile *file, const char *prefix="")
int32_t add(const K &key, const T &data)
void map_parameters(DynArray< TParameter * > *param_base, int32_t &base_version, DynArray< const SGParamInfo * > *target_param_infos)
index_t get_modsel_param_index(const char *param_name)
void set_global_io(SGIO *io)
bool copy(TParameter *target)
void copy_data(const TParameter *source)
Class which collects generic mathematical functions.
Class SGIO, used to do input output operations throughout shogun.
Parameter * m_gradient_parameters
virtual void print_serializable(const char *prefix="")
virtual bool parameter_hash_changed()
void set_global_version(Version *version)
void allocate_data_from_scratch(SGVector< index_t > dims, bool new_cont_call=true)
template class SGStringList