Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <shogun/features/SubsetStack.h>
00011 #include <shogun/io/SGIO.h>
00012 #include <shogun/base/Parameter.h>
00013
00014 using namespace shogun;
00015
00016 CSubsetStack::CSubsetStack()
00017 {
00018 init();
00019 }
00020
00021 CSubsetStack::CSubsetStack(const CSubsetStack& other)
00022 {
00023 init();
00024
00025 for (int32_t i=0; i < other.m_active_subsets_stack->get_num_elements(); ++i)
00026 {
00027 m_active_subset=(CSubset*)other.m_active_subsets_stack->get_element(i);
00028 m_active_subsets_stack->append_element(m_active_subset);
00029 }
00030 }
00031
00032 CSubsetStack::~CSubsetStack()
00033 {
00034 SG_UNREF(m_active_subsets_stack);
00035 SG_UNREF(m_active_subset);
00036 }
00037
00038 void CSubsetStack::remove_all_subsets()
00039 {
00040
00041 for (index_t i=m_active_subsets_stack->get_num_elements()-1; i>=0; --i)
00042 m_active_subsets_stack->delete_element(i);
00043
00044 SG_UNREF(m_active_subset);
00045 }
00046
00047 void CSubsetStack::init()
00048 {
00049 SG_ADD((CSGObject**)&m_active_subset, "active_subset",
00050 "Currently active subset", MS_NOT_AVAILABLE);
00051 SG_ADD((CSGObject**)&m_active_subsets_stack, "active_subsets_stack",
00052 "Stack of active subsets", MS_NOT_AVAILABLE);
00053
00054 m_active_subset=NULL;
00055 m_active_subsets_stack=new CDynamicObjectArray();
00056 SG_REF(m_active_subsets_stack);
00057 }
00058
00059 void CSubsetStack::add_subset(SGVector<index_t> subset)
00060 {
00061
00062 if (m_active_subsets_stack->get_num_elements())
00063 {
00064
00065 CSubset* latest=(CSubset*)m_active_subsets_stack->get_last_element();
00066 if (subset.vlen>latest->m_subset_idx.vlen)
00067 {
00068 subset.display_vector("subset");
00069 latest->m_subset_idx.display_vector("last on stack");
00070 SG_ERROR("%s::add_subset(): Provided index vector is "
00071 "larger than the subsets on the stubset stack!\n", get_name());
00072 }
00073
00074
00075 index_t max_index=SGVector<index_t>::max(subset.vector, subset.vlen);
00076 if (max_index>=latest->m_subset_idx.vlen)
00077 {
00078 subset.display_vector("subset");
00079 latest->m_subset_idx.display_vector("last on stack");
00080 SG_ERROR("%s::add_subset(): Provided index vector contains"
00081 " indices larger than possible range!\n", get_name());
00082 }
00083
00084
00085 SG_UNREF(latest);
00086 }
00087
00088
00089 SG_UNREF(m_active_subset);
00090
00091
00092 if (m_active_subsets_stack->get_num_elements())
00093 {
00094
00095
00096
00097
00098 CSubset* latest=(CSubset*)m_active_subsets_stack->get_last_element();
00099
00100
00101 SGVector<index_t> new_active_subset=SGVector<index_t>(subset.vlen);
00102
00103
00104
00105 for (index_t i=0; i<subset.vlen; ++i)
00106 {
00107 new_active_subset.vector[i]=
00108 latest->m_subset_idx.vector[subset.vector[i]];
00109 }
00110
00111
00112 m_active_subset=new CSubset(new_active_subset);
00113 SG_REF(m_active_subset);
00114 SG_UNREF(latest);
00115 }
00116 else
00117 {
00118
00119 m_active_subset=new CSubset(subset);
00120 SG_REF(m_active_subset);
00121 }
00122
00123
00124 m_active_subsets_stack->append_element(m_active_subset);
00125 }
00126
00127 void CSubsetStack::remove_subset()
00128 {
00129 index_t num_subsets=m_active_subsets_stack->get_num_elements();
00130 if (num_subsets)
00131 {
00132
00133 SG_UNREF(m_active_subset);
00134 m_active_subset=NULL;
00135
00136
00137 if (num_subsets>=1)
00138 {
00139 index_t last_idx=m_active_subsets_stack->get_num_elements()-1;
00140 m_active_subsets_stack->delete_element(last_idx);
00141 }
00142
00143
00144 if (num_subsets>1)
00145 {
00146
00147 index_t last_idx=m_active_subsets_stack->get_num_elements()-1;
00148 m_active_subset=(CSubset*)
00149 m_active_subsets_stack->get_element(last_idx);
00150 }
00151
00152
00153 }
00154 else
00155 {
00156 SG_WARNING("%s::remove_subset() was called but there is no subset set."
00157 "\n", get_name());
00158 }
00159 }