Created
January 14, 2014 11:33
-
-
Save Saurabh7/8416913 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/shogun/evaluation/CrossValidation.cpp b/src/shogun/evaluation/CrossValidation.cpp | |
index 04a3d51..6b48aa2 100644 | |
--- a/src/shogun/evaluation/CrossValidation.cpp | |
+++ b/src/shogun/evaluation/CrossValidation.cpp | |
@@ -291,7 +291,7 @@ float64_t CCrossValidation::evaluate_one_run() | |
SG_DEBUG("starting unlocked evaluation\n", get_name()) | |
/* tell machine to store model internally | |
* (otherwise changing subset of features will kaboom the classifier) */ | |
- m_machine->set_store_model_features(true); | |
+ //m_machine->set_store_model_features(true); | |
/* do actual cross-validation */ | |
for (index_t i=0; i <num_subsets; ++i) | |
@@ -307,6 +307,11 @@ float64_t CCrossValidation::evaluate_one_run() | |
m_xval_outputs->get_next_element(); | |
} | |
+ /* set feature subset for testing (subset method that stores pointer) */ | |
+ SGVector<index_t> subset_indices = | |
+ m_splitting_strategy->generate_subset_indices(i); | |
+ CFeatures* features_test=m_features->create_view(subset_indices); | |
+ | |
/* set feature subset for training */ | |
SGVector<index_t> inverse_subset_indices= | |
m_splitting_strategy->generate_subset_inverse(i); | |
@@ -344,13 +349,9 @@ float64_t CCrossValidation::evaluate_one_run() | |
m_xval_outputs->get_next_element(); | |
} | |
- m_features->remove_subset(); | |
m_labels->remove_subset(); | |
- /* set feature subset for testing (subset method that stores pointer) */ | |
- SGVector<index_t> subset_indices = | |
- m_splitting_strategy->generate_subset_indices(i); | |
- m_features->add_subset(subset_indices); | |
+ //m_features->add_subset(subset_indices); | |
/* set label subset for testing */ | |
m_labels->add_subset(subset_indices); | |
@@ -364,10 +365,10 @@ float64_t CCrossValidation::evaluate_one_run() | |
/* apply machine to test features and remove subset */ | |
SG_DEBUG("starting evaluation\n") | |
- SG_DEBUG("%p\n", m_features) | |
- CLabels* result_labels=m_machine->apply(m_features); | |
+ SG_DEBUG("%p\n", features_test) | |
+ CLabels* result_labels=m_machine->apply(features_test); | |
SG_DEBUG("finished evaluation\n") | |
- m_features->remove_subset(); | |
+ //m_features->remove_subset(); | |
SG_REF(result_labels); | |
/* evaluate */ | |
@@ -391,6 +392,7 @@ float64_t CCrossValidation::evaluate_one_run() | |
/* clean up, remove subsets */ | |
SG_UNREF(result_labels); | |
m_labels->remove_subset(); | |
+ m_features->remove_subset(); | |
} | |
SG_DEBUG("done unlocked evaluation\n", get_name()) | |
diff --git a/src/shogun/features/DenseFeatures.cpp b/src/shogun/features/DenseFeatures.cpp | |
index fa495d1..ab1d85b 100644 | |
--- a/src/shogun/features/DenseFeatures.cpp | |
+++ b/src/shogun/features/DenseFeatures.cpp | |
@@ -943,6 +943,13 @@ template<class ST> bool CDenseFeatures<ST>::is_equal(CDenseFeatures* rhs) | |
return true; | |
} | |
+template<class ST> CFeatures* CDenseFeatures<ST>::create_view(SGVector<index_t> indices) | |
+{ | |
+ CFeatures* temp_feat=new CDenseFeatures(*this); | |
+ temp_feat->add_subset(indices); | |
+ return temp_feat; | |
+} | |
+ | |
template<class ST> CFeatures* CDenseFeatures<ST>::create_merged_copy( | |
CList* others) | |
{ | |
diff --git a/src/shogun/features/DenseFeatures.h b/src/shogun/features/DenseFeatures.h | |
index beaa604..3da8362 100644 | |
--- a/src/shogun/features/DenseFeatures.h | |
+++ b/src/shogun/features/DenseFeatures.h | |
@@ -502,6 +502,8 @@ public: | |
/** @return object name */ | |
virtual const char* get_name() const { return "DenseFeatures"; } | |
+ virtual CFeatures* create_view(SGVector<index_t> indices); | |
+ | |
protected: | |
/** compute feature vector for sample num | |
* if target is set the vector is written to target | |
diff --git a/src/shogun/features/Features.cpp b/src/shogun/features/Features.cpp | |
index 927b2b5..3072c99 100644 | |
--- a/src/shogun/features/Features.cpp | |
+++ b/src/shogun/features/Features.cpp | |
@@ -334,3 +334,7 @@ CFeatures* CFeatures::copy_subset(SGVector<index_t> indices) | |
"not yet implemented yet. Ask developers!\n", get_name()); | |
return NULL; | |
} | |
+ | |
+CFeatures* CFeatures::create_view(SGVector<index_t> indices) | |
+{ | |
+} | |
diff --git a/src/shogun/features/Features.h b/src/shogun/features/Features.h | |
index 0dd0a11..9c4a7d3 100644 | |
--- a/src/shogun/features/Features.h | |
+++ b/src/shogun/features/Features.h | |
@@ -280,6 +280,10 @@ class CFeatures : public CSGObject | |
* @return new CFeatures instance with copies of feature data | |
*/ | |
virtual CFeatures* copy_subset(SGVector<index_t> indices); | |
+ | |
+ /*create view on features | |
+ *NOT IMPLEMENTED*/ | |
+ virtual CFeatures* create_view(SGVector<index_t> indices); | |
private: | |
void init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment