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
......@@ -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)));
}
}
......
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