Skip to content

Commit

Permalink
Merge pull request #426 from pockerman/ml_framework
Browse files Browse the repository at this point in the history
API fixtures and improvements
  • Loading branch information
pockerman authored Aug 7, 2021
2 parents 2c44a4b + 3424c28 commit 56e9cf0
Show file tree
Hide file tree
Showing 16 changed files with 282 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "kernel/numerics/optimization/gd_control.h"
#include "kernel/maths/errorfunctions/error_function_type.h"
#include "kernel/numerics/optimization/optimizer_type.h"
#include "kernel/utilities/algorithm_info.h"
#include "kernel/utilities/iterative_algorithm_result.h"

#include <vector>
#include <map>
Expand All @@ -27,7 +27,7 @@ using cengine::ml::RegularizerType;
using kernel::numerics::opt::OptimizerType;
using kernel::numerics::opt::GDConfig;
using kernel::ErrorFuncType;
using kernel::AlgInfo;
using kernel::IterativeAlgorithmResult;

struct TestSetLoader{

Expand All @@ -44,7 +44,7 @@ TestSetLoader::load(DynMat<real_t>& mat, DynVec<real_t>& labels, ColsTp& /*colum

struct TestSolver{

typedef AlgInfo output_t;
typedef IterativeAlgorithmResult output_t;

template<typename MatTyp, typename LabelTp, typename FunTp>
output_t solve(MatTyp& /*mat*/, LabelTp& /*labels*/, FunTp& /*columns*/) const{return output_t();}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "kernel/numerics/optimization/gd_control.h"
#include "kernel/maths/errorfunctions/error_function_type.h"
#include "kernel/numerics/optimization/optimizer_type.h"
#include "kernel/utilities/algorithm_info.h"
#include "kernel/utilities/iterative_algorithm_result.h"

#include <vector>
#include <map>
Expand All @@ -26,7 +26,7 @@ using cengine::ml::LogisticRegression;
using kernel::numerics::opt::OptimizerType;
using kernel::numerics::opt::GDConfig;
using kernel::ErrorFuncType;
using kernel::AlgInfo;
using kernel::IterativeAlgorithmResult;

struct TestSetLoader{

Expand All @@ -43,7 +43,7 @@ TestSetLoader::load(DynMat<real_t>& mat, DynVec<real_t>& labels, ColsTp& /*colum

struct TestSolver{

typedef AlgInfo output_t;
typedef IterativeAlgorithmResult output_t;

template<typename MatTyp, typename LabelTp, typename FunTp>
output_t solve(MatTyp& /*mat*/, LabelTp& /*labels*/, FunTp& /*columns*/) const{return output_t();}
Expand Down Expand Up @@ -94,7 +94,7 @@ TEST(TestLogisticRegression, DISABLED_Empty_Solver_Type) {
options["solver_options"] = nullptr;

// attempt to fit with an empty dataset
TestSolver solver;
TestSolver solver;
EXPECT_DEATH(regressor.fit(dataset, solver, options), "Solver was not specified");
}
catch(...){
Expand Down
19 changes: 0 additions & 19 deletions kernel/kernel/utilities/src/kernel/utilities/algorithm_info.cpp

This file was deleted.

83 changes: 0 additions & 83 deletions kernel/kernel/utilities/src/kernel/utilities/algorithm_info.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class IterativeAlgorithmController
///
bool show_iterations()const{return show_iterations_;}

///
/// \brief track_residuals
/// \return
///
bool track_residuals()const{return track_residuals_;}

///
/// \brief set_tolerance
/// \param tol
Expand All @@ -65,6 +71,12 @@ class IterativeAlgorithmController
/// \brief show iterations
///
void set_show_iterations_flag(bool flag){show_iterations_ = flag;}

///
/// \brief set_track_residuals_flag
/// \param flag
///
void set_track_residuals_flag(bool flag){track_residuals_ = flag;}

///
/// \brief Set the number of threads
Expand Down Expand Up @@ -129,9 +141,11 @@ class IterativeAlgorithmController
uint_t max_iterations_;
real_t exit_tolerance_;
uint_t current_iteration_idx_;
uint_t n_threads_;
real_t current_res_;
bool show_iterations_;
uint_t n_threads_;
bool track_residuals_;

};

inline
Expand All @@ -140,9 +154,10 @@ IterativeAlgorithmController::IterativeAlgorithmController(uint_t max_iterations
max_iterations_(max_iterations),
exit_tolerance_(exit_tolerance),
current_iteration_idx_(0),
n_threads_(1),
current_res_(std::numeric_limits<real_t>::max()),
show_iterations_(false),
n_threads_(1)
track_residuals_(false)
{}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "kernel/base/types.h"
#include <ostream>
#include <chrono>
#include <vector>

namespace kernel{

Expand Down Expand Up @@ -38,6 +39,11 @@ struct IterativeAlgorithmResult {
///
std::chrono::seconds total_time;

///
/// \brief residuals
///
std::vector<real_t> residuals;

///
/// \brief IterativeAlgorithmResult
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ struct BlazeDirectSolverConfig
DirectSolverType dstype;
};


///
/// \brief The BlazeDirectSolver class. This class is simply
/// a wrapper to the blaze::solve() function.
/// It computes a solution for the given dense linear system of equations (LSE) A*x=b,
/// where A is the given system matrix, x is the solution vector, and b
/// is the given dense right-hand side vector:
///
class BlazeDirectSolver: public DirectSolverBase<DynMat<real_t>, DynVec<real_t>>
{
public:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
#ifndef KRYLOV_SOLVER_OUTPUT_H
#define KRYLOV_SOLVER_OUTPUT_H

#include "kernel/utilities/algorithm_info.h"
#include "kernel/utilities/iterative_algorithm_result.h"
#include "kernel/numerics/krylov_solvers/preconditioner_type.h"
#include "kernel/numerics/krylov_solvers/krylov_solver_type.h"

namespace kernel {
namespace numerics {

struct KrylovSolverResult: public AlgInfo
struct KrylovSolverResult
{
///
/// \brief The type of the preconditioner the solver is using
///
PreconditionerType precondioner_type;

///
/// \brief The type of the solver
///
KrylovSolverType solver_type;

/// \brief Print the information about the performance of
/// the algorithm on the given stream
virtual std::ostream& print(std::ostream& out)const;
std::ostream& print(std::ostream& out)const;

private:

IterativeAlgorithmResult result_;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ KrylovSolverResult::print(std::ostream& out)const{

out<<"Solver: "<<krylov_solver_to_string(solver_type)<<std::endl;
out<<"Preconditioner: "<<preconditioner_to_string(precondioner_type)<<std::endl;
this->AlgInfo::print(out);
result_.print(out);
return out;
}

Expand Down
18 changes: 0 additions & 18 deletions kernel/numerics/src/kernel/numerics/optimization/gd_info.cpp

This file was deleted.

44 changes: 0 additions & 44 deletions kernel/numerics/src/kernel/numerics/optimization/gd_info.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

#include "kernel/base/types.h"
#include "kernel/parallel/utilities/result_holder.h"
#include "kernel/utilities/algorithm_info.h"
#include "kernel/utilities/iterative_algorithm_result.h"
#include "kernel/numerics/optimization/optimizer_type.h"
#include <boost/noncopyable.hpp>

namespace kernel {
Expand All @@ -28,7 +29,7 @@ class OptimizerBase: private boost::noncopyable
/// \brief Expose the type that is returned by this object
/// when calling its solve functions
///
typedef AlgInfo output_t;
typedef IterativeAlgorithmResult output_t;

///
///
Expand All @@ -43,6 +44,12 @@ class OptimizerBase: private boost::noncopyable
///
virtual output_t solve(const data_set_t& features, const labels_set_t& labels, function_t& fnc) = 0;

///
/// \brief type
/// \return
///
virtual OptimizerType type()const=0;

protected:

///
Expand Down
Loading

0 comments on commit 56e9cf0

Please sign in to comment.