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

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
......@@ -367,7 +367,7 @@ namespace dlib
- #num_labels == the number of distinct values in labels.
- returns a vector V such that:
- V.size() == labels.size()
- max(vector_to_matrix(V))+1 == num_labels.
- max(mat(V))+1 == num_labels.
- for all valid i,j:
- if (labels[i] == labels[j]) then
- V[i] == V[j]
......
......@@ -92,7 +92,7 @@ namespace dlib
// predict next state
for (long i = 0; i < next.size(); ++i)
next(i) = filter(vector_to_matrix(data[i]));
next(i) = filter(mat(data[i]));
}
template <typename EXP>
......@@ -127,7 +127,7 @@ namespace dlib
// showing it to the rls filter so it can do its thing.
if (count >= 2)
{
filter.train(vector_to_matrix(data[i]), z(i));
filter.train(mat(data[i]), z(i));
}
// keep track of the measurements in our circular buffer
......@@ -139,7 +139,7 @@ namespace dlib
{
// predict next state
for (long i = 0; i < z.size(); ++i)
next(i) = filter(vector_to_matrix(data[i]));
next(i) = filter(mat(data[i]));
}
else
{
......
......@@ -2375,7 +2375,7 @@ namespace dlib
/*!
requires
- image_type == an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix or something convertible to a matrix via array_to_matrix()
a dlib::matrix or something convertible to a matrix via mat()
- pixel_traits<typename image_type::type> must be defined
ensures
- #*this widget is now displaying the given image new_img.
......@@ -2790,7 +2790,7 @@ namespace dlib
/*!
requires
- image_type == an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix or something convertible to a matrix via array_to_matrix()
a dlib::matrix or something convertible to a matrix via mat()
- pixel_traits<typename image_type::type> must be defined
ensures
- this object is properly initialized
......
......@@ -67,7 +67,7 @@ namespace dlib
)
{
COMPILE_TIME_ASSERT( pixel_traits<typename image_type::type>::has_alpha == false );
load_impl(array_to_matrix(img));
load_impl(mat(img));
}
inline void unload(
......
......@@ -102,7 +102,7 @@ namespace dlib
/*!
requires
- image_type is a dlib::matrix or something convertible to a matrix
via array_to_matrix()
via mat()
- pixel_traits<typename image_type::type>::has_alpha == false
ensures
- if (img.nr() < min_size || img.nc() < min_size) then
......
......@@ -83,7 +83,7 @@ namespace dlib
)
{
COMPILE_TIME_ASSERT( pixel_traits<typename image_type::type>::has_alpha == false );
load_impl(array_to_matrix(img));
load_impl(mat(img));
}
inline void unload(
......
......@@ -158,7 +158,7 @@ namespace dlib
/*!
requires
- image_type is a dlib::matrix or something convertible to a matrix
via array_to_matrix()
via mat()
- pixel_traits<typename image_type::type>::has_alpha == false
ensures
- if (img.nr() < min_size || img.nc() < min_size) then
......
......@@ -102,7 +102,7 @@ namespace dlib
{
const typename image_array_type::type& img = images[rects[i].first];
const rectangle rect = get_rect(img).intersect(translate_rect(rects[i].second,position));
temp += sum(matrix_cast<ptype>(subm(array_to_matrix(img), rect)));
temp += sum(matrix_cast<ptype>(subm(mat(img), rect)));
}
return static_cast<double>(temp);
......@@ -161,7 +161,7 @@ namespace dlib
{
const typename image_array_type::type& img = images[fixed_rects[i].first];
const rectangle rect = get_rect(img).intersect(translate_rect(fixed_rects[i].second,position));
temp += sum(matrix_cast<ptype>(subm(array_to_matrix(img), rect)));
temp += sum(matrix_cast<ptype>(subm(mat(img), rect)));
}
if (images.size() > 0)
......@@ -176,7 +176,7 @@ namespace dlib
const rectangle rect = get_rect(tempimg).intersect(translate_rect(window,position));
if (rect.is_empty() == false)
temp += std::max(0,max(matrix_cast<ptype>(subm(array_to_matrix(tempimg), rect))));
temp += std::max(0,max(matrix_cast<ptype>(subm(mat(tempimg), rect))));
}
}
......
......@@ -75,7 +75,7 @@ namespace dlib
if (is_same_object(dest,src))
return;
impl_assign_image(dest, array_to_matrix(src));
impl_assign_image(dest, mat(src));
}
// ----------------------------------------------------------------------------------------
......@@ -175,7 +175,7 @@ namespace dlib
if (is_same_object(dest,src))
return;
impl_assign_image_scaled(dest, array_to_matrix(src),thresh);
impl_assign_image_scaled(dest, mat(src),thresh);
}
// ----------------------------------------------------------------------------------------
......
......@@ -21,7 +21,7 @@ namespace dlib
/*!
requires
- src_image_type == is an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix or something convertible to a matrix via array_to_matrix()
a dlib::matrix or something convertible to a matrix via mat()
- dest_image_type == is an implementation of array2d/array2d_kernel_abstract.h or
is a dlib::matrix.
- pixel_traits<typename src_image_type::type> is defined
......@@ -48,7 +48,7 @@ namespace dlib
/*!
requires
- src_image_type == is an implementation of array2d/array2d_kernel_abstract.h or
a dlib::matrix or something convertible to a matrix via array_to_matrix()
a dlib::matrix or something convertible to a matrix via mat()
- dest_image_type == is an implementation of array2d/array2d_kernel_abstract.h or
is a dlib::matrix.
- pixel_traits<typename src_image_type::type> is defined
......@@ -75,8 +75,8 @@ namespace dlib
deviation of src_img. Call the mean M and the standard deviation
D. Then the scaling from src_img to dest_img is performed using
the following mapping:
let SRC_UPPER = min(M + thresh*D, max(array_to_matrix(src_img)))
let SRC_LOWER = max(M - thresh*D, min(array_to_matrix(src_img)))
let SRC_UPPER = min(M + thresh*D, max(mat(src_img)))
let SRC_LOWER = max(M - thresh*D, min(mat(src_img)))
let DEST_UPPER = pixel_traits<dest_image_type::type>::max()
let DEST_LOWER = pixel_traits<dest_image_type::type>::min()
......
......@@ -78,7 +78,7 @@ namespace dlib
(i.e. rect must not be outside the integral image)
ensures
- Let O denote the image this integral image was generated from.
Then this function returns sum(subm(array_to_matrix(O),rect)).
Then this function returns sum(subm(mat(O),rect)).
That is, this function returns the sum of the pixels in O that
are contained within the given rectangle.
!*/
......
......@@ -554,7 +554,7 @@ namespace dlib
<< "\n\t is_same_object(in_img, out_img): " << is_same_object(in_img, out_img)
);
assign_image(out_img, fliplr(array_to_matrix(in_img)));
assign_image(out_img, fliplr(mat(in_img)));
}
// ----------------------------------------------------------------------------------------
......@@ -575,7 +575,7 @@ namespace dlib
<< "\n\t is_same_object(in_img, out_img): " << is_same_object(in_img, out_img)
);
assign_image(out_img, flipud(array_to_matrix(in_img)));
assign_image(out_img, flipud(mat(in_img)));
}
// ----------------------------------------------------------------------------------------
......
......@@ -177,7 +177,7 @@ namespace dlib
- else
- #label_img[r][c] != 0
- if (img.size() != 0) then
- returns max(array_to_matrix(#label_img))+1
- returns max(mat(#label_img))+1
(i.e. returns a number one greater than the maximum blob id number,
this is the number of blobs found.)
- else
......
......@@ -663,7 +663,7 @@ namespace dlib
strip = strip.intersect(get_rect(img));
if (!strip.is_empty())
{
column_sum[j] = sum(matrix_cast<ptype>(subm(array_to_matrix(img),strip)));
column_sum[j] = sum(matrix_cast<ptype>(subm(mat(img),strip)));
}
++left;
......@@ -679,7 +679,7 @@ namespace dlib
// Now do the bulk of the filtering work.
for (long r = 0; r < img.nr(); ++r)
{
// set to sum at point(-1,r). i.e. should be equal to sum(array_to_matrix(img), translate_rect(rect, point(-1,r)))
// set to sum at point(-1,r). i.e. should be equal to sum(mat(img), translate_rect(rect, point(-1,r)))
// We compute it's value in the next loop.
ptype cur_sum = 0;
......
......@@ -87,7 +87,7 @@ namespace dlib
counts[h[i]] += 1;
}
const unsigned long max_h = index_of_max(vector_to_matrix(counts));
const unsigned long max_h = index_of_max(mat(counts));
temp.clear();
for (unsigned long i = 0; i < v.size(); ++i)
......
......@@ -301,7 +301,7 @@ namespace dlib
}
}
map_assignment[id_i] = index_of_max(vector_to_matrix(b));
map_assignment[id_i] = index_of_max(mat(b));
}
}
......
......@@ -28,12 +28,12 @@ namespace dlib
// can't call max on an empty vector. So put an if here to guard against it.
if (assignment.size() > 0)
{
DLIB_ASSERT(0 <= min(vector_to_matrix(assignment)) && max(vector_to_matrix(assignment)) < cost.nr(),
DLIB_ASSERT(0 <= min(mat(assignment)) && max(mat(assignment)) < cost.nr(),
"\t type assignment_cost(cost,assignment)"
<< "\n\t cost.nr(): " << cost.nr()
<< "\n\t cost.nc(): " << cost.nc()
<< "\n\t min(assignment): " << min(vector_to_matrix(assignment))
<< "\n\t max(assignment): " << max(vector_to_matrix(assignment))
<< "\n\t min(assignment): " << min(mat(assignment))
<< "\n\t max(assignment): " << max(mat(assignment))
);
}
#endif
......
......@@ -193,7 +193,7 @@ namespace dlib
universe_set.top_min = 0;
universe_set.bottom_max = mat.nr()-1;
universe_set.top_max = mat.nr()-1;
universe_set.weight = sum(rowm(array_to_matrix(sum_pos),mat.nr()));
universe_set.weight = sum(rowm(dlib::mat(sum_pos),mat.nr()));
q.push(universe_set);
......@@ -247,7 +247,7 @@ namespace dlib
}
universe_set.weight = sum(rowm(array_to_matrix(sum_pos),mat.nr()));
universe_set.weight = sum(rowm(dlib::mat(sum_pos),mat.nr()));
if (universe_set.weight <= thresh)
break;
......
......@@ -874,7 +874,7 @@ L360:
//goto L720;
}
++nf;
f = calfun(pointer_to_column_vector(&x[1], n));
f = calfun(mat(&x[1], n));
if (ntrits == -1) {
fsave = f;
goto L720;
......@@ -1946,7 +1946,7 @@ L50:
}
/* L60: */
}
f = calfun(pointer_to_column_vector(&x[1],n));
f = calfun(mat(&x[1],n));
fval[nf] = f;
if (nf == 1) {
fbeg = f;
......@@ -2572,7 +2572,7 @@ L260:
/* L290: */
}
++(nf);
f = calfun(pointer_to_column_vector(&w[1],n));
f = calfun(mat(&w[1],n));
fval[kpt] = f;
if (f < fval[kopt]) {
kopt = kpt;
......
......@@ -191,18 +191,18 @@ namespace dlib
)
{
// make sure requires clause is not broken
DLIB_ASSERT(is_vector(vector_to_matrix(list)) && list.size() > 0 &&
DLIB_ASSERT(is_vector(mat(list)) && list.size() > 0 &&
is_col_vector(x) && radius > 0,
"\t double solve_least_squares()"
<< "\n\t invalid arguments were given to this function"
<< "\n\t is_vector(list): " << is_vector(vector_to_matrix(list))
<< "\n\t is_vector(list): " << is_vector(mat(list))
<< "\n\t list.size(): " << list.size()
<< "\n\t is_col_vector(x): " << is_col_vector(x)
<< "\n\t radius: " << radius
);
return find_min_trust_region(stop_strategy,
least_squares_model<T>(f, der, vector_to_matrix(list)),
least_squares_model<T>(f, der, mat(list)),
x,
radius);
}
......@@ -314,18 +314,18 @@ namespace dlib
)
{
// make sure requires clause is not broken
DLIB_ASSERT(is_vector(vector_to_matrix(list)) && list.size() > 0 &&
DLIB_ASSERT(is_vector(mat(list)) && list.size() > 0 &&
is_col_vector(x) && radius > 0,
"\t double solve_least_squares_lm()"
<< "\n\t invalid arguments were given to this function"
<< "\n\t is_vector(list): " << is_vector(vector_to_matrix(list))
<< "\n\t is_vector(list): " << is_vector(mat(list))
<< "\n\t list.size(): " << list.size()
<< "\n\t is_col_vector(x): " << is_col_vector(x)
<< "\n\t radius: " << radius
);
return find_min_trust_region(stop_strategy,
least_squares_lm_model<T>(f, der, vector_to_matrix(list)),
least_squares_lm_model<T>(f, der, mat(list)),
x,
radius);
}
......
......@@ -30,7 +30,7 @@ namespace dlib
requires
- stop_strategy == an object that defines a stop strategy such as one of
the objects from dlib/optimization/optimization_stop_strategies_abstract.h
- list == a matrix or something convertible to a matrix via vector_to_matrix()
- list == a matrix or something convertible to a matrix via mat()
such as a std::vector.
- is_vector(list) == true
- list.size() > 0
......@@ -78,7 +78,7 @@ namespace dlib
requires
- stop_strategy == an object that defines a stop strategy such as one of
the objects from dlib/optimization/optimization_stop_strategies_abstract.h
- list == a matrix or something convertible to a matrix via vector_to_matrix()
- list == a matrix or something convertible to a matrix via mat()
such as a std::vector.
- is_vector(list) == true
- list.size() > 0
......
......@@ -225,9 +225,9 @@ namespace dlib
// Note that we warm start this optimization by using the alpha from the last
// iteration as the starting point.
if (num_nonnegative != 0)
solve_qp4_using_smo(rowm(planes,range(0,num_nonnegative-1)), K, vector_to_matrix(bs), alpha, eps, sub_max_iter);
solve_qp4_using_smo(rowm(planes,range(0,num_nonnegative-1)), K, mat(bs), alpha, eps, sub_max_iter);
else
solve_qp_using_smo(K, vector_to_matrix(bs), alpha, eps, sub_max_iter);
solve_qp_using_smo(K, mat(bs), alpha, eps, sub_max_iter);
// construct the w that minimized the subproblem.
w = -(planes*alpha);
......@@ -245,14 +245,14 @@ namespace dlib
// Compute the lower bound on the true objective given to us by the cutting
// plane subproblem.
cp_obj = -0.5*trans(w)*w + trans(alpha)*vector_to_matrix(bs);
cp_obj = -0.5*trans(w)*w + trans(alpha)*mat(bs);
// If it has been a while since a cutting plane was an active constraint then
// we should throw it away.
while (max(vector_to_matrix(miss_count)) >= inactive_thresh)
while (max(mat(miss_count)) >= inactive_thresh)
{
const long idx = index_of_max(vector_to_matrix(miss_count));
const long idx = index_of_max(mat(miss_count));
bs.erase(bs.begin()+idx);
miss_count.erase(miss_count.begin()+idx);
K = removerc(K, idx, idx);
......
......@@ -74,7 +74,7 @@ namespace dlib
const T& y
)
{
return maximum_nu_impl(vector_to_matrix(y));
return maximum_nu_impl(mat(y));
}
template <
......@@ -84,7 +84,7 @@ namespace dlib
const T& y
)
{
return maximum_nu_impl(vector_to_matrix(y));
return maximum_nu_impl(mat(y));
}
// ----------------------------------------------------------------------------------------
......
......@@ -37,7 +37,7 @@ namespace dlib
);
/*!
requires
- T == a matrix object or an object convertible to a matrix via vector_to_matrix()
- T == a matrix object or an object convertible to a matrix via mat()
- is_col_vector(y) == true
- y.size() > 1
- sum((y == +1) + (y == -1)) == y.size()
......
......@@ -7,6 +7,7 @@
#include <vector>
#include "../algs.h"
#include "../serialize.h"
#include "../matrix/matrix_mat.h"
namespace dlib
{
......@@ -209,6 +210,19 @@ namespace dlib
}
}
// ----------------------------------------------------------------------------------------
template <
typename T
>
const matrix_op<op_array_to_mat<circular_buffer<T> > > mat (
const circular_buffer<T>& m
)
{
typedef op_array_to_mat<circular_buffer<T> > op;
return matrix_op<op>(op(m));
}
// ----------------------------------------------------------------------------------------
}
......
......@@ -222,6 +222,23 @@ namespace dlib
provides deserialization support
!*/
// ----------------------------------------------------------------------------------------
template <
typename T
>
const matrix_exp mat (
const circular_buffer<T>& m
);
/*!
ensures
- returns a matrix R such that:
- is_col_vector(R) == true
- R.size() == m.size()
- for all valid r:
R(r) == m[r]
!*/
// ----------------------------------------------------------------------------------------
}
......
......@@ -9,6 +9,7 @@
#include "../algs.h"
#include "../string.h"
#include "../serialize.h"
#include "../matrix/matrix_mat.h"
#include <iostream>
namespace dlib
......@@ -346,6 +347,19 @@ namespace dlib
return subset;
}
// ----------------------------------------------------------------------------------------
template <
typename T
>
const matrix_op<op_array_to_mat<random_subset_selector<T> > > mat (
const random_subset_selector<T>& m
)
{
typedef op_array_to_mat<random_subset_selector<T> > op;
return matrix_op<op>(op(m));
}
// ----------------------------------------------------------------------------------------
}
......
......@@ -351,6 +351,23 @@ namespace dlib
generator used by this function.
!*/
// ----------------------------------------------------------------------------------------
template <
typename T
>
const matrix_exp mat (
const random_subset_selector<T>& m
);
/*!
ensures
- returns a matrix R such that:
- is_col_vector(R) == true
- R.size() == m.size()
- for all valid r:
R(r) == m[r]
!*/
// ----------------------------------------------------------------------------------------
}
......
......@@ -549,7 +549,7 @@ namespace dlib
<< "\n\t b.size(): " << b.size()
);
return mean(squared(matrix_cast<double>(vector_to_matrix(a))-matrix_cast<double>(vector_to_matrix(b))));
return mean(squared(matrix_cast<double>(mat(a))-matrix_cast<double>(mat(b))));
}
// ----------------------------------------------------------------------------------------
......@@ -737,8 +737,8 @@ namespace dlib
<< "\n\tthis: " << this
);
m = mean(vector_to_matrix(samples));
sd = reciprocal(sqrt(variance(vector_to_matrix(samples))));
m = mean(mat(samples));
sd = reciprocal(sqrt(variance(mat(samples))));
}
long in_vector_size (
......@@ -900,7 +900,7 @@ namespace dlib
<< "\n\tyou have to give a nonempty set of samples to this function"
<< "\n\tthis: " << this
);
train_pca_impl(vector_to_matrix(samples),eps);
train_pca_impl(mat(samples),eps);
}
long in_vector_size (
......
......@@ -101,7 +101,7 @@ namespace dlib
- a.size() == b.size()
ensures
- returns the mean squared error between all the elements of a and b.
(i.e. mean(squared(vector_to_matrix(a)-vector_to_matrix(b))))
(i.e. mean(squared(mat(a)-mat(b))))
!*/
// ----------------------------------------------------------------------------------------
......@@ -584,7 +584,7 @@ namespace dlib
requires
- samples.size() > 0
- samples == a column matrix or something convertible to a column
matrix via vector_to_matrix(). Also, x should contain
matrix via mat(). Also, x should contain
matrix_type objects that represent nonempty column vectors.
ensures
- #in_vector_size() == samples(0).nr()
......@@ -742,7 +742,7 @@ namespace dlib
- 0 < eps <= 1
- samples.size() > 0
- samples == a column matrix or something convertible to a column
matrix via vector_to_matrix(). Also, x should contain
matrix via mat(). Also, x should contain
matrix_type objects that represent nonempty column vectors.
ensures
- This object has learned how to normalize vectors that look like
......
......@@ -177,6 +177,18 @@ namespace dlib
const array_type& array;
const std::vector<unsigned long>& idx_set;
};
template <
typename T
>
const matrix_op<op_array_to_mat<array_subset_helper<T> > > mat (
const array_subset_helper<T>& m
)
{
typedef op_array_to_mat<array_subset_helper<T> > op;
return matrix_op<op>(op(m));
}
}
// ----------------------------------------------------------------------------------------
......
......@@ -69,7 +69,7 @@ namespace dlib
const T& basis_samples
)
{
load_impl(kernel_, vector_to_matrix(basis_samples));
load_impl(kernel_, mat(basis_samples));
}
void load(
......@@ -150,7 +150,7 @@ namespace dlib
<< "\n\t this: " << this
);
return decision_function<kernel_type>(trans(weights)*vect, 0, kernel, vector_to_matrix(basis));
return decision_function<kernel_type>(trans(weights)*vect, 0, kernel, mat(basis));
}
template <typename EXP>
......@@ -168,7 +168,7 @@ namespace dlib
<< "\n\t this: " << this
);
return distance_function<kernel_type>(trans(weights)*vect, dot(vect,vect), kernel, vector_to_matrix(basis));
return distance_function<kernel_type>(trans(weights)*vect, dot(vect,vect), kernel, mat(basis));
}
const projection_function<kernel_type> get_projection_function (
......@@ -181,7 +181,7 @@ namespace dlib
<< "\n\t this: " << this
);
return projection_function<kernel_type>(weights, kernel, vector_to_matrix(basis));
return projection_function<kernel_type>(weights, kernel, mat(basis));
}
const matrix<scalar_type,0,0,mem_manager_type> get_transformation_to (
......@@ -242,7 +242,7 @@ namespace dlib
tmat = colm(target.weights, range(0,num1-1))*kernel_matrix(kernel, basis)*trans(weights);
empirical_kernel_map temp_ekm;
temp_ekm.load(kernel, rowm(vector_to_matrix(target.basis), range(num1,num2-1)));
temp_ekm.load(kernel, rowm(mat(target.basis), range(num1,num2-1)));
partial_projection = temp_ekm.get_projection_function();
......
......@@ -124,7 +124,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
......
......@@ -150,7 +150,7 @@ namespace dlib
const label_matrix_type& labels
)
{
return rank_features_impl(kc, vector_to_matrix(samples), vector_to_matrix(labels));
return rank_features_impl(kc, mat(samples), mat(labels));
}
// ----------------------------------------------------------------------------------------
......@@ -266,14 +266,14 @@ namespace dlib
const long num_features
)
{
if (vector_to_matrix(samples).nr() > 0 && num_features == vector_to_matrix(samples)(0).nr())
if (mat(samples).nr() > 0 && num_features == mat(samples)(0).nr())
{
// if we are going to rank them all then might as well do the recursive feature elimination version
return rank_features_impl(kc, vector_to_matrix(samples), vector_to_matrix(labels));
return rank_features_impl(kc, mat(samples), mat(labels));
}
else
{
return rank_features_impl(kc, vector_to_matrix(samples), vector_to_matrix(labels), num_features);
return rank_features_impl(kc, mat(samples), mat(labels), num_features);
}
}
......@@ -416,8 +416,8 @@ namespace dlib
<< "\n\t is_binary_classification_problem(): " << is_binary_classification_problem(samples, labels)
);
return rank_features_helpers::find_gamma_with_big_centroid_gap_impl(vector_to_matrix(samples),
vector_to_matrix(labels),
return rank_features_helpers::find_gamma_with_big_centroid_gap_impl(mat(samples),
mat(labels),
initial_gamma,
num_sv,
false);
......@@ -443,8 +443,8 @@ namespace dlib
<< "\n\t is_binary_classification_problem(): " << is_binary_classification_problem(samples, labels)
);
return rank_features_helpers::find_gamma_with_big_centroid_gap_impl(vector_to_matrix(samples),
vector_to_matrix(labels),
return rank_features_helpers::find_gamma_with_big_centroid_gap_impl(mat(samples),
mat(labels),
initial_gamma,
num_sv,
true);
......
......@@ -28,8 +28,8 @@ namespace dlib
);
/*!
requires
- sample_matrix_type == a matrix or something convertible to a matrix via vector_to_matrix()
- label_matrix_type == a matrix or something convertible to a matrix via vector_to_matrix()
- sample_matrix_type == a matrix or something convertible to a matrix via mat()
- label_matrix_type == a matrix or something convertible to a matrix via mat()
- is_binary_classification_problem(samples, labels) == true
- kc.train(samples(0)) must be a valid expression. This means that
kc must use a kernel type that is capable of operating on the
......
......@@ -337,10 +337,10 @@ namespace dlib
) const
{
refresh_bias();
return distance_function<kernel_type>(vector_to_matrix(alpha),
return distance_function<kernel_type>(mat(alpha),
bias,
kernel,
vector_to_matrix(dictionary));
mat(dictionary));
}
private:
......@@ -352,7 +352,7 @@ namespace dlib
{
bias_is_stale = false;
// recompute the bias term
bias = sum(pointwise_multiply(K, vector_to_matrix(alpha)*trans(vector_to_matrix(alpha))));
bias = sum(pointwise_multiply(K, mat(alpha)*trans(mat(alpha))));
}
}
......@@ -396,7 +396,7 @@ namespace dlib
if (do_test)
{
refresh_bias();
test_result = std::sqrt(kx + bias - 2*trans(vector_to_matrix(alpha))*k);
test_result = std::sqrt(kx + bias - 2*trans(mat(alpha))*k);
}
// compute the error we would have if we approximated the new x sample
......@@ -525,7 +525,7 @@ namespace dlib
// now compute the updated alpha values to take account that we just removed one of
// our dictionary vectors
a = (K_inv*remove_row(K,i)*vector_to_matrix(alpha));
a = (K_inv*remove_row(K,i)*mat(alpha));
// now copy over the new alpha values
alpha.resize(alpha.size()-1);
......
......@@ -104,7 +104,7 @@ namespace dlib
long max_iter = 1000
)
{
do_train(vector_to_matrix(samples),vector_to_matrix(initial_centers),max_iter);
do_train(mat(samples),mat(initial_centers),max_iter);
}
unsigned long operator() (
......
......@@ -112,7 +112,7 @@ namespace dlib
/*!
requires
- matrix_type and matrix_type2 must either be dlib::matrix objects or convertible to dlib::matrix
via vector_to_matrix()
via mat()
- matrix_type::type == sample_type (i.e. matrix_type should contain sample_type objects)
- matrix_type2::type == sample_type (i.e. matrix_type2 should contain sample_type objects)
- initial_centers.nc() == 1 (i.e. must be a column vector)
......
......@@ -182,7 +182,7 @@ namespace dlib
temp.swap(P);
// now update the alpha vector (equation 3.16)
const scalar_type k_a = (y-trans(k)*vector_to_matrix(alpha))/delta;
const scalar_type k_a = (y-trans(k)*mat(alpha))/delta;
for (unsigned long i = 0; i < alpha.size(); ++i)
{
alpha[i] -= a(i)*k_a;
......@@ -198,7 +198,7 @@ namespace dlib
P -= q*temp_matrix;
// update the alpha vector (equation 3.13)
const scalar_type k_a = y-trans(k)*vector_to_matrix(alpha);
const scalar_type k_a = y-trans(k)*mat(alpha);
for (unsigned long i = 0; i < alpha.size(); ++i)
{
alpha[i] += (K_inv*q*k_a)(i);
......@@ -232,10 +232,10 @@ namespace dlib
) const
{
return decision_function<kernel_type>(
vector_to_matrix(alpha),
-sum(vector_to_matrix(alpha))*tau,
mat(alpha),
-sum(mat(alpha))*tau,
kernel,
vector_to_matrix(dictionary)
mat(dictionary)
);
}
......@@ -295,7 +295,7 @@ namespace dlib
// now compute the updated alpha values to take account that we just removed one of
// our dictionary vectors
a = (K_inv*remove_row(K,i)*vector_to_matrix(alpha));
a = (K_inv*remove_row(K,i)*mat(alpha));
// now copy over the new alpha values
alpha.resize(alpha.size()-1);
......
......@@ -88,15 +88,15 @@ namespace dlib
)
{
// make sure requires clause is not broken
DLIB_ASSERT(basis_samples.size() > 0 && is_vector(vector_to_matrix(basis_samples)),
DLIB_ASSERT(basis_samples.size() > 0 && is_vector(mat(basis_samples)),
"\tvoid krr_trainer::set_basis(basis_samples)"
<< "\n\t You have to give a non-empty set of basis_samples and it must be a vector"
<< "\n\t basis_samples.size(): " << basis_samples.size()
<< "\n\t is_vector(vector_to_matrix(basis_samples)): " << is_vector(vector_to_matrix(basis_samples))
<< "\n\t is_vector(mat(basis_samples)): " << is_vector(mat(basis_samples))
<< "\n\t this: " << this
);
basis = vector_to_matrix(basis_samples);
basis = mat(basis_samples);
ekm_stale = true;
}
......@@ -191,7 +191,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 <
......@@ -205,7 +205,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 <
......@@ -219,7 +219,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);
}
......
......@@ -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);
}
}
......
......@@ -181,7 +181,7 @@ namespace dlib
matrix<unsigned long,0,1> candidate_labeling;
for (unsigned long i = 0; i < sample.size(); ++i)
{
candidate_labeling = rowm(vector_to_matrix(label), range(i, std::max((int)i-order,0)));
candidate_labeling = rowm(mat(label), range(i, std::max((int)i-order,0)));
fe_helpers::get_feature_vector(psi,fe,sample,candidate_labeling, i);
}
......
......@@ -48,7 +48,7 @@ namespace dlib
const U& x_labels
)
{
return is_learning_problem_impl(vector_to_matrix(x), vector_to_matrix(x_labels));
return is_learning_problem_impl(mat(x), mat(x_labels));
}
// ----------------------------------------------------------------------------------------
......@@ -93,7 +93,7 @@ namespace dlib
const U& x_labels
)
{
return is_binary_classification_problem_impl(vector_to_matrix(x), vector_to_matrix(x_labels));
return is_binary_classification_problem_impl(mat(x), mat(x_labels));
}
// ----------------------------------------------------------------------------------------
......@@ -171,8 +171,8 @@ namespace dlib
)
{
return test_binary_decision_function_impl(dec_funct,
vector_to_matrix(x_test),
vector_to_matrix(y_test));
mat(x_test),
mat(y_test));
}
// ----------------------------------------------------------------------------------------
......@@ -256,7 +256,7 @@ namespace dlib
{
for (unsigned long i = 0; i < samples.size(); ++i)
{
const unsigned long N = sum(vector_to_matrix(labels[i]) != -1);
const unsigned long N = sum(mat(labels[i]) != -1);
if (std::min(samples[i].first.size(), samples[i].second.size()) != N)
return false;
}
......@@ -418,8 +418,8 @@ namespace dlib
)
{
return cross_validate_trainer_impl(trainer,
vector_to_matrix(x),
vector_to_matrix(y),
mat(x),
mat(y),
folds);
}
......@@ -600,8 +600,8 @@ namespace dlib
);
// count the number of positive and negative examples
const long num_pos = (long)sum(vector_to_matrix(y) > 0);
const long num_neg = (long)sum(vector_to_matrix(y) < 0);
const long num_pos = (long)sum(mat(y) > 0);
const long num_neg = (long)sum(mat(y) < 0);
// figure out how many positive and negative examples we will have in each fold
const long num_pos_test_samples = num_pos/folds;
......
......@@ -30,8 +30,8 @@ namespace dlib
);
/*!
requires
- T == a matrix or something convertible to a matrix via vector_to_matrix()
- U == a matrix or something convertible to a matrix via vector_to_matrix()
- T == a matrix or something convertible to a matrix via mat()
- U == a matrix or something convertible to a matrix via mat()
ensures
- returns true if all of the following are true and false otherwise:
- is_col_vector(x) == true
......@@ -50,8 +50,8 @@ namespace dlib
);
/*!
requires
- T == a matrix or something convertible to a matrix via vector_to_matrix()
- U == a matrix or something convertible to a matrix via vector_to_matrix()
- T == a matrix or something convertible to a matrix via mat()
- U == a matrix or something convertible to a matrix via mat()
ensures
- returns true if all of the following are true and false otherwise:
- is_learning_problem(x, x_labels) == true
......
......@@ -149,15 +149,15 @@ namespace dlib
)
{
// make sure requires clause is not broken
DLIB_ASSERT(basis_samples.size() > 0 && is_vector(vector_to_matrix(basis_samples)),
DLIB_ASSERT(basis_samples.size() > 0 && is_vector(mat(basis_samples)),
"\tvoid svm_c_ekm_trainer::set_basis(basis_samples)"
<< "\n\t You have to give a non-empty set of basis_samples and it must be a vector"
<< "\n\t basis_samples.size(): " << basis_samples.size()
<< "\n\t is_vector(vector_to_matrix(basis_samples)): " << is_vector(vector_to_matrix(basis_samples))
<< "\n\t is_vector(mat(basis_samples)): " << is_vector(mat(basis_samples))
<< "\n\t this: " << this
);
basis = vector_to_matrix(basis_samples);
basis = mat(basis_samples);
ekm_stale = true;
}
......@@ -311,9 +311,9 @@ namespace dlib
{
scalar_type obj;
if (basis_loaded())
return do_train_user_basis(vector_to_matrix(x),vector_to_matrix(y),obj);
return do_train_user_basis(mat(x),mat(y),obj);
else
return do_train_auto_basis(vector_to_matrix(x),vector_to_matrix(y),obj);
return do_train_auto_basis(mat(x),mat(y),obj);
}
template <
......@@ -327,9 +327,9 @@ namespace dlib
) const
{
if (basis_loaded())
return do_train_user_basis(vector_to_matrix(x),vector_to_matrix(y),svm_objective);
return do_train_user_basis(mat(x),mat(y),svm_objective);
else
return do_train_auto_basis(vector_to_matrix(x),vector_to_matrix(y),svm_objective);
return do_train_auto_basis(mat(x),mat(y),svm_objective);
}
......
......@@ -169,7 +169,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
......@@ -324,9 +324,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 C support vector classifier given the training samples in x and
......@@ -355,9 +355,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 C support vector classifier given the training samples in x and
......
......@@ -441,7 +441,7 @@ namespace dlib
) const
{
optimizer_state state;
return do_train(vector_to_matrix(x), vector_to_matrix(y), state);
return do_train(mat(x), mat(y), state);
}
template <
......@@ -454,7 +454,7 @@ namespace dlib
optimizer_state& state
) const
{
return do_train(vector_to_matrix(x), vector_to_matrix(y), state);
return do_train(mat(x), mat(y), state);
}
private:
......
......@@ -264,9 +264,9 @@ namespace dlib
- is_learning_problem(x,y) == true
(Note that it is ok for x.size() == 1)
- All elements of y must be equal to +1 or -1
- 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 C support vector classifier given the training samples in x and
......@@ -319,9 +319,9 @@ namespace dlib
- max_index_plus_one(x) == max_index_plus_one(X)
- else
- max_index_plus_one(x) >= max_index_plus_one(X)
- 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 C support vector classifier given the training samples in x and
......
......@@ -511,7 +511,7 @@ namespace dlib
) const
{
scalar_type obj;
return do_train(vector_to_matrix(x),vector_to_matrix(y),obj);
return do_train(mat(x),mat(y),obj);
}
......@@ -525,7 +525,7 @@ namespace dlib
scalar_type& svm_objective
) const
{
return do_train(vector_to_matrix(x),vector_to_matrix(y),svm_objective);
return do_train(mat(x),mat(y),svm_objective);
}
private:
......
......@@ -236,9 +236,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 C support vector classifier given the training samples in x and
......@@ -265,9 +265,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 C support vector classifier given the training samples in x and
......
......@@ -178,7 +178,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 (
......
......@@ -195,9 +195,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 C support vector classifier given the training samples in x and
......
......@@ -75,7 +75,7 @@ namespace dlib
psi.push_back(std::make_pair(dims-1,static_cast<scalar_type>(-1)));
// Find which distinct label goes with this psi.
const long label_idx = index_of_max(vector_to_matrix(distinct_labels) == labels[idx]);
const long label_idx = index_of_max(mat(distinct_labels) == labels[idx]);
offset_feature_vector(psi, dims*label_idx);
}
......@@ -96,7 +96,7 @@ namespace dlib
{
// Compute the F(x,y) part:
// perform: temp == dot(relevant part of current solution, samples[idx]) - current_bias
scalar_type temp = dot(pointer_to_column_vector(&current_solution(i*dims),dims-1), samples[idx]) - current_solution((i+1)*dims-1);
scalar_type temp = dot(mat(&current_solution(i*dims),dims-1), samples[idx]) - current_solution((i+1)*dims-1);
// Add the LOSS(idx,y) part:
if (labels[idx] != distinct_labels[i])
......
......@@ -138,7 +138,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 (
......
......@@ -164,9 +164,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 nu support vector classifier given the training samples in x and
......
......@@ -133,7 +133,7 @@ namespace dlib
const in_sample_vector_type& x
) const
{
return do_train(vector_to_matrix(x));
return do_train(mat(x));
}
void swap (
......
......@@ -160,7 +160,7 @@ namespace dlib
requires
- x.size() > 0
- is_col_vector(x) == 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.
ensures
- trains a one-class support vector classifier given the training samples in x.
......
......@@ -237,8 +237,8 @@ namespace dlib
)
{
return cross_validate_trainer_threaded_impl(trainer,
vector_to_matrix(x),
vector_to_matrix(y),
mat(x),
mat(y),
folds,
num_threads);
}
......
......@@ -140,7 +140,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 (
......
......@@ -170,9 +170,9 @@ namespace dlib
/*!
requires
- is_learning_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
- performs support vector regression given the training samples in x and
......
......@@ -315,9 +315,9 @@ namespace
for (unsigned long i = 0; i < samples.size(); ++i)
{
std::vector<long> out = ass(samples[i]);
dlog << LINFO << "true labels: " << trans(vector_to_matrix(labels[i]));
dlog << LINFO << "pred labels: " << trans(vector_to_matrix(out));
DLIB_TEST(trans(vector_to_matrix(labels[i])) == trans(vector_to_matrix(out)));
dlog << LINFO << "true labels: " << trans(mat(labels[i]));
dlog << LINFO << "pred labels: " << trans(mat(out));
DLIB_TEST(trans(mat(labels[i])) == trans(mat(out)));
}
double accuracy;
......@@ -343,9 +343,9 @@ namespace
for (unsigned long i = 0; i < samples.size(); ++i)
{
std::vector<long> out = ass2(samples[i]);
dlog << LINFO << "true labels: " << trans(vector_to_matrix(labels[i]));
dlog << LINFO << "pred labels: " << trans(vector_to_matrix(out));
DLIB_TEST(trans(vector_to_matrix(labels[i])) == trans(vector_to_matrix(out)));
dlog << LINFO << "true labels: " << trans(mat(labels[i]));
dlog << LINFO << "pred labels: " << trans(mat(out));
DLIB_TEST(trans(mat(labels[i])) == trans(mat(out)));
}
}
......
......@@ -541,7 +541,7 @@ namespace
dlog << LINFO << "score MAP: " << score2;
DLIB_TEST(std::abs(score1 - score2) < 1e-10);
DLIB_TEST(vector_to_matrix(map_assignment1) == vector_to_matrix(map_assignment2));
DLIB_TEST(mat(map_assignment1) == mat(map_assignment2));
}
// ----------------------------------------------------------------------------------------
......@@ -568,10 +568,10 @@ namespace
dlog << LINFO << "score NMPLP: " << score1;
dlog << LINFO << "score MAP: " << score2;
dlog << LINFO << "MAP assignment: "<< trans(vector_to_matrix(map_assignment1));
dlog << LINFO << "MAP assignment: "<< trans(mat(map_assignment1));
DLIB_TEST(std::abs(score1 - score2) < 1e-10);
DLIB_TEST(vector_to_matrix(map_assignment1) == vector_to_matrix(map_assignment2));
DLIB_TEST(mat(map_assignment1) == mat(map_assignment2));
}
// ----------------------------------------------------------------------------------------
......
......@@ -131,9 +131,9 @@ namespace
brute_force_find_max_factor_graph_viterbi(prob, assign);
find_max_factor_graph_viterbi(prob, assign2);
DLIB_TEST_MSG(vector_to_matrix(assign) == vector_to_matrix(assign2),
trans(vector_to_matrix(assign))
<< trans(vector_to_matrix(assign2))
DLIB_TEST_MSG(mat(assign) == mat(assign2),
trans(mat(assign))
<< trans(mat(assign2))
);
}
}
......
......@@ -344,7 +344,7 @@ namespace
// This test is just to make sure the covariance function can compile when used
// on a dlib::vector. The actual test doesn't matter.
DLIB_TEST(sum(covariance(vector_to_matrix(a))) < 10);
DLIB_TEST(sum(covariance(mat(a))) < 10);
}
......@@ -446,7 +446,7 @@ namespace
DLIB_TEST(be.current_element_valid() == false);
DLIB_TEST(be.at_start() == false);
DLIB_TEST(array_to_matrix(img) == array_to_matrix(img2));
DLIB_TEST(mat(img) == mat(img2));
}
}
......@@ -485,7 +485,7 @@ namespace
DLIB_TEST(be.current_element_valid() == false);
DLIB_TEST(be.at_start() == false);
DLIB_TEST(array_to_matrix(img) == array_to_matrix(img2));
DLIB_TEST(mat(img) == mat(img2));
}
}
......@@ -521,7 +521,7 @@ namespace
DLIB_TEST(be.move_next() == false);
DLIB_TEST(be.current_element_valid() == false);
DLIB_TEST(array_to_matrix(img) == array_to_matrix(img2));
DLIB_TEST(mat(img) == mat(img2));
}
}
......
......@@ -57,7 +57,7 @@ namespace
DLIB_TEST(img2.size() == 0);
DLIB_TEST(img2.nr() == 0);
DLIB_TEST(img2.nc() == 0);
assign_image(img2, array_to_matrix(img1));
assign_image(img2, mat(img1));
DLIB_TEST_MSG(img1.nr() == 100 && img1.nc() == 100 &&
img2.nr() == 100 && img2.nc() == 100,"");
......@@ -669,22 +669,22 @@ namespace
assign_border_pixels(img, 2,2, 4);
DLIB_TEST(zeros_matrix<unsigned char>(6,6) == subm(array_to_matrix(img), rectangle(2,2,7,7)));
DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(array_to_matrix(img), 0));
DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(array_to_matrix(img), 1));
DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(array_to_matrix(img), 8));
DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(array_to_matrix(img), 9));
DLIB_TEST(zeros_matrix<unsigned char>(6,6) == subm(mat(img), rectangle(2,2,7,7)));
DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(mat(img), 0));
DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(mat(img), 1));
DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(mat(img), 8));
DLIB_TEST(uniform_matrix<unsigned char>(1,10, 4) == rowm(mat(img), 9));
DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(array_to_matrix(img), 0));
DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(array_to_matrix(img), 1));
DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(array_to_matrix(img), 8));
DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(array_to_matrix(img), 9));
DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(mat(img), 0));
DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(mat(img), 1));
DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(mat(img), 8));
DLIB_TEST(uniform_matrix<unsigned char>(10,1, 4) == colm(mat(img), 9));
assign_border_pixels(img, 7, 7, 5);
DLIB_TEST(uniform_matrix<unsigned char>(10,10, 5) == array_to_matrix(img));
DLIB_TEST(uniform_matrix<unsigned char>(10,10, 5) == mat(img));
assign_border_pixels(img, 37, 47, 5);
DLIB_TEST(uniform_matrix<unsigned char>(10,10, 5) == array_to_matrix(img));
DLIB_TEST(uniform_matrix<unsigned char>(10,10, 5) == mat(img));
}
{
......@@ -694,21 +694,21 @@ namespace
assign_border_pixels(img, 2,2, 4);
DLIB_TEST(zeros_matrix<unsigned char>(7,7) == subm(array_to_matrix(img), rectangle(2,2,8,8)));
DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(array_to_matrix(img), 0));
DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(array_to_matrix(img), 1));
DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(array_to_matrix(img), 9));
DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(array_to_matrix(img), 10));
DLIB_TEST(zeros_matrix<unsigned char>(7,7) == subm(mat(img), rectangle(2,2,8,8)));
DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(mat(img), 0));
DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(mat(img), 1));
DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(mat(img), 9));
DLIB_TEST(uniform_matrix<unsigned char>(1,11, 4) == rowm(mat(img), 10));
DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(array_to_matrix(img), 0));
DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(array_to_matrix(img), 1));
DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(array_to_matrix(img), 9));
DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(array_to_matrix(img), 10));
DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(mat(img), 0));
DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(mat(img), 1));
DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(mat(img), 9));
DLIB_TEST(uniform_matrix<unsigned char>(11,1, 4) == colm(mat(img), 10));
assign_border_pixels(img, 7, 7, 5);
DLIB_TEST(uniform_matrix<unsigned char>(11,11, 5) == array_to_matrix(img));
DLIB_TEST(uniform_matrix<unsigned char>(11,11, 5) == mat(img));
assign_border_pixels(img, 70, 57, 5);
DLIB_TEST(uniform_matrix<unsigned char>(11,11, 5) == array_to_matrix(img));
DLIB_TEST(uniform_matrix<unsigned char>(11,11, 5) == mat(img));
}
......@@ -752,9 +752,9 @@ namespace
point p1(rnd.get_random_32bit_number()%img.nc(), rnd.get_random_32bit_number()%img.nr());
point p2(rnd.get_random_32bit_number()%img.nc(), rnd.get_random_32bit_number()%img.nr());
rectangle rect(p1,p2);
DLIB_TEST(int_img.get_sum_of_area(rect) == sum(subm(matrix_cast<T>(array_to_matrix(img)), rect)));
DLIB_TEST(int_img.get_sum_of_area(rect) == sum(subm(matrix_cast<T>(mat(img)), rect)));
rect = rectangle(p1,p1);
DLIB_TEST(int_img.get_sum_of_area(rect) == sum(subm(matrix_cast<T>(array_to_matrix(img)), rect)));
DLIB_TEST(int_img.get_sum_of_area(rect) == sum(subm(matrix_cast<T>(mat(img)), rect)));
}
}
......@@ -812,7 +812,7 @@ namespace
spatially_filter_image_separable(img, img3, row_filter, col_filter);
DLIB_TEST(array_to_matrix(img2) == array_to_matrix(img3));
DLIB_TEST(mat(img2) == mat(img3));
dlib::rand rnd;
......@@ -844,7 +844,7 @@ namespace
rectangle brect1, brect2;
brect1 = spatially_filter_image(img, img2, filter, scale, use_abs);
brect2 = spatially_filter_image_separable(img, img3, row_filter, col_filter, scale, use_abs);
DLIB_TEST(array_to_matrix(img2) == array_to_matrix(img3));
DLIB_TEST(mat(img2) == mat(img3));
DLIB_TEST(brect1 == shrink_rect(get_rect(img), filter.nc()/2, filter.nr()/2));
DLIB_TEST(brect1 == brect2);
......@@ -1256,13 +1256,13 @@ namespace
spatially_filter_image_separable_down(downsample, img, out2, row_filter, col_filter);
DLIB_TEST(get_rect(out1) == get_rect(out2));
DLIB_TEST(array_to_matrix(out1) == array_to_matrix(out2));
DLIB_TEST(mat(out1) == mat(out2));
test_spatially_filter_image_separable_down_simple(downsample, img, out1, row_filter, col_filter,3, true, true );
spatially_filter_image_separable_down(downsample, img, out2, row_filter, col_filter, 3, true, true);
DLIB_TEST(get_rect(out1) == get_rect(out2));
DLIB_TEST(array_to_matrix(out1) == array_to_matrix(out2));
DLIB_TEST(mat(out1) == mat(out2));
}
}
......
......@@ -70,7 +70,7 @@ namespace
}
}
DLIB_TEST(equal(K, kernel_matrix(kern, vect1, vect2)));
DLIB_TEST(equal(K, kernel_matrix(kern, vector_to_matrix(vect1), vector_to_matrix(vect2))));
DLIB_TEST(equal(K, kernel_matrix(kern, mat(vect1), mat(vect2))));
K.set_size(vect2.size(), vect1.size());
......@@ -83,7 +83,7 @@ namespace
}
DLIB_TEST(equal(K, kernel_matrix(kern, vect2, vect1)));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, vect2, vect1))));
DLIB_TEST(equal(K, kernel_matrix(kern, vector_to_matrix(vect2), vector_to_matrix(vect1))));
DLIB_TEST(equal(K, kernel_matrix(kern, mat(vect2), mat(vect1))));
K.set_size(vect1.size(), vect1.size());
......@@ -98,10 +98,10 @@ namespace
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, vect1, vect1))));
DLIB_TEST(equal(K, kernel_matrix(kern, vect1)));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, vect1))));
DLIB_TEST(equal(K, kernel_matrix(kern, vector_to_matrix(vect1), vector_to_matrix(vect1))));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, vector_to_matrix(vect1), vector_to_matrix(vect1)))));
DLIB_TEST(equal(K, kernel_matrix(kern, vector_to_matrix(vect1))));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, vector_to_matrix(vect1)))));
DLIB_TEST(equal(K, kernel_matrix(kern, mat(vect1), mat(vect1))));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, mat(vect1), mat(vect1)))));
DLIB_TEST(equal(K, kernel_matrix(kern, mat(vect1))));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, mat(vect1)))));
K.set_size(vect1.size(),1);
......@@ -113,7 +113,7 @@ namespace
}
}
DLIB_TEST(equal(K, kernel_matrix(kern, vect1, samp)));
DLIB_TEST(equal(K, kernel_matrix(kern, vector_to_matrix(vect1), samp)));
DLIB_TEST(equal(K, kernel_matrix(kern, mat(vect1), samp)));
K.set_size(1, vect1.size());
......@@ -125,9 +125,9 @@ namespace
}
}
DLIB_TEST(equal(K, kernel_matrix(kern, samp, vect1)));
DLIB_TEST(equal(K, kernel_matrix(kern, samp, vector_to_matrix(vect1))));
DLIB_TEST(equal(K, kernel_matrix(kern, samp, mat(vect1))));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, samp, vect1))));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, samp, vector_to_matrix(vect1)))));
DLIB_TEST(equal(K, tmp(kernel_matrix(kern, samp, mat(vect1)))));
......
......@@ -422,26 +422,26 @@ namespace
DLIB_TEST(rowm(array_to_matrix(a),1).nr() == 1);
DLIB_TEST(rowm(array_to_matrix(a),1).nc() == a.nc());
DLIB_TEST(colm(array_to_matrix(a),1).nr() == a.nr());
DLIB_TEST(colm(array_to_matrix(a),1).nc() == 1);
DLIB_TEST(rowm(mat(a),1).nr() == 1);
DLIB_TEST(rowm(mat(a),1).nc() == a.nc());
DLIB_TEST(colm(mat(a),1).nr() == a.nr());
DLIB_TEST(colm(mat(a),1).nc() == 1);
for (long c = 0; c < a.nc(); ++c)
{
DLIB_TEST( rowm(array_to_matrix(a),1)(c) == 1*a.nc() + c);
DLIB_TEST( rowm(mat(a),1)(c) == 1*a.nc() + c);
}
for (long r = 0; r < a.nr(); ++r)
{
DLIB_TEST( colm(array_to_matrix(a),1)(r) == r*a.nc() + 1);
DLIB_TEST( colm(mat(a),1)(r) == r*a.nc() + 1);
}
for (long r = 0; r < 2; ++r)
{
for (long c = 0; c < 3; ++c)
{
DLIB_TEST(subm(array_to_matrix(a),1,2,2,3)(r,c) == (r+1)*a.nc() + c+2);
DLIB_TEST(subm(mat(a),1,2,2,3)(r,c) == (r+1)*a.nc() + c+2);
}
}
......@@ -461,11 +461,11 @@ namespace
}
matrix<double> mi = pinv(cos(exp(array_to_matrix(m))) );
matrix<double> mi = pinv(cos(exp(mat(m))) );
DLIB_TEST(mi.nr() == m.nc());
DLIB_TEST(mi.nc() == m.nr());
DLIB_TEST((equal(round_zeros(mi*cos(exp(array_to_matrix(m))),0.000001) , identity_matrix<double,5>())));
DLIB_TEST((equal(round_zeros(cos(exp(array_to_matrix(m)))*mi,0.000001) , identity_matrix<double,5>())));
DLIB_TEST((equal(round_zeros(mi*cos(exp(mat(m))),0.000001) , identity_matrix<double,5>())));
DLIB_TEST((equal(round_zeros(cos(exp(mat(m)))*mi,0.000001) , identity_matrix<double,5>())));
}
{
......
......@@ -171,33 +171,33 @@ namespace
for (long i = 0; i < 4; ++i)
stdv[i] = stdv_c[i] = arr[i] = i+1;
DLIB_TEST(vector_to_matrix(stdv)(0) == 1);
DLIB_TEST(vector_to_matrix(stdv)(1) == 2);
DLIB_TEST(vector_to_matrix(stdv)(2) == 3);
DLIB_TEST(vector_to_matrix(stdv)(3) == 4);
DLIB_TEST(vector_to_matrix(stdv).nr() == 4);
DLIB_TEST(vector_to_matrix(stdv).nc() == 1);
DLIB_TEST(vector_to_matrix(stdv).size() == 4);
DLIB_TEST(equal(trans(vector_to_matrix(stdv))*vector_to_matrix(stdv), trans(v)*v));
DLIB_TEST(equal(trans(vector_to_matrix(stdv))*vector_to_matrix(stdv), tmp(trans(v)*v)));
DLIB_TEST(vector_to_matrix(stdv_c)(0) == 1);
DLIB_TEST(vector_to_matrix(stdv_c)(1) == 2);
DLIB_TEST(vector_to_matrix(stdv_c)(2) == 3);
DLIB_TEST(vector_to_matrix(stdv_c)(3) == 4);
DLIB_TEST(vector_to_matrix(stdv_c).nr() == 4);
DLIB_TEST(vector_to_matrix(stdv_c).nc() == 1);
DLIB_TEST(vector_to_matrix(stdv_c).size() == 4);
DLIB_TEST(equal(trans(vector_to_matrix(stdv_c))*vector_to_matrix(stdv_c), trans(v)*v));
DLIB_TEST(vector_to_matrix(arr)(0) == 1);
DLIB_TEST(vector_to_matrix(arr)(1) == 2);
DLIB_TEST(vector_to_matrix(arr)(2) == 3);
DLIB_TEST(vector_to_matrix(arr)(3) == 4);
DLIB_TEST(vector_to_matrix(arr).nr() == 4);
DLIB_TEST(vector_to_matrix(arr).nc() == 1);
DLIB_TEST(vector_to_matrix(arr).size() == 4);
DLIB_TEST(equal(trans(vector_to_matrix(arr))*vector_to_matrix(arr), trans(v)*v));
DLIB_TEST(mat(stdv)(0) == 1);
DLIB_TEST(mat(stdv)(1) == 2);
DLIB_TEST(mat(stdv)(2) == 3);
DLIB_TEST(mat(stdv)(3) == 4);
DLIB_TEST(mat(stdv).nr() == 4);
DLIB_TEST(mat(stdv).nc() == 1);
DLIB_TEST(mat(stdv).size() == 4);
DLIB_TEST(equal(trans(mat(stdv))*mat(stdv), trans(v)*v));
DLIB_TEST(equal(trans(mat(stdv))*mat(stdv), tmp(trans(v)*v)));
DLIB_TEST(mat(stdv_c)(0) == 1);
DLIB_TEST(mat(stdv_c)(1) == 2);
DLIB_TEST(mat(stdv_c)(2) == 3);
DLIB_TEST(mat(stdv_c)(3) == 4);
DLIB_TEST(mat(stdv_c).nr() == 4);
DLIB_TEST(mat(stdv_c).nc() == 1);
DLIB_TEST(mat(stdv_c).size() == 4);
DLIB_TEST(equal(trans(mat(stdv_c))*mat(stdv_c), trans(v)*v));
DLIB_TEST(mat(arr)(0) == 1);
DLIB_TEST(mat(arr)(1) == 2);
DLIB_TEST(mat(arr)(2) == 3);
DLIB_TEST(mat(arr)(3) == 4);
DLIB_TEST(mat(arr).nr() == 4);
DLIB_TEST(mat(arr).nc() == 1);
DLIB_TEST(mat(arr).size() == 4);
DLIB_TEST(equal(trans(mat(arr))*mat(arr), trans(v)*v));
DLIB_TEST(v(0) == 1);
DLIB_TEST(v(1) == 2);
......
......@@ -723,16 +723,16 @@ namespace
std::vector<double> v(34, 8);
std::vector<double> v2(34, 9);
DLIB_TEST(pointer_to_column_vector(&v[0], v.size()) == vector_to_matrix(v));
DLIB_TEST(pointer_to_column_vector(&v2[0], v.size()) != vector_to_matrix(v));
DLIB_TEST(mat(&v[0], v.size()) == mat(v));
DLIB_TEST(mat(&v2[0], v.size()) != mat(v));
}
{
std::vector<long> v(1, 3);
std::vector<long> v2(1, 2);
DLIB_TEST(pointer_to_column_vector(&v[0], v.size()) == vector_to_matrix(v));
DLIB_TEST(pointer_to_column_vector(&v2[0], v.size()) != vector_to_matrix(v));
DLIB_TEST(mat(&v[0], v.size()) == mat(v));
DLIB_TEST(mat(&v2[0], v.size()) != mat(v));
}
{
......@@ -940,7 +940,7 @@ namespace
a = 0, 1, 2,
3, 4, 5;
DLIB_TEST(pointer_to_matrix(&v[0], 2, 3) == a);
DLIB_TEST(mat(&v[0], 2, 3) == a);
}
{
......
......@@ -66,7 +66,7 @@ namespace
oca solver;
// test the version without a non-negativity constraint on w.
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 0);
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 0);
dlog << LINFO << trans(w);
true_w = -0.5, 0.5, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w));
......@@ -75,7 +75,7 @@ namespace
print_spinner();
// test the version with a non-negativity constraint on w.
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 9999);
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 9999);
dlog << LINFO << trans(w);
true_w = 0, 1, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w));
......@@ -91,7 +91,7 @@ namespace
print_spinner();
// test the version with a non-negativity constraint on w.
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 2);
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 2);
dlog << LINFO << trans(w);
true_w = 0, 1, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w));
......@@ -101,7 +101,7 @@ namespace
// test the version with a non-negativity constraint on w.
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 1);
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 1);
dlog << LINFO << trans(w);
true_w = 0, 1, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w));
......@@ -116,7 +116,7 @@ namespace
y.push_back(+1);
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 0);
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 0);
dlog << LINFO << trans(w);
true_w = 0.5, -0.5, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w));
......@@ -124,7 +124,7 @@ namespace
print_spinner();
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 1);
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 1);
dlog << LINFO << trans(w);
true_w = 0.5, -0.5, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w));
......@@ -132,7 +132,7 @@ namespace
print_spinner();
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 2);
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 2);
dlog << LINFO << trans(w);
true_w = 1, 0, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w));
......@@ -140,7 +140,7 @@ namespace
print_spinner();
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, vector_to_matrix(x), vector_to_matrix(y), false, 1e-12, 40), w, 5);
solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 40), w, 5);
dlog << LINFO << trans(w);
true_w = 1, 0, 0;
dlog << LINFO << "error: "<< max(abs(w-true_w));
......
......@@ -58,8 +58,8 @@ namespace
rx.set_max_size(x.size());
ry.set_max_size(x.size());
dlog << LINFO << "pos labels: "<< sum(vector_to_matrix(y) == +1);
dlog << LINFO << "neg labels: "<< sum(vector_to_matrix(y) == -1);
dlog << LINFO << "pos labels: "<< sum(mat(y) == +1);
dlog << LINFO << "neg labels: "<< sum(mat(y) == -1);
for (unsigned long i = 0; i < x.size(); ++i)
{
......
......@@ -44,8 +44,8 @@ void test_pyramid_down_grayscale()
overlap = rect1.intersect(rect2).area() / (double)(rect1 + rect2).area();
DLIB_TEST(overlap > 0.95);
DLIB_TEST(min(array_to_matrix(down)) == 10);
DLIB_TEST(max(array_to_matrix(down)) == 10);
DLIB_TEST(min(mat(down)) == 10);
DLIB_TEST(max(mat(down)) == 10);
}
void test_pyramid_down_rgb()
......@@ -169,11 +169,11 @@ void test_pyramid_down_rgb2()
*/
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(array_to_matrix(img2)),rect1)) - 255/3) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(array_to_matrix(img2)),rect2)) - 255/3) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(array_to_matrix(img2)),rect3)) - 255/3) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(mat(img2)),rect1)) - 255/3) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(mat(img2)),rect2)) - 255/3) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(mat(img2)),rect3)) - 255/3) < 3);
assign_image(img4, img);
DLIB_TEST(std::abs((int)mean(array_to_matrix(img4)) - mean(array_to_matrix(img2))) < 2);
DLIB_TEST(std::abs((int)mean(mat(img4)) - mean(mat(img2))) < 2);
rgb_pixel mean1 = mean_pixel(img3, rect1);
......@@ -256,11 +256,11 @@ void test_pyramid_down_grayscale2()
*/
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(array_to_matrix(img2)),rect1)) - 255) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(array_to_matrix(img2)),rect2)) - 170) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(array_to_matrix(img2)),rect3)) - 100) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(mat(img2)),rect1)) - 255) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(mat(img2)),rect2)) - 170) < 3);
DLIB_TEST(std::abs((int)mean(subm(matrix_cast<long>(mat(img2)),rect3)) - 100) < 3);
assign_image(img4, img);
DLIB_TEST(std::abs((int)mean(array_to_matrix(img4)) - mean(array_to_matrix(img2))) < 2);
DLIB_TEST(std::abs((int)mean(mat(img4)) - mean(mat(img2))) < 2);
//my_window.wait_until_closed();
......
......@@ -68,8 +68,8 @@ namespace
count_ranking_inversions(x, y, x_count, y_count);
brute_force_count_ranking_inversions(x, y, x_count2, y_count2);
DLIB_TEST(vector_to_matrix(x_count) == vector_to_matrix(x_count2));
DLIB_TEST(vector_to_matrix(y_count) == vector_to_matrix(y_count2));
DLIB_TEST(mat(x_count) == mat(x_count2));
DLIB_TEST(mat(y_count) == mat(y_count2));
}
}
......
......@@ -139,7 +139,7 @@ namespace
strip = strip.intersect(get_rect(img));
if (!strip.is_empty())
{
column_sums[i][j] = sum(matrix_cast<ptype>(subm(array_to_matrix(img),strip)));
column_sums[i][j] = sum(matrix_cast<ptype>(subm(mat(img),strip)));
}
++left;
......@@ -434,8 +434,8 @@ namespace
sum_filter(img, test1_i, rect);
sum_filter(img, test2_i, rect);
DLIB_TEST(array_to_matrix(test1) == array_to_matrix(test1_i));
DLIB_TEST(array_to_matrix(test2) == array_to_matrix(test2_i));
DLIB_TEST(mat(test1) == mat(test1_i));
DLIB_TEST(mat(test2) == mat(test2_i));
}
}
}
......@@ -462,7 +462,7 @@ namespace
for (long c = 0; c < img.nc(); ++c)
{
const rectangle win = centered_rect(point(c,r),width,height).intersect(area);
out[r][c] += std::max(dlib::max(subm(array_to_matrix(img),win)), thresh);
out[r][c] += std::max(dlib::max(subm(mat(img),win)), thresh);
}
}
}
......@@ -492,7 +492,7 @@ namespace
naive_max_filter(img, out2, rect.width(), rect.height(), thresh);
max_filter(img, out, rect.width(), rect.height(), thresh);
DLIB_TEST_MSG(array_to_matrix(out) == array_to_matrix(out2),
DLIB_TEST_MSG(mat(out) == mat(out2),
"rows: "<< rows
<< "\ncols: "<< rows
<< "\nwidth: "<< width
......
......@@ -307,8 +307,8 @@ namespace
// print out some of the randomly sampled sequences
for (int i = 0; i < 10; ++i)
{
dlog << LINFO << "hidden states: " << trans(vector_to_matrix(labels[i]));
dlog << LINFO << "observed states: " << trans(vector_to_matrix(samples[i].item));
dlog << LINFO << "hidden states: " << trans(mat(labels[i]));
dlog << LINFO << "observed states: " << trans(mat(samples[i].item));
dlog << LINFO << "******************************";
}
......@@ -325,10 +325,10 @@ namespace
sequence_labeler<fe_type> labeler = trainer.train(samples, labels);
std::vector<unsigned long> predicted_labels = labeler(samples[0]);
dlog << LINFO << "true hidden states: "<< trans(vector_to_matrix(labels[0]));
dlog << LINFO << "predicted hidden states: "<< trans(vector_to_matrix(predicted_labels));
dlog << LINFO << "true hidden states: "<< trans(mat(labels[0]));
dlog << LINFO << "predicted hidden states: "<< trans(mat(predicted_labels));
DLIB_TEST(vector_to_matrix(labels[0]) == vector_to_matrix(predicted_labels));
DLIB_TEST(mat(labels[0]) == mat(predicted_labels));
print_spinner();
......
......@@ -114,7 +114,7 @@ namespace
for (unsigned long i = 0; i < samples.size(); ++i)
cur_vals.push_back(df(samples[i]));
const double err = max(abs(vector_to_matrix(cur_vals) - vector_to_matrix(prev_vals)));
const double err = max(abs(mat(cur_vals) - mat(prev_vals)));
dlog << LINFO << "simplify error: "<< err;
DLIB_TEST(err < 1e-13);
......@@ -150,7 +150,7 @@ namespace
for (unsigned long i = 0; i < samples.size(); ++i)
cur_vals.push_back(df(samples[i]));
const double err = max(abs(vector_to_matrix(cur_vals) - vector_to_matrix(prev_vals)));
const double err = max(abs(mat(cur_vals) - mat(prev_vals)));
dlog << LINFO << "simplify error: "<< err;
DLIB_TEST(err < 1e-13);
......@@ -189,7 +189,7 @@ namespace
for (unsigned long i = 0; i < dense_samples.size(); ++i)
cur_vals.push_back(dense_df(dense_samples[i]));
const double err = max(abs(vector_to_matrix(cur_vals) - vector_to_matrix(prev_vals)));
const double err = max(abs(mat(cur_vals) - mat(prev_vals)));
dlog << LINFO << "simplify error: "<< err;
DLIB_TEST(err < 1e-13);
}
......@@ -228,7 +228,7 @@ namespace
for (unsigned long i = 0; i < dense_samples.size(); ++i)
cur_vals.push_back(dense_df(dense_samples[i]));
const double err = max(abs(vector_to_matrix(cur_vals) - vector_to_matrix(prev_vals)));
const double err = max(abs(mat(cur_vals) - mat(prev_vals)));
dlog << LINFO << "simplify error: "<< err;
DLIB_TEST(err < 1e-13);
}
......@@ -275,7 +275,7 @@ namespace
for (unsigned long i = 0; i < dense_samples.size(); ++i)
cur_vals.push_back(simple_df(dense_samples[i]));
const double err = max(abs(vector_to_matrix(cur_vals) - vector_to_matrix(prev_vals)));
const double err = max(abs(mat(cur_vals) - mat(prev_vals)));
dlog << LINFO << "simplify error: "<< err;
DLIB_TEST(err < 1e-13);
......
......@@ -155,9 +155,9 @@ namespace
}
DLIB_TEST(cov.in_vector_size() == (long)dims);
DLIB_TEST(equal(mean(vector_to_matrix(vects)), cov.mean()));
DLIB_TEST_MSG(equal(covariance(vector_to_matrix(vects)), cov.covariance()),
max(abs(covariance(vector_to_matrix(vects)) - cov.covariance()))
DLIB_TEST(equal(mean(mat(vects)), cov.mean()));
DLIB_TEST_MSG(equal(covariance(mat(vects)), cov.covariance()),
max(abs(covariance(mat(vects)) - cov.covariance()))
<< " dims = " << dims << " samps = " << samps
);
}
......@@ -182,9 +182,9 @@ namespace
}
DLIB_TEST((cov+cov2).in_vector_size() == (long)dims);
DLIB_TEST(equal(mean(vector_to_matrix(vects)), (cov+cov2).mean()));
DLIB_TEST_MSG(equal(covariance(vector_to_matrix(vects)), (cov+cov2).covariance()),
max(abs(covariance(vector_to_matrix(vects)) - (cov+cov2).covariance()))
DLIB_TEST(equal(mean(mat(vects)), (cov+cov2).mean()));
DLIB_TEST_MSG(equal(covariance(mat(vects)), (cov+cov2).covariance()),
max(abs(covariance(mat(vects)) - (cov+cov2).covariance()))
<< " dims = " << dims << " samps = " << samps
);
}
......@@ -298,9 +298,9 @@ namespace
a.push_back(i);
}
DLIB_TEST(std::abs(variance(vector_to_matrix(a)) - rs1.variance()) < 1e-13);
DLIB_TEST(std::abs(stddev(vector_to_matrix(a)) - rs1.stddev()) < 1e-13);
DLIB_TEST(std::abs(mean(vector_to_matrix(a)) - rs1.mean()) < 1e-13);
DLIB_TEST(std::abs(variance(mat(a)) - rs1.variance()) < 1e-13);
DLIB_TEST(std::abs(stddev(mat(a)) - rs1.stddev()) < 1e-13);
DLIB_TEST(std::abs(mean(mat(a)) - rs1.mean()) < 1e-13);
for (int i = 10; i < 20; ++i)
{
......@@ -308,8 +308,8 @@ namespace
a.push_back(i);
}
DLIB_TEST(std::abs(variance(vector_to_matrix(a)) - (rs1+rs2).variance()) < 1e-13);
DLIB_TEST(std::abs(mean(vector_to_matrix(a)) - (rs1+rs2).mean()) < 1e-13);
DLIB_TEST(std::abs(variance(mat(a)) - (rs1+rs2).variance()) < 1e-13);
DLIB_TEST(std::abs(mean(mat(a)) - (rs1+rs2).mean()) < 1e-13);
DLIB_TEST((rs1+rs2).current_n() == 20);
running_scalar_covariance<double> rc1, rc2, rc3;
......
......@@ -69,7 +69,7 @@ namespace
psi.push_back(std::make_pair(dims-1,static_cast<scalar_type>(-1)));
// Find which distinct label goes with this psi.
const long label_idx = index_of_max(vector_to_matrix(distinct_labels) == labels[idx]);
const long label_idx = index_of_max(mat(distinct_labels) == labels[idx]);
offset_feature_vector(psi, dims*label_idx);
}
......
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