Commit 5e10ae6e authored by Davis King's avatar Davis King

Added more sparse vector tools and fixed a bug.

parent 313bca15
#include <boost/python.hpp>
#include <boost/shared_ptr.hpp>
#include <dlib/matrix.h>
#include <dlib/data_io.h>
#include <dlib/sparse_vector.h>
using namespace dlib;
using namespace std;
using namespace boost::python;
typedef std::vector<std::pair<unsigned long,double> > sparse_vect;
tuple get_training_data()
{
typedef matrix<double,0,1> sample_type;
......@@ -28,8 +32,43 @@ tuple get_training_data()
return make_tuple(samples, labels);
}
void _make_sparse_vector (
sparse_vect& v
)
{
make_sparse_vector_inplace(v);
}
void _make_sparse_vector2 (
std::vector<sparse_vect>& v
)
{
for (unsigned long i = 0; i < v.size(); ++i)
make_sparse_vector_inplace(v[i]);
}
tuple _load_libsvm_formatted_data (
const std::string& file_name
)
{
std::vector<sparse_vect> samples;
std::vector<double> labels;
load_libsvm_formatted_data(file_name, samples, labels);
return make_tuple(samples, labels);
}
void _save_libsvm_formatted_data (
const std::string& file_name,
const std::vector<sparse_vect>& samples,
const std::vector<double>& labels
) { save_libsvm_formatted_data(file_name, samples, labels); }
void bind_other()
{
def("get_training_data",get_training_data);
def("make_sparse_vector", _make_sparse_vector , "This function modifies its argument so that it is a properly sorted sparse vector.");
def("make_sparse_vector", _make_sparse_vector2 , "This function modifies a sparse_vectors object so that all elements it contains are properly sorted sparse vectors.");
def("load_libsvm_formatted_data",_load_libsvm_formatted_data);
def("save_libsvm_formatted_data",_save_libsvm_formatted_data);
}
......@@ -177,7 +177,7 @@ void bind_svm_c_trainer()
{
typedef svm_c_trainer<sparse_radial_basis_kernel<sparse_vect> > T;
setup_trainer2<T>("svm_c_trainer_sparse_radial_basis")
.add_property("gamma", get_gamma, set_gamma);
.add_property("gamma", get_gamma_sparse, set_gamma_sparse);
def("cross_validate_trainer", _cross_validate_trainer<T>);
def("cross_validate_trainer_threaded", _cross_validate_trainer_t<T>);
}
......
Markdown is supported
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