Commit 6efd585e authored by Carlos Ungil's avatar Carlos Ungil

upgrade to lightgbm 2.2.2

parent 8507b154
This source diff could not be displayed because it is too large. You can view the blob instead.
typedef signed long int32_t;
typedef signed long long int64_t;
#ifndef LIGHTGBM_C_API_H_
#define LIGHTGBM_C_API_H_
//#include <LightGBM/meta.h>
#include <cstdint>
#include <exception>
#include <stdexcept>
#include <cstring>
#include <string>
/*!
* To avoid type conversion on large data, most of our expose interface support both for float_32 and float_64.
......@@ -18,8 +16,8 @@
*/
//#include <LightGBM/export.h>
#define LIGHTGBM_C_EXPORT
#include <stdint.h>
#define LIGHTGBM_C_EXPORT
typedef void* DatasetHandle;
typedef void* BoosterHandle;
......@@ -206,6 +204,27 @@ LIGHTGBM_C_EXPORT int LGBM_DatasetCreateFromMat(const void* data,
const DatasetHandle reference,
DatasetHandle* out);
/*!
* \brief create dataset from array of dense matrices
* \param data pointer to the data space
* \param data_type type of data pointer, can be C_API_DTYPE_FLOAT32 or C_API_DTYPE_FLOAT64
* \param nrow number of rows
* \param ncol number columns
* \param parameters additional parameters
* \param reference used to align bin mapper with other dataset, nullptr means don't used
* \param out created dataset
* \return 0 when succeed, -1 when failure happens
*/
LIGHTGBM_C_EXPORT int LGBM_DatasetCreateFromMats(int32_t nmat,
const void** data,
int data_type,
int32_t* nrow,
int32_t ncol,
int is_row_major,
const char* parameters,
const DatasetHandle reference,
DatasetHandle* out);
/*!
* \brief Create subset of a data
* \param handle handle of full dataset
......@@ -357,6 +376,11 @@ LIGHTGBM_C_EXPORT int LGBM_BoosterLoadModelFromString(
*/
LIGHTGBM_C_EXPORT int LGBM_BoosterFree(BoosterHandle handle);
/*!
* \brief Shuffle Models
*/
LIGHTGBM_C_EXPORT int LGBM_BoosterShuffleModels(BoosterHandle handle, int start_iter, int end_iter);
/*!
* \brief Merge model in two booster to first handle
* \param handle handle, will merge other handle to this
......@@ -408,6 +432,16 @@ LIGHTGBM_C_EXPORT int LGBM_BoosterGetNumClasses(BoosterHandle handle, int* out_l
*/
LIGHTGBM_C_EXPORT int LGBM_BoosterUpdateOneIter(BoosterHandle handle, int* is_finished);
/*!
* \brief Refit the tree model using the new data (online learning)
* \param handle handle
* \param leaf_preds
* \param nrow number of rows of leaf_preds
* \param ncol number of columns of leaf_preds
* \return 0 when succeed, -1 when failure happens
*/
LIGHTGBM_C_EXPORT int LGBM_BoosterRefit(BoosterHandle handle, const int32_t* leaf_preds, int32_t nrow, int32_t ncol);
/*!
* \brief update the model, by directly specify gradient and second order gradient,
* this can be used to support customized loss function
......@@ -436,6 +470,20 @@ LIGHTGBM_C_EXPORT int LGBM_BoosterRollbackOneIter(BoosterHandle handle);
*/
LIGHTGBM_C_EXPORT int LGBM_BoosterGetCurrentIteration(BoosterHandle handle, int* out_iteration);
/*!
* \brief Get number of tree per iteration
* \param out_tree_per_iteration number of tree per iteration
* \return 0 when succeed, -1 when failure happens
*/
LIGHTGBM_C_EXPORT int LGBM_BoosterNumModelPerIteration(BoosterHandle handle, int* out_tree_per_iteration);
/*!
* \brief Get number of weak sub-models
* \param out_models number of weak sub-models
* \return 0 when succeed, -1 when failure happens
*/
LIGHTGBM_C_EXPORT int LGBM_BoosterNumberOfTotalModel(BoosterHandle handle, int* out_models);
/*!
* \brief Get number of eval
* \param out_len total number of eval results
......@@ -668,6 +716,7 @@ LIGHTGBM_C_EXPORT int LGBM_BoosterPredictForMat(BoosterHandle handle,
* \return 0 when succeed, -1 when failure happens
*/
LIGHTGBM_C_EXPORT int LGBM_BoosterSaveModel(BoosterHandle handle,
int start_iteration,
int num_iteration,
const char* filename);
......@@ -681,6 +730,7 @@ LIGHTGBM_C_EXPORT int LGBM_BoosterSaveModel(BoosterHandle handle,
* \return 0 when succeed, -1 when failure happens
*/
LIGHTGBM_C_EXPORT int LGBM_BoosterSaveModelToString(BoosterHandle handle,
int start_iteration,
int num_iteration,
int64_t buffer_len,
int64_t* out_len,
......@@ -696,6 +746,7 @@ LIGHTGBM_C_EXPORT int LGBM_BoosterSaveModelToString(BoosterHandle handle,
* \return 0 when succeed, -1 when failure happens
*/
LIGHTGBM_C_EXPORT int LGBM_BoosterDumpModel(BoosterHandle handle,
int start_iteration,
int num_iteration,
int64_t buffer_len,
int64_t* out_len,
......@@ -763,6 +814,12 @@ LIGHTGBM_C_EXPORT int LGBM_NetworkInitWithFunctions(int num_machines, int rank,
void* reduce_scatter_ext_fun,
void* allgather_ext_fun);
#if defined(_MSC_VER)
#define THREAD_LOCAL __declspec(thread)
#else
#define THREAD_LOCAL thread_local
#endif
// exception handle and error msg
static char* LastErrorMsg() { static THREAD_LOCAL char err_msg[512] = "Everything is fine"; return err_msg; }
......@@ -771,21 +828,4 @@ inline void LGBM_SetLastError(const char* msg) {
std::strcpy(LastErrorMsg(), msg);
}
inline int LGBM_APIHandleException(const std::exception& ex) {
LGBM_SetLastError(ex.what());
return -1;
}
inline int LGBM_APIHandleException(const std::string& ex) {
LGBM_SetLastError(ex.c_str());
return -1;
}
#define API_BEGIN() try {
#define API_END() } \
catch(std::exception& ex) { return LGBM_APIHandleException(ex); } \
catch(std::string& ex) { return LGBM_APIHandleException(ex); } \
catch(...) { return LGBM_APIHandleException("unknown exception"); } \
return 0;
#endif // LIGHTGBM_C_API_H_
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,6 +3,11 @@
;; FIXME: LGBM_DatasetCreateFromSampledColumn
;; FIXME: LGBM_DatasetCreateFromCSC
;; FIXME: LGBM_BoosterPredictForCSC
;; FIXME: LGBM_DatasetCreateFromMats
;; FIXME: LGBM_BoosterShuffleModels
;; FIXME: LGBM_BoosterRefit
;; FIXME: LGBM_BoosterNumModelPerIteration
;; FIXME: LGBM_BoosterNumberOfTotalModel
(defmacro with-output-value ((name type) &body body)
`(cffi:with-foreign-object (,name ,type)
......@@ -26,7 +31,7 @@
(unless (zerop x)
(error "~A" (lgbm.ffi:lgbm-get-last-error))))
(defgeneric save (object file &optional iteration))
(defgeneric save (object file &optional start-iteration n-iterations))
(defclass lgbm-pointer ()
((pointer :initarg :pointer :accessor pointer)))
......@@ -43,8 +48,8 @@
(defvar *datasets*
(tg:make-weak-hash-table :weakness :value))
(defmethod save ((dataset lgbm-dataset) file &optional ignore)
(declare (ignore ignore))
(defmethod save ((dataset lgbm-dataset) file &optional start-iteration n-iterations)
(declare (ignore start-iteration n-iterations))
(check-errors (lgbm.ffi:lgbm-dataset-save-binary (pointer dataset) (namestring file))))
(defmethod nrow ((dataset lgbm-dataset))
......@@ -328,28 +333,28 @@
(defparameter *default-buffer-length* 4096)
(defmethod dump-model ((booster lgbm-booster) &optional (iteration 0) ;; 0: save all
(defmethod dump-model ((booster lgbm-booster) &optional (start-iteration 0) (n-iterations 0) ;; 0: save all
(buffer-length *default-buffer-length*))
(cffi:with-foreign-object (buffer :char buffer-length)
(if (< buffer-length
(with-output-value (output-length :int)
(check-errors (lgbm.ffi:lgbm-booster-dump-model (pointer booster) iteration buffer-length output-length buffer))))
(dump-model booster iteration (* 2 buffer-length))
(check-errors (lgbm.ffi:lgbm-booster-dump-model (pointer booster) start-iteration n-iterations buffer-length output-length buffer))))
(dump-model booster start-iteration n-iterations (* 2 buffer-length))
(cffi:foreign-string-to-lisp buffer))))
(defun save-model-to-string (booster &optional (iteration 0) ;; 0: save all
(defun save-model-to-string (booster &optional (start-iteration 0) (n-iterations 0) ;; 0: save all
(buffer-length *default-buffer-length*))
(cffi:with-foreign-object (buffer :char buffer-length)
(if (< buffer-length
(with-output-value (output-length :int)
(check-errors (lgbm.ffi:lgbm-booster-save-model-to-string (pointer booster) iteration buffer-length output-length buffer))))
(save-model-to-string booster iteration (* 2 buffer-length))
(check-errors (lgbm.ffi:lgbm-booster-save-model-to-string (pointer booster) start-iteration n-iterations buffer-length output-length buffer))))
(save-model-to-string booster start-iteration n-iterations (* 2 buffer-length))
(cffi:foreign-string-to-lisp buffer))))
(defmethod save ((booster lgbm-booster) file &optional (iteration 0)) ;; 0: save all
(defmethod save ((booster lgbm-booster) file &optional (start-iteration 0) (n-iterations 0)) ;; 0: save all
(if (or (null file) (eq :string file))
(save-model-to-string booster iteration)
(check-errors (lgbm.ffi:lgbm-booster-save-model (pointer booster) iteration (namestring file)))))
(save-model-to-string booster start-iteration n-iterations)
(check-errors (lgbm.ffi:lgbm-booster-save-model (pointer booster) start-iteration n-iterations (namestring file)))))
(defmethod booster ((file-or-string t) &optional parameters)
(assert (null parameters))
......
......@@ -10,6 +10,12 @@
(when (and (plusp errors) (> len 10) (< errors len))
(terpri)
(warn "FIXME: ~A out of ~A elements ~A different" errors len (if (> errors 1) "are" "is"))
(loop for matches in matching
for i from 0
unless matches
do (print i)
(print (elt a i))
(print (elt b i)))
(terpri))
(every #'identity matching))
(cond ((and (numberp a) (numberp b))
......@@ -72,8 +78,10 @@ feature_names=Column_0 Column_1 Column_2 Column_3 Column_4 Column_5 Column_6 Col
feature_infos=[0.27500000000000002:6.6950000000000003] [-2.4169999999999998:2.4300000000000002] [-1.7429999999999999:1.7429999999999999] [0.019:5.7000000000000002] [-1.7429999999999999:1.7429999999999999] [0.159:4.1900000000000004] [-2.9409999999999998:2.9699999999999998] [-1.7410000000000001:1.7410000000000001] [0:2.173] [0.19:5.1929999999999996] [-2.9039999999999999:2.9089999999999998] [-1.742:1.7429999999999999] [0:2.2149999999999999] [0.26400000000000001:6.5229999999999997] [-2.7279999999999998:2.7269999999999999] [-1.742:1.742] [0:2.548] [0.36499999999999999:6.0679999999999996] [-2.4950000000000001:2.496] [-1.74:1.7429999999999999] [0:3.1019999999999999] [0.17199999999999999:13.098000000000001] [0.41899999999999998:7.3920000000000003] [0.46100000000000002:3.6819999999999999] [0.38400000000000001:6.5830000000000002] [0.092999999999999999:7.8600000000000003] [0.38900000000000001:4.5430000000000001] [0.48899999999999999:4.3159999999999998]
tree_sizes=
end of trees
feature importances:
parameters:
[boosting: gbdt]
[objective: regression]
......@@ -116,6 +124,7 @@ parameters:
[monotone_constraints: ]
[feature_contri: ]
[forcedsplits_filename: ]
[refit_decay_rate: 0.9]
[verbosity: 1]
[max_bin: 255]
[min_data_in_bin: 3]
......@@ -177,6 +186,7 @@ parameters:
[gpu_device_id: -1]
[gpu_use_dp: 0]
end of parameters
")))
(5am:test dump-model
......
......@@ -12,8 +12,8 @@
(autowrap:c-include '(lightgbm ffi "c_api.h") :spec-path '(lightgbm ffi))
(cl:let ((library #-windows (cl:merge-pathnames "LightGBM-2.1.2/lib_lightgbm.so" (cl:user-homedir-pathname))
#+windows (cl:merge-pathnames "LightGBM-2.1.2/windows/x64/DLL/lib_lightgbm.dll"
(cl:let ((library #-windows (cl:merge-pathnames "LightGBM/lib_lightgbm.so" (cl:user-homedir-pathname))
#+windows (cl:merge-pathnames "LightGBM/windows/x64/DLL/lib_lightgbm.dll"
#-sbcl (cl:user-homedir-pathname)
#+sbcl (cl:concatenate 'cl:string (sb-posix:getenv "USERPROFILE") "/"))))
(cffi:load-foreign-library library)
......
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