Commit 4fe77ac9 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Fix Classification errors

SVM used the wrong index array
LPWrapper need to shift by nrow not len(inds)
parent 71032681
......@@ -130,7 +130,6 @@ double ConvexHull1D::overlap_1d(double* value, double width)
);
}
}
// Calculate the score for the feature
for(int tt = 0; tt < _n_task; ++tt)
{
......
......@@ -77,7 +77,7 @@ public:
*
* @returns The projection score for the particular feature
*/
double overlap_1d(double* value, double width = 0.0);
double overlap_1d(double* value, double width = 1e-5);
};
......
......@@ -233,6 +233,7 @@ void LPWrapper::copy_data(const int cls, const std::vector<int> inds)
}
int n_copied = 0;
_n_pts_check = 0;
for(int cc = 0; cc < _n_class; ++cc)
{
if(cc == cls)
......@@ -244,9 +245,9 @@ void LPWrapper::copy_data(const int cls, const std::vector<int> inds)
dcopy_(_n_row_per_class[cc], prop_sorted_d_mat::access_sorted_d_matrix(inds[ii], _task_num, cc), 1, &_row_lower[n_copied + ii], _n_row);
dcopy_(_n_row_per_class[cc], prop_sorted_d_mat::access_sorted_d_matrix(inds[ii], _task_num, cc), 1, &_row_upper[n_copied + ii], _n_row);
}
n_copied += _n_row_per_class[cc] * inds.size();
n_copied += _n_row_per_class[cc] * _n_row;
_n_pts_check += _n_row_per_class[cc];
}
_n_pts_check = n_copied / inds.size();
_simplex.loadProblem(
_n_col,
......@@ -280,6 +281,8 @@ void LPWrapper::copy_data(const int cls, const std::vector<double*> val_ptrs, co
int n_copied = 0;
int n_copied_test = 0;
_n_pts_check = 0;
_n_pts_check_test = 0;
for(int cc = 0; cc < _n_class; ++cc)
{
if(cc == cls)
......@@ -306,7 +309,8 @@ void LPWrapper::copy_data(const int cls, const std::vector<double*> val_ptrs, co
_n_row
);
}
n_copied += _n_row_per_class[cc] * val_ptrs.size();
n_copied += _n_row_per_class[cc] * _n_row;
_n_pts_check += _n_row_per_class[cc];
for(int ii = 0; ii < test_val_ptrs.size(); ++ii)
{
......@@ -325,10 +329,9 @@ void LPWrapper::copy_data(const int cls, const std::vector<double*> val_ptrs, co
_n_row
);
}
n_copied_test += _n_row_per_class_test[cc] * test_val_ptrs.size();
n_copied_test += _n_row_per_class_test[cc] * _n_row;
_n_pts_check_test += _n_row_per_class_test[cc];
}
_n_pts_check = n_copied / val_ptrs.size();
_n_pts_check_test = n_copied_test / test_val_ptrs.size();
_simplex.loadProblem(
_n_col,
......
......@@ -166,15 +166,15 @@ void SVMWrapper::copy_data(const std::vector<int> inds, const int task)
for(int ii = 0; ii < inds.size(); ++ii)
{
double* val_ptr = prop_sorted_d_mat::access_sorted_d_matrix(inds[ii], task, 0);
double* val_ptr = node_value_arrs::get_d_matrix_ptr(inds[ii], task);
_b_remap[ii] = *std::min_element(val_ptr, val_ptr +_n_samp);
_w_remap[ii] = 1.0 / *std::max_element(val_ptr, val_ptr +_n_samp);
_w_remap[ii] = 1.0 / (*std::max_element(val_ptr, val_ptr +_n_samp) - _b_remap[ii]);
for(auto el : _x)
{
el[ii].index = ii;
el[ii].value = ((*val_ptr) - _b_remap[ii]) * _w_remap[ii];
el[ii].value = (*val_ptr - _b_remap[ii]) * _w_remap[ii];
++val_ptr;
}
}
......@@ -192,7 +192,7 @@ void SVMWrapper::copy_data(const std::vector<double*> val_ptrs)
double* val_ptr = val_ptrs[ii];
_b_remap[ii] = *std::min_element(val_ptr, val_ptr +_n_samp);
_w_remap[ii] = 1.0 / *std::max_element(val_ptr, val_ptr +_n_samp);
_w_remap[ii] = 1.0 / (*std::max_element(val_ptr, val_ptr +_n_samp) - _b_remap[ii]);
for(auto el : _x)
{
......
......@@ -27,6 +27,7 @@
#include "classification/prop_sorted_d_mat.hpp"
#include "external/libsvm/svm.h"
#include "feature_creation/node/value_storage/nodes_value_containers.hpp"
// DocString: cls_svm_wrapper
/**
......
......@@ -233,8 +233,8 @@ void SISSOClassifier::l0_regularization(const int n_dim)
{
if(
(min_n_convex_overlap_private[ee] < min_n_convex_overlap[max_error_ind]) ||
(min_svm_score_private[ee] < min_svm_score[max_error_ind]) ||
((min_svm_score_private[ee] == min_svm_score[max_error_ind]) && (min_svm_margin_private[ee] > min_svm_margin[max_error_ind]))
((min_n_convex_overlap_private[ee] == min_n_convex_overlap[max_error_ind]) && (min_svm_score_private[ee] < min_svm_score[max_error_ind])) ||
((min_n_convex_overlap_private[ee] == min_n_convex_overlap[max_error_ind]) && (min_svm_score_private[ee] == min_svm_score[max_error_ind]) && (min_svm_margin_private[ee] > min_svm_margin[max_error_ind]))
)
{
min_n_convex_overlap[max_error_ind] = min_n_convex_overlap_private[ee];
......
......@@ -36,6 +36,7 @@ std::vector<int> node_value_arrs::TEMP_STORAGE_REG;
std::vector<int> node_value_arrs::TEMP_STORAGE_TEST_REG;
std::vector<int> node_value_arrs::TASK_SZ_TRAIN;
std::vector<int> node_value_arrs::TASK_START_TRAIN;
std::vector<int> node_value_arrs::TASK_SZ_TEST;
std::vector<double> node_value_arrs::PARAM_STORAGE_ARR;
......@@ -68,6 +69,7 @@ void node_value_arrs::initialize_values_arr(
if(set_task_sz)
{
TASK_SZ_TRAIN = {n_samples};
TASK_START_TRAIN = {0};
TASK_SZ_TEST = {n_samples_test};
}
......@@ -104,6 +106,8 @@ void node_value_arrs::initialize_values_arr(
{
TASK_SZ_TRAIN = task_sz_train;
TASK_SZ_TEST = task_sz_test;
TASK_START_TRAIN = std::vector<int>(TASK_SZ_TRAIN.size(), 0);
std::copy_n(TASK_SZ_TRAIN.begin(), TASK_SZ_TRAIN.size() - 1, &TASK_START_TRAIN[1]);
initialize_values_arr(
std::accumulate(task_sz_train.begin(), task_sz_train.end(), 0),
......@@ -130,6 +134,7 @@ void node_value_arrs::set_task_sz_train(const std::vector<int> task_sz_train)
throw std::logic_error("The total number of samples has changed, task_sz_train is wrong.");
}
TASK_SZ_TRAIN = task_sz_train;
std::copy_n(TASK_SZ_TRAIN.begin(), TASK_SZ_TRAIN.size() - 1, &TASK_START_TRAIN[1]);
}
void node_value_arrs::set_task_sz_test(const std::vector<int> task_sz_test)
......
......@@ -55,6 +55,7 @@ namespace node_value_arrs
extern std::vector<double> D_MATRIX; //!< The descriptor matrix (Central storage for the selected feature space)
extern std::vector<int> TASK_SZ_TRAIN; //!< Number of training samples per task
extern std::vector<int> TASK_START_TRAIN; //!< The starting point for each task in the training data
extern std::vector<int> TASK_SZ_TEST; //!< Number of test sample per task
extern int N_SELECTED; //!< Number of selected features
......@@ -385,6 +386,15 @@ namespace node_value_arrs
*/
inline double* get_d_matrix_ptr(const int ind){return &D_MATRIX[ind * N_SAMPLES];}
/**
* @brief Get the pointer to a particular selected Node from sis
*
* @param ind Index of the data in the descriptor matrix
* @param taskind The index for the given task
* @return The pointer to the descriptor matrix's data
*/
inline double* get_d_matrix_ptr(const int ind, const int taskind){return &D_MATRIX[ind * N_SAMPLES + TASK_START_TRAIN[taskind]];}
/**
* @brief Flush the temporary storage register (training data)
* @details Reset all slots in the register to -1
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment