[LIBXGBOOST] pass demo running.

This commit is contained in:
tqchen
2016-01-05 21:49:48 -08:00
parent cee148ed64
commit d75e3ed05d
59 changed files with 1611 additions and 1845 deletions

View File

@@ -16,6 +16,15 @@
#define XGBOOST_STRICT_R_MODE 0
#endif
/*!
* \brief Whether always log console message with time.
* It will display like, with timestamp appended to head of the message.
* "[21:47:50] 6513x126 matrix with 143286 entries loaded from ../data/agaricus.txt.train"
*/
#ifndef XGBOOST_LOG_WITH_TIME
#define XGBOOST_LOG_WITH_TIME 0
#endif
/*! \brief namespace of xgboo st*/
namespace xgboost {
/*!
@@ -23,6 +32,8 @@ namespace xgboost {
* used for feature index and row index.
*/
typedef uint32_t bst_uint;
/*! \brief long integers */
typedef unsigned long bst_ulong; // NOLINT(*)
/*! \brief float type, used for storing statistics */
typedef float bst_float;

View File

@@ -36,13 +36,6 @@ typedef void *BoosterHandle;
*/
XGB_DLL const char *XGBGetLastError();
/*!
* \brief Entry point of CLI program.
* \param argc The number of arguments.
* \param argv The command line arguments.
*/
XGB_DLL int XGBoostCLIMain(int argc, char* argv[])
/*!
* \brief load a data matrix
* \param fname the name of the file

View File

@@ -59,7 +59,7 @@ struct MetaInfo {
/*! \brief version flag, used to check version of this info */
static const int kVersion = 1;
/*! \brief default constructor */
MetaInfo() : num_row(0), num_col(0) {}
MetaInfo() : num_row(0), num_col(0), num_nonzero(0) {}
/*!
* \brief Get weight of each instances.
* \param i Instance index.
@@ -96,14 +96,6 @@ struct MetaInfo {
* \param num Number of elements in the source array.
*/
void SetInfo(const char* key, const void* dptr, DataType dtype, size_t num);
/*!
* \brief Get information from meta info.
* \param key The key of the information.
* \param dptr The output data pointer of the source array.
* \param dtype The output data type of the information array.
* \param num Number of elements in the array.
*/
void GetInfo(const char* key, const void** dptr, DataType* dtype, size_t* num) const;
};
/*! \brief read-only sparse instance batch in CSR format */
@@ -259,11 +251,14 @@ class DMatrix {
* \param uri The URI of input.
* \param silent Whether print information during loading.
* \param load_row_split Flag to read in part of rows, divided among the workers in distributed mode.
* \param file_format The format type of the file, used for dmlc::Parser::Create.
* By default "auto" will be able to load in both local binary file.
* \return The created DMatrix.
*/
static DMatrix* Load(const std::string& uri,
bool silent,
bool load_row_split);
bool load_row_split,
const std::string& file_format = "auto");
/*!
* \brief create a new DMatrix, by wrapping a row_iterator, and meta info.
* \param source The source iterator of the data, the create function takes ownership of the source.
@@ -273,7 +268,7 @@ class DMatrix {
* \return a Created DMatrix.
*/
static DMatrix* Create(std::unique_ptr<DataSource>&& source,
const char* cache_prefix = nullptr);
const std::string& cache_prefix = "");
/*!
* \brief Create a DMatrix by loaidng data from parser.
* Parser can later be deleted after the DMatrix i created.
@@ -287,7 +282,7 @@ class DMatrix {
* \return A created DMatrix.
*/
static DMatrix* Create(dmlc::Parser<uint32_t>* parser,
const char* cache_prefix = nullptr);
const std::string& cache_prefix = "");
private:
// allow learner class to access this field.

View File

@@ -163,7 +163,7 @@ struct GradientBoosterReg
*/
#define XGBOOST_REGISTER_GBM(UniqueId, Name) \
static ::xgboost::GradientBoosterReg & __make_ ## GradientBoosterReg ## _ ## UniqueId ## __ = \
::dmlc::Registry< ::xgboost::GradientBoosterReg>::Get()->__REGISTER__(#Name)
::dmlc::Registry< ::xgboost::GradientBoosterReg>::Get()->__REGISTER__(Name)
} // namespace xgboost
#endif // XGBOOST_GBM_H_

View File

