Commit 37c815f6 authored by Davis King's avatar Davis King
Browse files

All I did in this change was rename calls to array_to_matrix(),

vector_to_matrix(), pointer_to_column_vector(), and pointer_to_matrix() to
mat() (in addition to adding a few more mat() overloads for certain things).
parent 0d970e47
...@@ -102,7 +102,7 @@ namespace dlib ...@@ -102,7 +102,7 @@ namespace dlib
); );
/*! /*!
requires requires
- T must be a dlib::matrix type or something convertible to a matrix via vector_to_matrix() - T must be a dlib::matrix type or something convertible to a matrix via mat()
(e.g. a std::vector) (e.g. a std::vector)
- is_vector(basis_samples) == true - is_vector(basis_samples) == true
- basis_samples.size() > 0 - basis_samples.size() > 0
...@@ -229,9 +229,9 @@ namespace dlib ...@@ -229,9 +229,9 @@ namespace dlib
) const; ) const;
/*! /*!
requires requires
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
- is_learning_problem(x,y) == true - is_learning_problem(x,y) == true
- if (get_lambda() == 0 && will_use_regression_loss_for_loo_cv() == false) then - if (get_lambda() == 0 && will_use_regression_loss_for_loo_cv() == false) then
......
...@@ -36,7 +36,7 @@ namespace dlib ...@@ -36,7 +36,7 @@ namespace dlib
- get_kernel() == kernel - get_kernel() == kernel
- minimum_tolerance() == min_tolerance - minimum_tolerance() == min_tolerance
- size() == dictionary.size() - size() == dictionary.size()
- get_dictionary() == vector_to_matrix(dictionary) - get_dictionary() == mat(dictionary)
- K.nr() == dictionary.size() - K.nr() == dictionary.size()
- K.nc() == dictionary.size() - K.nc() == dictionary.size()
- for all valid r,c: - for all valid r,c:
...@@ -302,7 +302,7 @@ namespace dlib ...@@ -302,7 +302,7 @@ namespace dlib
const matrix<sample_type,0,1,mem_manager_type> get_dictionary ( const matrix<sample_type,0,1,mem_manager_type> get_dictionary (
) const ) const
{ {
return vector_to_matrix(dictionary); return mat(dictionary);
} }
friend void serialize(const linearly_independent_subset_finder& item, std::ostream& out) friend void serialize(const linearly_independent_subset_finder& item, std::ostream& out)
...@@ -410,6 +410,18 @@ namespace dlib ...@@ -410,6 +410,18 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <
typename T
>
const matrix_op<op_array_to_mat<linearly_independent_subset_finder<T> > > mat (
const linearly_independent_subset_finder<T>& m
)
{
typedef op_array_to_mat<linearly_independent_subset_finder<T> > op;
return matrix_op<op>(op(m));
}
// ----------------------------------------------------------------------------------------
namespace impl namespace impl
{ {
template < template <
...@@ -485,7 +497,7 @@ namespace dlib ...@@ -485,7 +497,7 @@ namespace dlib
) )
{ {
dlib::rand rnd; dlib::rand rnd;
impl::fill_lisf(lisf, vector_to_matrix(samples),rnd, 2000); impl::fill_lisf(lisf, mat(samples),rnd, 2000);
} }
template < template <
...@@ -500,7 +512,7 @@ namespace dlib ...@@ -500,7 +512,7 @@ namespace dlib
const int sampling_size = 2000 const int sampling_size = 2000
) )
{ {
impl::fill_lisf(lisf, vector_to_matrix(samples),rnd, sampling_size); impl::fill_lisf(lisf, mat(samples),rnd, sampling_size);
} }
template < template <
...@@ -517,7 +529,7 @@ namespace dlib ...@@ -517,7 +529,7 @@ namespace dlib
{ {
dlib::rand rnd; dlib::rand rnd;
rnd.set_seed(cast_to_string(random_seed)); rnd.set_seed(cast_to_string(random_seed));
impl::fill_lisf(lisf, vector_to_matrix(samples), rnd, sampling_size); impl::fill_lisf(lisf, mat(samples), rnd, sampling_size);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -255,6 +255,22 @@ namespace dlib ...@@ -255,6 +255,22 @@ namespace dlib
provides serialization support for linearly_independent_subset_finder objects provides serialization support for linearly_independent_subset_finder objects
!*/ !*/
template <
typename T
>
const matrix_exp mat (
const linearly_independent_subset_finder<T>& m
);
/*!
ensures
- converts m into a matrix
- returns a matrix R such that:
- is_col_vector(R) == true
- R.size() == m.size()
- for all valid r:
R(r) == m[r]
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template < template <
...@@ -271,8 +287,8 @@ namespace dlib ...@@ -271,8 +287,8 @@ namespace dlib
/*! /*!
requires requires
- vector_type == a dlib::matrix or something convertible to one via - vector_type == a dlib::matrix or something convertible to one via
vector_to_matrix() mat()
- is_vector(vector_to_matrix(samples)) == true - is_vector(mat(samples)) == true
- rand_type == an implementation of rand/rand_kernel_abstract.h or a type - rand_type == an implementation of rand/rand_kernel_abstract.h or a type
convertible to a string via cast_to_string() convertible to a string via cast_to_string()
- sampling_size > 0 - sampling_size > 0
...@@ -297,8 +313,8 @@ namespace dlib ...@@ -297,8 +313,8 @@ namespace dlib
/*! /*!
requires requires
- vector_type == a dlib::matrix or something convertible to one via - vector_type == a dlib::matrix or something convertible to one via
vector_to_matrix() mat()
- is_vector(vector_to_matrix(samples)) == true - is_vector(mat(samples)) == true
ensures ensures
- performs fill_lisf(lisf, samples, default_rand_generator, 2000) - performs fill_lisf(lisf, samples, default_rand_generator, 2000)
!*/ !*/
......
...@@ -525,9 +525,9 @@ namespace dlib ...@@ -525,9 +525,9 @@ namespace dlib
) const ) const
{ {
if (use_cache) if (use_cache)
return do_train_cached(vector_to_matrix(x), vector_to_matrix(y)); return do_train_cached(mat(x), mat(y));
else else
return do_train(vector_to_matrix(x), vector_to_matrix(y)); return do_train(mat(x), mat(y));
} }
private: private:
......
...@@ -257,7 +257,7 @@ namespace dlib ...@@ -257,7 +257,7 @@ namespace dlib
// Note that we don't need to look at nonrel_counts since it is redundant with // Note that we don't need to look at nonrel_counts since it is redundant with
// the information in rel_counts in this case. // the information in rel_counts in this case.
total_wrong += sum(vector_to_matrix(rel_counts)); total_wrong += sum(mat(rel_counts));
} }
return static_cast<double>(total_pairs - total_wrong) / total_pairs; return static_cast<double>(total_pairs - total_wrong) / total_pairs;
...@@ -359,7 +359,7 @@ namespace dlib ...@@ -359,7 +359,7 @@ namespace dlib
// Note that we don't need to look at nonrel_counts since it is redundant with // Note that we don't need to look at nonrel_counts since it is redundant with
// the information in rel_counts in this case. // the information in rel_counts in this case.
total_wrong += sum(vector_to_matrix(rel_counts)); total_wrong += sum(mat(rel_counts));
} }
} // for (long i = 0; i < folds; ++i) } // for (long i = 0; i < folds; ++i)
......
...@@ -75,7 +75,7 @@ namespace dlib ...@@ -75,7 +75,7 @@ namespace dlib
const in_scalar_vector_type& y const in_scalar_vector_type& y
) const ) const
{ {
return do_train(vector_to_matrix(x), vector_to_matrix(y)); return do_train(mat(x), mat(y));
} }
void swap ( void swap (
......
...@@ -89,9 +89,9 @@ namespace dlib ...@@ -89,9 +89,9 @@ namespace dlib
) const ) const
/*! /*!
requires requires
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
- is_learning_problem(x,y) == true - is_learning_problem(x,y) == true
ensures ensures
......
...@@ -63,7 +63,7 @@ namespace dlib ...@@ -63,7 +63,7 @@ namespace dlib
"\t reduced_decision_function_trainer::train(x,y)" "\t reduced_decision_function_trainer::train(x,y)"
<< "\n\t You have tried to use an uninitialized version of this object" << "\n\t You have tried to use an uninitialized version of this object"
<< "\n\t num_bv: " << num_bv ); << "\n\t num_bv: " << num_bv );
return do_train(vector_to_matrix(x), vector_to_matrix(y)); return do_train(mat(x), mat(y));
} }
private: private:
...@@ -438,7 +438,7 @@ namespace dlib ...@@ -438,7 +438,7 @@ namespace dlib
// Now we compute the fist approximate distance function. // Now we compute the fist approximate distance function.
beta = pinv(kernel_matrix(kern,starting_basis)) * beta = pinv(kernel_matrix(kern,starting_basis)) *
(kernel_matrix(kern,starting_basis,target.get_basis_vectors())*target.get_alpha()); (kernel_matrix(kern,starting_basis,target.get_basis_vectors())*target.get_alpha());
matrix<sample_type,0,1,mem_manager_type> out_vectors(vector_to_matrix(starting_basis)); matrix<sample_type,0,1,mem_manager_type> out_vectors(mat(starting_basis));
// Now setup to do a global optimization of all the parameters in the approximate // Now setup to do a global optimization of all the parameters in the approximate
...@@ -529,7 +529,7 @@ namespace dlib ...@@ -529,7 +529,7 @@ namespace dlib
"\t reduced_decision_function_trainer2::train(x,y)" "\t reduced_decision_function_trainer2::train(x,y)"
<< "\n\t You have tried to use an uninitialized version of this object" << "\n\t You have tried to use an uninitialized version of this object"
<< "\n\t num_bv: " << num_bv ); << "\n\t num_bv: " << num_bv );
return do_train(vector_to_matrix(x), vector_to_matrix(y)); return do_train(mat(x), mat(y));
} }
private: private:
......
...@@ -123,7 +123,7 @@ namespace dlib ...@@ -123,7 +123,7 @@ namespace dlib
- stop_strategy == an object that defines a stop strategy such as one of - stop_strategy == an object that defines a stop strategy such as one of
the objects from dlib/optimization/optimization_stop_strategies_abstract.h the objects from dlib/optimization/optimization_stop_strategies_abstract.h
- requirements on starting_basis - requirements on starting_basis
- T must be a dlib::matrix type or something convertible to a matrix via vector_to_matrix() - T must be a dlib::matrix type or something convertible to a matrix via mat()
(e.g. a std::vector). Additionally, starting_basis must contain K::sample_type (e.g. a std::vector). Additionally, starting_basis must contain K::sample_type
objects which can be supplied to the kernel function used by target. objects which can be supplied to the kernel function used by target.
- is_vector(starting_basis) == true - is_vector(starting_basis) == true
......
...@@ -63,7 +63,7 @@ namespace dlib ...@@ -63,7 +63,7 @@ namespace dlib
); );
return do_train(vector_to_matrix(samples), vector_to_matrix(labels)); return do_train(mat(samples), mat(labels));
} }
private: private:
......
...@@ -73,9 +73,9 @@ namespace dlib ...@@ -73,9 +73,9 @@ namespace dlib
/*! /*!
requires requires
- is_binary_classification_problem(samples, labels) == true - is_binary_classification_problem(samples, labels) == true
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- performs training using the trainer object given to this object's - performs training using the trainer object given to this object's
......
...@@ -135,7 +135,7 @@ namespace dlib ...@@ -135,7 +135,7 @@ namespace dlib
{ {
std::vector<scalar_type> temp; std::vector<scalar_type> temp;
scalar_type temp2; scalar_type temp2;
return do_train(vector_to_matrix(x), vector_to_matrix(y), false, temp, temp2); return do_train(mat(x), mat(y), false, temp, temp2);
} }
template < template <
...@@ -149,7 +149,7 @@ namespace dlib ...@@ -149,7 +149,7 @@ namespace dlib
) const ) const
{ {
scalar_type temp; scalar_type temp;
return do_train(vector_to_matrix(x), vector_to_matrix(y), true, loo_values, temp); return do_train(mat(x), mat(y), true, loo_values, temp);
} }
template < template <
...@@ -163,7 +163,7 @@ namespace dlib ...@@ -163,7 +163,7 @@ namespace dlib
scalar_type& lambda_used scalar_type& lambda_used
) const ) const
{ {
return do_train(vector_to_matrix(x), vector_to_matrix(y), true, loo_values, lambda_used); return do_train(mat(x), mat(y), true, loo_values, lambda_used);
} }
......
...@@ -165,9 +165,9 @@ namespace dlib ...@@ -165,9 +165,9 @@ namespace dlib
) const; ) const;
/*! /*!
requires requires
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
- is_learning_problem(x,y) == true - is_learning_problem(x,y) == true
- if (get_lambda() == 0 && will_use_regression_loss_for_loo_cv() == false) then - if (get_lambda() == 0 && will_use_regression_loss_for_loo_cv() == false) then
......
...@@ -192,7 +192,7 @@ namespace dlib ...@@ -192,7 +192,7 @@ namespace dlib
const in_scalar_vector_type& y const in_scalar_vector_type& y
) const ) const
{ {
return do_train(vector_to_matrix(x), vector_to_matrix(y)); return do_train(mat(x), mat(y));
} }
void swap ( void swap (
...@@ -502,10 +502,10 @@ namespace dlib ...@@ -502,10 +502,10 @@ namespace dlib
} }
} }
return decision_function<kernel_type> ( vector_to_matrix(final_weights), return decision_function<kernel_type> ( mat(final_weights),
-sum(vector_to_matrix(final_weights))*tau, -sum(mat(final_weights))*tau,
kernel, kernel,
vector_to_matrix(dictionary)); mat(dictionary));
} }
...@@ -664,7 +664,7 @@ namespace dlib ...@@ -664,7 +664,7 @@ namespace dlib
const in_scalar_vector_type& t const in_scalar_vector_type& t
) const ) const
{ {
return do_train(vector_to_matrix(x), vector_to_matrix(t)); return do_train(mat(x), mat(t));
} }
void swap ( void swap (
...@@ -906,10 +906,10 @@ namespace dlib ...@@ -906,10 +906,10 @@ namespace dlib
} }
} }
return decision_function<kernel_type> ( vector_to_matrix(final_weights), return decision_function<kernel_type> ( mat(final_weights),
-sum(vector_to_matrix(final_weights))*tau, -sum(mat(final_weights))*tau,
kernel, kernel,
vector_to_matrix(dictionary)); mat(dictionary));
} }
......
...@@ -97,9 +97,9 @@ namespace dlib ...@@ -97,9 +97,9 @@ namespace dlib
/*! /*!
requires requires
- is_binary_classification_problem(x,y) == true - is_binary_classification_problem(x,y) == true
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
ensures ensures
- trains a relevance vector classifier given the training samples in x and - trains a relevance vector classifier given the training samples in x and
...@@ -219,9 +219,9 @@ namespace dlib ...@@ -219,9 +219,9 @@ namespace dlib
) const; ) const;
/*! /*!
requires requires
- x == a matrix or something convertible to a matrix via vector_to_matrix(). - x == a matrix or something convertible to a matrix via mat().
Also, x should contain sample_type objects. Also, x should contain sample_type objects.
- y == a matrix or something convertible to a matrix via vector_to_matrix(). - y == a matrix or something convertible to a matrix via mat().
Also, y should contain scalar_type objects. Also, y should contain scalar_type objects.
- is_learning_problem(x,y) == true - is_learning_problem(x,y) == true
- x.size() > 0 - x.size() > 0
......
...@@ -211,9 +211,9 @@ namespace dlib ...@@ -211,9 +211,9 @@ namespace dlib
) )
{ {
return bs_impl::sort_basis_vectors_impl(kern, return bs_impl::sort_basis_vectors_impl(kern,
vector_to_matrix(samples), mat(samples),
vector_to_matrix(labels), mat(labels),
vector_to_matrix(basis), mat(basis),
eps); eps);
} }
......
...@@ -33,9 +33,9 @@ namespace dlib ...@@ -33,9 +33,9 @@ namespace dlib
- basis.size() > 0 - basis.size() > 0
- kernel_type is a kernel function object as defined in dlib/svm/kernel_abstract.h - kernel_type is a kernel function object as defined in dlib/svm/kernel_abstract.h
It must be capable of operating on the elements of samples and basis. It must be capable of operating on the elements of samples and basis.
- vect1_type == a matrix or something convertible to a matrix via vector_to_matrix() - vect1_type == a matrix or something convertible to a matrix via mat()
- vect2_type == a matrix or something convertible to a matrix via vector_to_matrix() - vect2_type == a matrix or something convertible to a matrix via mat()
- vect3_type == a matrix or something convertible to a matrix via vector_to_matrix() - vect3_type == a matrix or something convertible to a matrix via mat()
ensures ensures
- A kernel based learning method ultimately needs to select a set of basis functions - A kernel based learning method ultimately needs to select a set of basis functions
represented by a particular choice of kernel and a set of basis vectors. represented by a particular choice of kernel and a set of basis vectors.
......
...@@ -550,7 +550,7 @@ namespace dlib ...@@ -550,7 +550,7 @@ namespace dlib
const T& samples const T& samples
) )
{ {
return impl::max_index_plus_one(vector_to_matrix(samples)); return impl::max_index_plus_one(mat(samples));
} }
// ------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------
......
...@@ -314,7 +314,7 @@ namespace dlib ...@@ -314,7 +314,7 @@ namespace dlib
requires requires
- samples == a single vector (either sparse or dense), or a container - samples == a single vector (either sparse or dense), or a container
of vectors which is either a dlib::matrix of vectors or something of vectors which is either a dlib::matrix of vectors or something
convertible to a dlib::matrix via vector_to_matrix() (e.g. a std::vector) convertible to a dlib::matrix via mat() (e.g. a std::vector)
Valid types of samples include (but are not limited to): Valid types of samples include (but are not limited to):
- dlib::matrix<double,0,1> // A single dense vector - dlib::matrix<double,0,1> // A single dense vector
- std::map<unsigned int, double> // A single sparse vector - std::map<unsigned int, double> // A single sparse vector
......
...@@ -110,13 +110,13 @@ namespace dlib ...@@ -110,13 +110,13 @@ namespace dlib
if (loss.size() >= prob->get_max_cache_size()) if (loss.size() >= prob->get_max_cache_size())
{ {
// find least recently used cache entry for idx-th sample // find least recently used cache entry for idx-th sample
const long i = index_of_min(vector_to_matrix(lru_count)); const long i = index_of_min(mat(lru_count));
// save our new data in the cache // save our new data in the cache
loss[i] = out_loss; loss[i] = out_loss;
psi[i] = out_psi; psi[i] = out_psi;
const long max_use = max(vector_to_matrix(lru_count)); const long max_use = max(mat(lru_count));
// Make sure this new cache entry has the best lru count since we have used // Make sure this new cache entry has the best lru count since we have used
// it most recently. // it most recently.
lru_count[i] = max_use + 1; lru_count[i] = max_use + 1;
...@@ -127,7 +127,7 @@ namespace dlib ...@@ -127,7 +127,7 @@ namespace dlib
psi.push_back(out_psi); psi.push_back(out_psi);
long max_use = 1; long max_use = 1;
if (lru_count.size() != 0) if (lru_count.size() != 0)
max_use = max(vector_to_matrix(lru_count)) + 1; max_use = max(mat(lru_count)) + 1;
lru_count.push_back(max_use); lru_count.push_back(max_use);
} }
} }
......
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