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
);
/*!
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)
- is_vector(basis_samples) == true
- basis_samples.size() > 0
......@@ -229,9 +229,9 @@ namespace dlib
) const;
/*!
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.
- 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.
- is_learning_problem(x,y) == true
- if (get_lambda() == 0 && will_use_regression_loss_for_loo_cv() == false) then
......
......@@ -36,7 +36,7 @@ namespace dlib
- get_kernel() == kernel
- minimum_tolerance() == min_tolerance
- size() == dictionary.size()
- get_dictionary() == vector_to_matrix(dictionary)
- get_dictionary() == mat(dictionary)
- K.nr() == dictionary.size()
- K.nc() == dictionary.size()
- for all valid r,c:
......@@ -302,7 +302,7 @@ namespace dlib
const matrix<sample_type,0,1,mem_manager_type> get_dictionary (
) const
{
return vector_to_matrix(dictionary);
return mat(dictionary);
}
friend void serialize(const linearly_independent_subset_finder& item, std::ostream& out)
......@@ -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
{
template <
......@@ -485,7 +497,7 @@ namespace dlib
)
{
dlib::rand rnd;
impl::fill_lisf(lisf, vector_to_matrix(samples),rnd, 2000);
impl::fill_lisf(lisf, mat(samples),rnd, 2000);
}
template <
......@@ -500,7 +512,7 @@ namespace dlib
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 <
......@@ -517,7 +529,7 @@ namespace dlib
{
dlib::rand rnd;
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
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 <
......@@ -271,8 +287,8 @@ namespace dlib
/*!
requires
- vector_type == a dlib::matrix or something convertible to one via
vector_to_matrix()
- is_vector(vector_to_matrix(samples)) == true
mat()
- is_vector(mat(samples)) == true
- rand_type == an implementation of rand/rand_kernel_abstract.h or a type
convertible to a string via cast_to_string()
- sampling_size > 0
......@@ -297,8 +313,8 @@ namespace dlib
/*!
requires
- vector_type == a dlib::matrix or something convertible to one via
vector_to_matrix()
- is_vector(vector_to_matrix(samples)) == true
mat()
- is_vector(mat(samples)) == true
ensures
- performs fill_lisf(lisf, samples, default_rand_generator, 2000)
!*/
......
......@@ -525,9 +525,9 @@ namespace dlib
) const
{
if (use_cache)
return do_train_cached(vector_to_matrix(x), vector_to_matrix(y));
return do_train_cached(mat(x), mat(y));
else
return do_train(vector_to_matrix(x), vector_to_matrix(y));
return do_train(mat(x), mat(y));
}
private:
......
......@@ -257,7 +257,7 @@ namespace dlib
// Note that we don't need to look at nonrel_counts since it is redundant with
// 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;
......@@ -359,7 +359,7 @@ namespace dlib
// Note that we don't need to look at nonrel_counts since it is redundant with
// 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)
......
......@@ -75,7 +75,7 @@ namespace dlib
const in_scalar_vector_type& y
) const
{
return do_train(vector_to_matrix(x), vector_to_matrix(y));
return do_train(mat(x), mat(y));
}
void swap (
......
......@@ -89,9 +89,9 @@ namespace dlib
) const
/*!
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.
- 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.
- is_learning_problem(x,y) == true
ensures
......
......@@ -63,7 +63,7 @@ namespace dlib
"\t reduced_decision_function_trainer::train(x,y)"
<< "\n\t You have tried to use an uninitialized version of this object"
<< "\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:
......@@ -438,7 +438,7 @@ namespace dlib
// Now we compute the fist approximate distance function.
beta = pinv(kernel_matrix(kern,starting_basis)) *
(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
......@@ -529,7 +529,7 @@ namespace dlib
"\t reduced_decision_function_trainer2::train(x,y)"
<< "\n\t You have tried to use an uninitialized version of this object"
<< "\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:
......
......@@ -123,7 +123,7 @@ namespace dlib
- stop_strategy == an object that defines a stop strategy such as one of
the objects from dlib/optimization/optimization_stop_strategies_abstract.h
- 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
objects which can be supplied to the kernel function used by target.
- is_vector(starting_basis) == true
......
......@@ -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:
......
......@@ -73,9 +73,9 @@ namespace dlib
/*!
requires
- 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.
- 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.
ensures
- performs training using the trainer object given to this object's
......
......@@ -135,7 +135,7 @@ namespace dlib
{
std::vector<scalar_type> temp;
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 <
......@@ -149,7 +149,7 @@ namespace dlib
) const
{
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 <
......@@ -163,7 +163,7 @@ namespace dlib
scalar_type& lambda_used
) 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
) const;
/*!
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.
- 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.
- is_learning_problem(x,y) == true
- if (get_lambda() == 0 && will_use_regression_loss_for_loo_cv() == false) then
......
......@@ -192,7 +192,7 @@ namespace dlib
const in_scalar_vector_type& y
) const
{
return do_train(vector_to_matrix(x), vector_to_matrix(y));
return do_train(mat(x), mat(y));
}
void swap (
......@@ -502,10 +502,10 @@ namespace dlib
}
}
return decision_function<kernel_type> ( vector_to_matrix(final_weights),
-sum(vector_to_matrix(final_weights))*tau,
return decision_function<kernel_type> ( mat(final_weights),
-sum(mat(final_weights))*tau,
kernel,
vector_to_matrix(dictionary));
mat(dictionary));
}
......@@ -664,7 +664,7 @@ namespace dlib
const in_scalar_vector_type& t
) const
{
return do_train(vector_to_matrix(x), vector_to_matrix(t));
return do_train(mat(x), mat(t));
}
void swap (
......@@ -906,10 +906,10 @@ namespace dlib
}
}
return decision_function<kernel_type> ( vector_to_matrix(final_weights),
-sum(vector_to_matrix(final_weights))*tau,
return decision_function<kernel_type> ( mat(final_weights),
-sum(mat(final_weights))*tau,
kernel,
vector_to_matrix(dictionary));
mat(dictionary));
}
......
......@@ -97,9 +97,9 @@ namespace dlib
/*!
requires
- 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.
- 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.
ensures
- trains a relevance vector classifier given the training samples in x and
......@@ -219,9 +219,9 @@ namespace dlib
) const;
/*!
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.
- 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.
- is_learning_problem(x,y) == true
- x.size() > 0
......
......@@ -211,9 +211,9 @@ namespace dlib
)
{
return bs_impl::sort_basis_vectors_impl(kern,
vector_to_matrix(samples),
vector_to_matrix(labels),
vector_to_matrix(basis),
mat(samples),
mat(labels),
mat(basis),
eps);
}
......
......@@ -33,9 +33,9 @@ namespace dlib
- basis.size() > 0
- 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.
- vect1_type == a matrix or something convertible to a matrix via vector_to_matrix()
- vect2_type == a matrix or something convertible to a matrix via vector_to_matrix()
- vect3_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 mat()
- vect3_type == a matrix or something convertible to a matrix via mat()
ensures
- 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.
......
......@@ -550,7 +550,7 @@ namespace dlib
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
requires
- samples == a single vector (either sparse or dense), or a container
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):
- dlib::matrix<double,0,1> // A single dense vector
- std::map<unsigned int, double> // A single sparse vector
......
......@@ -110,13 +110,13 @@ namespace dlib
if (loss.size() >= prob->get_max_cache_size())
{
// 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
loss[i] = out_loss;
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
// it most recently.
lru_count[i] = max_use + 1;
......@@ -127,7 +127,7 @@ namespace dlib
psi.push_back(out_psi);
long max_use = 1;
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);
}
}
......
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