SHOGUN  6.1.3
SGObject.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 2008-2009 Soeren Sonnenburg
8  * Written (W) 2011-2013 Heiko Strathmann
9  * Written (W) 2013-2014 Thoralf Klein
10  * Copyright (C) 2008-2009 Fraunhofer Institute FIRST and Max Planck Society
11  */
12 
13 #include <shogun/lib/config.h>
14 #include <shogun/lib/memory.h>
15 #include <shogun/lib/RefCount.h>
16 
17 #include <shogun/base/DynArray.h>
18 #include <shogun/base/Parameter.h>
19 #include <shogun/base/SGObject.h>
20 #include <shogun/base/Version.h>
22 #include <shogun/lib/Map.h>
24 #include <shogun/lib/SGVector.h>
26 
27 #include <shogun/base/class_list.h>
28 
29 #include <stdlib.h>
30 #include <stdio.h>
31 
32 #include <rxcpp/operators/rx-filter.hpp>
33 #include <rxcpp/rx-lite.hpp>
34 
35 #include <unordered_map>
36 
37 namespace shogun
38 {
39  typedef std::map<BaseTag, Any> ParametersMap;
40  typedef std::unordered_map<std::string,
41  std::pair<SG_OBS_VALUE_TYPE, std::string>>
43 
45  {
46  public:
47  void set(const BaseTag& tag, const Any& any)
48  {
49  map[tag] = any;
50  }
51 
52  Any get(const BaseTag& tag) const
53  {
54  if(!has(tag))
55  return Any();
56  return map.at(tag);
57  }
58 
59  bool has(const BaseTag& tag) const
60  {
61  return map.find(tag) != map.end();
62  }
63 
64  ParametersMap map;
65  };
66 
67  class Parallel;
68 
69  extern Parallel* sg_parallel;
70  extern SGIO* sg_io;
71  extern Version* sg_version;
72 
73  template<> void CSGObject::set_generic<bool>()
74  {
75  m_generic = PT_BOOL;
76  }
77 
78  template<> void CSGObject::set_generic<char>()
79  {
80  m_generic = PT_CHAR;
81  }
82 
83  template<> void CSGObject::set_generic<int8_t>()
84  {
85  m_generic = PT_INT8;
86  }
87 
88  template<> void CSGObject::set_generic<uint8_t>()
89  {
90  m_generic = PT_UINT8;
91  }
92 
93  template<> void CSGObject::set_generic<int16_t>()
94  {
95  m_generic = PT_INT16;
96  }
97 
98  template<> void CSGObject::set_generic<uint16_t>()
99  {
100  m_generic = PT_UINT16;
101  }
102 
103  template<> void CSGObject::set_generic<int32_t>()
104  {
105  m_generic = PT_INT32;
106  }
107 
108  template<> void CSGObject::set_generic<uint32_t>()
109  {
110  m_generic = PT_UINT32;
111  }
112 
113  template<> void CSGObject::set_generic<int64_t>()
114  {
115  m_generic = PT_INT64;
116  }
117 
118  template<> void CSGObject::set_generic<uint64_t>()
119  {
120  m_generic = PT_UINT64;
121  }
122 
123  template<> void CSGObject::set_generic<float32_t>()
124  {
125  m_generic = PT_FLOAT32;
126  }
127 
128  template<> void CSGObject::set_generic<float64_t>()
129  {
130  m_generic = PT_FLOAT64;
131  }
132 
133  template<> void CSGObject::set_generic<floatmax_t>()
134  {
135  m_generic = PT_FLOATMAX;
136  }
137 
138  template<> void CSGObject::set_generic<CSGObject*>()
139  {
140  m_generic = PT_SGOBJECT;
141  }
142 
143  template<> void CSGObject::set_generic<complex128_t>()
144  {
145  m_generic = PT_COMPLEX128;
146  }
147 
148 } /* namespace shogun */
149 
150 using namespace shogun;
151 
152 CSGObject::CSGObject() : self(), param_obs_list()
153 {
154  init();
155  set_global_objects();
156  m_refcount = new RefCount(0);
157 
158  SG_SGCDEBUG("SGObject created (%p)\n", this)
159 }
160 
162  : self(), param_obs_list(), io(orig.io), parallel(orig.parallel),
163  version(orig.version)
164 {
165  init();
166  set_global_objects();
167  m_refcount = new RefCount(0);
168 
169  SG_SGCDEBUG("SGObject copied (%p)\n", this)
170 }
171 
173 {
174  SG_SGCDEBUG("SGObject destroyed (%p)\n", this)
175 
176  unset_global_objects();
177  delete m_parameters;
179  delete m_gradient_parameters;
180  delete m_refcount;
181  delete m_subject_params;
182  delete m_observable_params;
183  delete m_subscriber_params;
184 }
185 
186 int32_t CSGObject::ref()
187 {
188  int32_t count = m_refcount->ref();
189  SG_SGCDEBUG("ref() refcount %ld obj %s (%p) increased\n", count, this->get_name(), this)
190  return m_refcount->ref_count();
191 }
192 
194 {
195  int32_t count = m_refcount->ref_count();
196  SG_SGCDEBUG("ref_count(): refcount %d, obj %s (%p)\n", count, this->get_name(), this)
197  return m_refcount->ref_count();
198 }
199 
201 {
202  int32_t count = m_refcount->unref();
203  if (count<=0)
204  {
205  SG_SGCDEBUG("unref() refcount %ld, obj %s (%p) destroying\n", count, this->get_name(), this)
206  delete this;
207  return 0;
208  }
209  else
210  {
211  SG_SGCDEBUG("unref() refcount %ld obj %s (%p) decreased\n", count, this->get_name(), this)
212  return m_refcount->ref_count();
213  }
214 }
215 
216 #ifdef TRACE_MEMORY_ALLOCS
217 #include <shogun/lib/Map.h>
218 extern CMap<void*, shogun::MemoryBlock>* sg_mallocs;
219 
220 void CSGObject::list_memory_allocs()
221 {
222  shogun::list_memory_allocs();
223 }
224 #endif
225 
227 {
229  return NULL;
230 }
231 
233 {
235  return NULL;
236 }
237 
238 void CSGObject::set_global_objects()
239 {
240  if (!sg_io || !sg_parallel || !sg_version)
241  {
242  fprintf(stderr, "call init_shogun() before using the library, dying.\n");
243  exit(1);
244  }
245 
246  SG_REF(sg_io);
249 
250  io=sg_io;
253 }
254 
255 void CSGObject::unset_global_objects()
256 {
257  SG_UNREF(version);
259  SG_UNREF(io);
260 }
261 
263 {
264  SG_REF(new_io);
265  SG_UNREF(sg_io);
266  sg_io=new_io;
267 }
268 
270 {
271  SG_REF(sg_io);
272  return sg_io;
273 }
274 
276 {
277  SG_REF(new_parallel);
279  sg_parallel=new_parallel;
280 }
281 
283 {
284  SG_DEBUG("entering\n")
285 
286  uint32_t carry=0;
287  uint32_t length=0;
288 
289  m_hash=0;
290  get_parameter_incremental_hash(m_hash, carry, length);
292 
293  SG_DEBUG("leaving\n")
294 }
295 
297 {
298  SG_DEBUG("entering\n")
299 
300  uint32_t hash=0;
301  uint32_t carry=0;
302  uint32_t length=0;
303 
304  get_parameter_incremental_hash(hash, carry, length);
305  hash=CHash::FinalizeIncrementalMurmurHash3(hash, carry, length);
306 
307  SG_DEBUG("leaving\n")
308  return (m_hash!=hash);
309 }
310 
312 {
314  return sg_parallel;
315 }
316 
318 {
319  SG_REF(new_version);
321  sg_version=new_version;
322 }
323 
325 {
327  return sg_version;
328 }
329 
330 bool CSGObject::is_generic(EPrimitiveType* generic) const
331 {
332  *generic = m_generic;
333 
334  return m_generic != PT_NOT_GENERIC;
335 }
336 
338 {
339  m_generic = PT_NOT_GENERIC;
340 }
341 
342 void CSGObject::print_serializable(const char* prefix)
343 {
344  SG_PRINT("\n%s\n================================================================================\n", get_name())
345  m_parameters->print(prefix);
346 }
347 
349  const char* prefix)
350 {
351  SG_DEBUG("START SAVING CSGObject '%s'\n", get_name())
352  try
353  {
355  }
356  catch (ShogunException& e)
357  {
358  SG_SWARNING("%s%s::save_serializable_pre(): ShogunException: "
359  "%s\n", prefix, get_name(),
361  return false;
362  }
363 
364  if (!m_save_pre_called)
365  {
366  SG_SWARNING("%s%s::save_serializable_pre(): Implementation "
367  "error: BASE_CLASS::SAVE_SERIALIZABLE_PRE() not "
368  "called!\n", prefix, get_name());
369  return false;
370  }
371 
372  if (!m_parameters->save(file, prefix))
373  return false;
374 
375  try
376  {
378  }
379  catch (ShogunException& e)
380  {
381  SG_SWARNING("%s%s::save_serializable_post(): ShogunException: "
382  "%s\n", prefix, get_name(),
384  return false;
385  }
386 
387  if (!m_save_post_called)
388  {
389  SG_SWARNING("%s%s::save_serializable_post(): Implementation "
390  "error: BASE_CLASS::SAVE_SERIALIZABLE_POST() not "
391  "called!\n", prefix, get_name());
392  return false;
393  }
394 
395  if (prefix == NULL || *prefix == '\0')
396  file->close();
397 
398  SG_DEBUG("DONE SAVING CSGObject '%s' (%p)\n", get_name(), this)
399 
400  return true;
401 }
402 
404  const char* prefix)
405 {
406  REQUIRE(file != NULL, "Serializable file object should be != NULL\n");
407 
408  SG_DEBUG("START LOADING CSGObject '%s'\n", get_name())
409  try
410  {
412  }
413  catch (ShogunException& e)
414  {
415  SG_SWARNING("%s%s::load_serializable_pre(): ShogunException: "
416  "%s\n", prefix, get_name(),
418  return false;
419  }
420  if (!m_load_pre_called)
421  {
422  SG_SWARNING("%s%s::load_serializable_pre(): Implementation "
423  "error: BASE_CLASS::LOAD_SERIALIZABLE_PRE() not "
424  "called!\n", prefix, get_name());
425  return false;
426  }
427 
428  if (!m_parameters->load(file, prefix))
429  return false;
430 
431  try
432  {
434  }
435  catch (ShogunException& e)
436  {
437  SG_SWARNING("%s%s::load_serializable_post(): ShogunException: "
438  "%s\n", prefix, get_name(),
440  return false;
441  }
442 
443  if (!m_load_post_called)
444  {
445  SG_SWARNING("%s%s::load_serializable_post(): Implementation "
446  "error: BASE_CLASS::LOAD_SERIALIZABLE_POST() not "
447  "called!\n", prefix, get_name());
448  return false;
449  }
450  SG_DEBUG("DONE LOADING CSGObject '%s' (%p)\n", get_name(), this)
451 
452  return true;
453 }
454 
456 {
457  m_load_pre_called = true;
458 }
459 
461 {
462  m_load_post_called = true;
463 }
464 
466 {
467  m_save_pre_called = true;
468 }
469 
471 {
472  m_save_post_called = true;
473 }
474 
475 #ifdef TRACE_MEMORY_ALLOCS
476 #include <shogun/lib/Map.h>
477 extern CMap<void*, shogun::MemoryBlock>* sg_mallocs;
478 #endif
479 
480 void CSGObject::init()
481 {
482 #ifdef TRACE_MEMORY_ALLOCS
483  if (sg_mallocs)
484  {
485  int32_t idx=sg_mallocs->index_of(this);
486  if (idx>-1)
487  {
488  MemoryBlock* b=sg_mallocs->get_element_ptr(idx);
489  b->set_sgobject();
490  }
491  }
492 #endif
493 
494  io = NULL;
495  parallel = NULL;
496  version = NULL;
497  m_parameters = new Parameter();
500  m_generic = PT_NOT_GENERIC;
501  m_load_pre_called = false;
502  m_load_post_called = false;
503  m_save_pre_called = false;
504  m_save_post_called = false;
505  m_hash = 0;
506 
507  m_subject_params = new SGSubject();
508  m_observable_params = new SGObservable(m_subject_params->get_observable());
509  m_subscriber_params = new SGSubscriber(m_subject_params->get_subscriber());
510 }
511 
513 {
514  SG_PRINT("parameters available for model selection for %s:\n", get_name())
515 
517 
518  if (!num_param)
519  SG_PRINT("\tnone\n")
520 
521  for (index_t i=0; i<num_param; i++)
522  {
524  index_t l=200;
525  char* type=SG_MALLOC(char, l);
526  if (type)
527  {
528  current->m_datatype.to_string(type, l);
529  SG_PRINT("\t%s (%s): %s\n", current->m_name, current->m_description,
530  type);
531  SG_FREE(type);
532  }
533  }
534 }
535 
537 {
539 
540  SGStringList<char> result(num_param, -1);
541 
542  index_t max_string_length=-1;
543 
544  for (index_t i=0; i<num_param; i++)
545  {
547  index_t len=strlen(name);
548  // +1 to have a zero terminated string
549  result.strings[i]=SGString<char>(name, len+1);
550 
551  if (len>max_string_length)
552  max_string_length=len;
553  }
554 
555  result.max_string_length=max_string_length;
556 
557  return result;
558 }
559 
560 char* CSGObject::get_modsel_param_descr(const char* param_name)
561 {
562  index_t index=get_modsel_param_index(param_name);
563 
564  if (index<0)
565  {
566  SG_ERROR("There is no model selection parameter called \"%s\" for %s",
567  param_name, get_name());
568  }
569 
571 }
572 
574 {
575  /* use fact that names extracted from below method are in same order than
576  * in m_model_selection_parameters variable */
578 
579  /* search for parameter with provided name */
580  index_t index=-1;
581  for (index_t i=0; i<names.num_strings; i++)
582  {
584  if (!strcmp(param_name, current->m_name))
585  {
586  index=i;
587  break;
588  }
589  }
590 
591  return index;
592 }
593 
594 void CSGObject::get_parameter_incremental_hash(uint32_t& hash, uint32_t& carry,
595  uint32_t& total_length)
596 {
597  for (index_t i=0; i<m_parameters->get_num_parameters(); i++)
598  {
600 
601  SG_DEBUG("Updating hash for parameter %s.%s\n", get_name(), p->m_name);
602 
603  if (p->m_datatype.m_ptype == PT_SGOBJECT)
604  {
605  if (p->m_datatype.m_ctype == CT_SCALAR)
606  {
607  CSGObject* child = *((CSGObject**)(p->m_parameter));
608 
609  if (child)
610  {
611  child->get_parameter_incremental_hash(hash, carry,
612  total_length);
613  }
614  }
615  else if (p->m_datatype.m_ctype==CT_VECTOR ||
616  p->m_datatype.m_ctype==CT_SGVECTOR)
617  {
618  CSGObject** child=(*(CSGObject***)(p->m_parameter));
619 
620  for (index_t j=0; j<*(p->m_datatype.m_length_y); j++)
621  {
622  if (child[j])
623  {
624  child[j]->get_parameter_incremental_hash(hash, carry,
625  total_length);
626  }
627  }
628  }
629  }
630  else
631  p->get_incremental_hash(hash, carry, total_length);
632  }
633 }
634 
636 {
638  {
640  dict->add(p, this);
641  }
642 
644  {
646  CSGObject* child=*(CSGObject**)(p->m_parameter);
647 
648  if ((p->m_datatype.m_ptype == PT_SGOBJECT) &&
649  (p->m_datatype.m_ctype == CT_SCALAR) && child)
650  {
652  }
653  }
654 }
655 
656 bool CSGObject::equals(CSGObject* other, float64_t accuracy, bool tolerant)
657 {
658  SG_DEBUG("entering %s::equals()\n", get_name());
659 
660  if (other==this)
661  {
662  SG_DEBUG("leaving %s::equals(): other object is me\n", get_name());
663  return true;
664  }
665 
666  if (!other)
667  {
668  SG_DEBUG("leaving %s::equals(): other object is NULL\n", get_name());
669  return false;
670  }
671 
672  SG_DEBUG("comparing \"%s\" to \"%s\"\n", get_name(), other->get_name());
673 
674  /* a crude type check based on the get_name */
675  if (strcmp(other->get_name(), get_name()))
676  {
677  SG_INFO("leaving %s::equals(): name of other object differs\n", get_name());
678  return false;
679  }
680 
681  /* should not be necessary but just ot be sure that type has not changed.
682  * Will assume that parameters are in same order with same name from here */
684  {
685  SG_INFO("leaving %s::equals(): number of parameters of other object "
686  "differs\n", get_name());
687  return false;
688  }
689 
690  for (index_t i=0; i<m_parameters->get_num_parameters(); ++i)
691  {
692  SG_DEBUG("comparing parameter %d\n", i);
693 
694  TParameter* this_param=m_parameters->get_parameter(i);
695  TParameter* other_param=other->m_parameters->get_parameter(i);
696 
697  /* some checks to make sure parameters have same order and names and
698  * are not NULL. Should never be the case but check anyway. */
699  if (!this_param && !other_param)
700  continue;
701 
702  if (!this_param && other_param)
703  {
704  SG_DEBUG("leaving %s::equals(): parameter %d is NULL where other's "
705  "parameter \"%s\" is not\n", get_name(), other_param->m_name);
706  return false;
707  }
708 
709  if (this_param && !other_param)
710  {
711  SG_DEBUG("leaving %s::equals(): parameter %d is \"%s\" where other's "
712  "parameter is NULL\n", get_name(), this_param->m_name);
713  return false;
714  }
715 
716  SG_DEBUG("comparing parameter \"%s\" to other's \"%s\"\n",
717  this_param->m_name, other_param->m_name);
718 
719  /* use equals method of TParameter from here */
720  if (!this_param->equals(other_param, accuracy, tolerant))
721  {
722  SG_INFO("leaving %s::equals(): parameters at position %d with name"
723  " \"%s\" differs from other object parameter with name "
724  "\"%s\"\n",
725  get_name(), i, this_param->m_name, other_param->m_name);
726  return false;
727  }
728  }
729 
730  SG_DEBUG("leaving %s::equals(): object are equal\n", get_name());
731  return true;
732 }
733 
735 {
736  SG_DEBUG("Constructing an empty instance of %s\n", get_name());
737  CSGObject* copy = create(get_name(), this->m_generic);
738 
739  SG_REF(copy);
740 
741  REQUIRE(copy, "Could not create empty instance of \"%s\". The reason for "
742  "this usually is that get_name() of the class returns something "
743  "wrong, or that a class has a wrongly set generic type.\n",
744  get_name());
745 
746  SG_DEBUG("Cloning all parameters of %s\n", get_name());
747  if (!copy->clone_parameters(this))
748  {
749  SG_WARNING("Cloning parameters failed.\n");
750  }
751  else
752  {
753  SG_DEBUG("Done cloning.\n");
754  }
755 
756  return copy;
757 }
758 
760 {
761  REQUIRE(other, "Provided instance must be non-empty.\n");
762  index_t num_parameters = m_parameters->get_num_parameters();
763 
764  REQUIRE(other->m_parameters->get_num_parameters() == num_parameters,
765  "Number of parameters of provided instance (%d) must match this instance (%d).\n",
766  other->m_parameters->get_num_parameters(), num_parameters);
767  REQUIRE(!strcmp(other->get_name(), get_name()),
768  "Name of provided instance (%s) must match this instance (%s).\n",
769  other->get_name(), get_name());
770 
771  for (index_t i=0; i<num_parameters; ++i)
772  {
773  SG_DEBUG("Cloning parameter \"%s\" at index %d into this instance\n",
774  other->m_parameters->get_parameter(i)->m_name, i);
775 
777  {
778  SG_WARNING("Cloning parameter \"%s\" (at index %d) of provided instance %s"
779  " into parameter \"%s\" of this instance %s failed.\n",
780  other->m_parameters->get_parameter(i)->m_name, i,
781  other->get_name(), m_parameters->get_parameter(i)->m_name,
782  get_name());
783  return false;
784  }
785  }
786 
787  return true;
788 }
789 
790 void CSGObject::type_erased_set(const BaseTag& _tag, const Any& any)
791 {
792  self->set(_tag, any);
793 }
794 
795 Any CSGObject::type_erased_get(const BaseTag& _tag) const
796 {
797  Any any = self->get(_tag);
798  if(any.empty())
799  {
800  SG_ERROR("There is no parameter called \"%s\" in %s",
801  _tag.name().c_str(), get_name());
802  }
803  return any;
804 }
805 
806 bool CSGObject::type_erased_has(const BaseTag& _tag) const
807 {
808  return self->has(_tag);
809 }
810 
812 {
813  auto sub = rxcpp::make_subscriber<TimedObservedValue>(
814  [obs](TimedObservedValue e) { obs->on_next(e); },
815  [obs](std::exception_ptr ep) { obs->on_error(ep); },
816  [obs]() { obs->on_complete(); });
817 
818  // Create an observable which emits values only if they are about
819  // parameters selected by the observable.
820  auto subscription = m_observable_params
821  ->filter([obs](ObservedValue v) {
822  return obs->filter(v.get_name());
823  })
824  .timestamp()
825  .subscribe(sub);
826 }
827 
829 {
830  m_subscriber_params->on_next(value);
831 }
832 
834 {
835 public:
837  const std::string& name, const SG_OBS_VALUE_TYPE type,
838  const std::string& description)
839  {
840  m_list_obs_params[name] = std::make_pair(type, description);
841  }
842 
843  std::string type_name(SG_OBS_VALUE_TYPE type)
844  {
845  std::string value;
846  switch (type)
847  {
848  case TENSORBOARD:
849  value = std::string("Tensorboard");
850  break;
851  case CROSSVALIDATION:
852  value = std::string("CrossValidation");
853  break;
854  default:
855  value = std::string("Unknown");
856  break;
857  }
858  return value;
859  }
860 
862  {
863  return m_list_obs_params;
864  }
865 
866 private:
868  ObsParamsList m_list_obs_params;
869 };
870 
872  const std::string& name, const SG_OBS_VALUE_TYPE type,
873  const std::string& description)
874 {
875  param_obs_list->register_param(name, type, description);
876 }
877 
879 {
880  SG_INFO("List of observable parameters of object %s\n", get_name());
881  SG_PRINT("------");
882  for (auto const& x : param_obs_list->get_list())
883  {
884  SG_PRINT(
885  "%s [%s]: %s\n", x.first.c_str(),
886  param_obs_list->type_name(x.second.first).c_str(),
887  x.second.second.c_str());
888  }
889 }
void list_observable_parameters()
Definition: SGObject.cpp:878
virtual const char * get_name() const =0
SGStringList< char > get_modelsel_names()
Definition: SGObject.cpp:536
#define SG_INFO(...)
Definition: SGIO.h:117
Parallel * get_global_parallel()
Definition: SGObject.cpp:311
virtual void update_parameter_hash()
Definition: SGObject.cpp:282
std::pair< ObservedValue, time_point > TimedObservedValue
void register_param(const std::string &name, const SG_OBS_VALUE_TYPE type, const std::string &description)
Definition: SGObject.cpp:836
SGString< T > * strings
Definition: SGStringList.h:88
SG_OBS_VALUE_TYPE
Definition: ObservedValue.h:54
int32_t index_t
Definition: common.h:72
std::string type_name(SG_OBS_VALUE_TYPE type)
Definition: SGObject.cpp:843
virtual int32_t get_num_parameters()
virtual CSGObject * clone()
Definition: SGObject.cpp:734
Base class for all tags. This class stores name and not the type information for a shogun object...
Definition: basetag.h:48
bool clone_parameters(CSGObject *other)
Definition: SGObject.cpp:759
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
virtual CSGObject * shallow_copy() const
Definition: SGObject.cpp:226
#define SG_SWARNING(...)
Definition: SGIO.h:163
void unset_generic()
Definition: SGObject.cpp:337
rxcpp::subjects::subject< ObservedValue > SGSubject
Definition: SGObject.h:127
TParameter * get_parameter(int32_t idx)
Version * get_global_version()
Definition: SGObject.cpp:324
parameter struct
virtual void save_serializable_pre()
Definition: SGObject.cpp:465
CSGObject * create(const char *sgserializable_name, EPrimitiveType generic)
#define SG_ERROR(...)
Definition: SGIO.h:128
#define REQUIRE(x,...)
Definition: SGIO.h:181
virtual bool is_generic(EPrimitiveType *generic) const
Definition: SGObject.cpp:330
#define SG_NOTIMPLEMENTED
Definition: SGIO.h:138
Allows to store objects of arbitrary types by using a BaseAnyPolicy and provides a type agnostic API...
Definition: any.h:290
Parameter * m_parameters
Definition: SGObject.h:609
virtual bool load_serializable(CSerializableFile *file, const char *prefix="")
Definition: SGObject.cpp:403
virtual void print(const char *prefix="")
Definition: Parameter.cpp:2763
static uint32_t FinalizeIncrementalMurmurHash3(uint32_t h, uint32_t carry, uint32_t total_length)
Definition: Hash.cpp:376
SG_FORCED_INLINE int32_t ref()
Definition: RefCount.h:26
void observe(const ObservedValue value)
Definition: SGObject.cpp:828
Parallel * parallel
Definition: SGObject.h:603
#define SG_REF(x)
Definition: SGObject.h:52
virtual bool load(CSerializableFile *file, const char *prefix="")
Definition: Parameter.cpp:2782
Version * sg_version
Definition: init.cpp:45
std::map< BaseTag, Any > ParametersMap
Definition: SGObject.cpp:39
std::string name() const
Definition: basetag.h:79
char * get_modsel_param_descr(const char *param_name)
Definition: SGObject.cpp:560
bool has(const BaseTag &tag) const
Definition: SGObject.cpp:59
bool equals(TParameter *other, float64_t accuracy=0.0, bool tolerant=false)
Definition: Parameter.cpp:2963
TSGDataType m_datatype
#define SG_PRINT(...)
Definition: SGIO.h:136
Parallel * sg_parallel
Definition: init.cpp:43
Parameter class.
Class SGObject is the base class of all shogun objects.
Definition: SGObject.h:124
virtual ~CSGObject()
Definition: SGObject.cpp:172
SGIO * sg_io
Definition: init.cpp:44
void build_gradient_parameter_dictionary(CMap< TParameter *, CSGObject * > *dict)
Definition: SGObject.cpp:635
SG_FORCED_INLINE int32_t unref()
Definition: RefCount.h:35
double float64_t
Definition: common.h:60
void register_observable_param(const std::string &name, const SG_OBS_VALUE_TYPE type, const std::string &description)
Definition: SGObject.cpp:871
Version * version
Definition: SGObject.h:606
virtual bool save(CSerializableFile *file, const char *prefix="")
Definition: Parameter.cpp:2770
the class CMap, a map based on the hash-table. w: http://en.wikipedia.org/wiki/Hash_table ...
Definition: SGObject.h:42
T * get_element_ptr(int32_t index)
Definition: Map.h:232
virtual void save_serializable_post()
Definition: SGObject.cpp:470
void print_modsel_params()
Definition: SGObject.cpp:512
ParametersMap map
Definition: SGObject.cpp:64
Class Version provides version information.
Definition: Version.h:28
Parameter * m_model_selection_parameters
Definition: SGObject.h:612
void get_incremental_hash(uint32_t &hash, uint32_t &carry, uint32_t &total_length)
Definition: Parameter.cpp:2424
virtual bool equals(CSGObject *other, float64_t accuracy=0.0, bool tolerant=false)
Definition: SGObject.cpp:656
index_t * m_length_y
Definition: DataType.h:78
virtual CSGObject * deep_copy() const
Definition: SGObject.cpp:232
void set_global_parallel(Parallel *parallel)
Definition: SGObject.cpp:275
void to_string(char *dest, size_t n) const
Definition: DataType.cpp:145
virtual void load_serializable_pre()
Definition: SGObject.cpp:455
virtual void load_serializable_post()
Definition: SGObject.cpp:460
EContainerType m_ctype
Definition: DataType.h:71
#define SG_UNREF(x)
Definition: SGObject.h:53
Class Parallel provides helper functions for multithreading.
Definition: Parallel.h:27
#define SG_DEBUG(...)
Definition: SGIO.h:106
int32_t index_of(const K &key)
Definition: Map.h:154
virtual bool save_serializable(CSerializableFile *file, const char *prefix="")
Definition: SGObject.cpp:348
const char * get_exception_string()
all of classes and functions are contained in the shogun namespace
Definition: class_list.h:18
int32_t add(const K &key, const T &data)
Definition: Map.h:101
rxcpp::subscriber< ObservedValue, rxcpp::observer< ObservedValue, void, void, void, void > > SGSubscriber
Definition: SGObject.h:133
#define SG_SGCDEBUG(...)
Definition: SGIO.h:148
SGIO * get_global_io()
Definition: SGObject.cpp:269
const std::string & get_name() const
#define PT_NOT_GENERIC
Definition: DataType.h:21
index_t get_modsel_param_index(const char *param_name)
Definition: SGObject.cpp:573
void set_global_io(SGIO *io)
Definition: SGObject.cpp:262
uint32_t m_hash
Definition: SGObject.h:618
bool copy(TParameter *target)
Definition: Parameter.cpp:3771
virtual void on_error(std::exception_ptr)=0
SG_FORCED_INLINE int32_t ref_count()
Definition: RefCount.h:44
int32_t ref_count()
Definition: SGObject.cpp:193
EPrimitiveType m_ptype
Definition: DataType.h:75
#define SG_WARNING(...)
Definition: SGIO.h:127
int32_t unref()
Definition: SGObject.cpp:200
void subscribe_to_parameters(ParameterObserverInterface *obs)
Definition: SGObject.cpp:811
Class SGIO, used to do input output operations throughout shogun.
Definition: SGIO.h:218
virtual bool filter(const std::string &param)
Parameter * m_gradient_parameters
Definition: SGObject.h:615
virtual void on_next(const TimedObservedValue &value)=0
virtual void print_serializable(const char *prefix="")
Definition: SGObject.cpp:342
virtual bool parameter_hash_changed()
Definition: SGObject.cpp:296
bool empty() const
Definition: any.h:389
void set_global_version(Version *version)
Definition: SGObject.cpp:317
std::unordered_map< std::string, std::pair< SG_OBS_VALUE_TYPE, std::string > > ObsParamsList
Definition: SGObject.cpp:42
rxcpp::observable< ObservedValue, rxcpp::dynamic_observable< ObservedValue > > SGObservable
Definition: SGObject.h:130
template class SGStringList
Definition: SGObject.h:46

SHOGUN Machine Learning Toolbox - Documentation