@@ -36,6 +36,8 @@ namespace xgboost {
*/
class Learner : public rabit::Serializable {
public:
/*! \brief virtual destructor */
virtual ~Learner() {}
/*!
* \brief set configuration from pair iterators.
* \param begin The beginning iterator.
@@ -51,6 +53,11 @@ class Learner : public rabit::Serializable {
* \param cfg configurations on both training and model parameters.
*/
virtual void Configure(const std::vector<std::pair<std::string, std::string> >& cfg) = 0;
/*!
* \brief Initialize the model using the specified configurations via Configure.
* An model have to be either Loaded or initialized before Update/Predict/Save can be called.
*/
virtual void InitModel() = 0;
/*!
* \brief load model from stream
* \param fi input stream.

50
include/xgboost/logging.h Normal file
View File

@@ -0,0 +1,50 @@
/*!
* Copyright (c) 2015 by Contributors
* \file logging.h
* \brief defines console logging options for xgboost.
* Use to enforce unified print behavior.
* For debug loggers, use LOG(INFO) and LOG(ERROR).
*/
#ifndef XGBOOST_LOGGING_H_
#define XGBOOST_LOGGING_H_
#include <dmlc/logging.h>
#include <sstream>
#include "./base.h"
namespace xgboost {
class BaseLogger {
public:
BaseLogger() {
#if XGBOOST_LOG_WITH_TIME
log_stream_ << "[" << dmlc::DateLogger().HumanDate() << "] ";
#endif
}
std::ostream& stream() { return log_stream_; }
protected:
std::ostringstream log_stream_;
};
class ConsoleLogger : public BaseLogger {
public:
~ConsoleLogger();
};
class TrackerLogger : public BaseLogger {
public:
~TrackerLogger();
};
// redefines the logging macro if not existed
#ifndef LOG
#define LOG(severity) LOG_##severity.stream()
#endif
// Enable LOG(CONSOLE) for print messages to console.
#define LOG_CONSOLE ::xgboost::ConsoleLogger()
// Enable LOG(TRACKER) for print messages to tracker
#define LOG_TRACKER ::xgboost::TrackerLogger()
} // namespace xgboost.
#endif // XGBOOST_LOGGING_H_

View File

@@ -70,7 +70,7 @@ struct MetricReg
* \endcode
*/
#define XGBOOST_REGISTER_METRIC(UniqueId, Name) \
static ::xgboost::MetricReg & __make_ ## MetricReg ## _ ## UniqueId ## __ = \
::dmlc::Registry< ::xgboost::MetricReg>::Get()->__REGISTER__(#Name)
::xgboost::MetricReg& __make_ ## MetricReg ## _ ## UniqueId ## __ = \
::dmlc::Registry< ::xgboost::MetricReg>::Get()->__REGISTER__(Name)
} // namespace xgboost
#endif // XGBOOST_METRIC_H_

View File

@@ -106,6 +106,6 @@ struct ObjFunctionReg
*/
#define XGBOOST_REGISTER_OBJECTIVE(UniqueId, Name) \
static ::xgboost::ObjFunctionReg & __make_ ## ObjFunctionReg ## _ ## UniqueId ## __ = \
::dmlc::Registry< ::xgboost::ObjFunctionReg>::Get()->__REGISTER__(#Name)
::dmlc::Registry< ::xgboost::ObjFunctionReg>::Get()->__REGISTER__(Name)
} // namespace xgboost
#endif // XGBOOST_OBJECTIVE_H_

View File

@@ -8,7 +8,6 @@
#define XGBOOST_TREE_MODEL_H_
#include <dmlc/io.h>
#include <dmlc/logging.h>
#include <dmlc/parameter.h>
#include <limits>
#include <vector>
@@ -17,6 +16,7 @@
#include <algorithm>
#include "./base.h"
#include "./data.h"
#include "./logging.h"
#include "./feature_map.h"
namespace xgboost {

View File

@@ -79,7 +79,7 @@ struct TreeUpdaterReg
*/
#define XGBOOST_REGISTER_TREE_UPDATER(UniqueId, Name) \
static ::xgboost::TreeUpdaterReg& __make_ ## TreeUpdaterReg ## _ ## UniqueId ## __ = \
::dmlc::Registry< ::xgboost::TreeUpdaterReg>::Get()->__REGISTER__(#Name)
::dmlc::Registry< ::xgboost::TreeUpdaterReg>::Get()->__REGISTER__(Name)
} // namespace xgboost
#endif // XGBOOST_TREE_UPDATER_H_