Skip to content

Commit 64d2a5a

Browse files
committed
[+] docstrings
1 parent 5f415f4 commit 64d2a5a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lgensemble.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"fmt"
55
)
66

7-
// LGEnsemble ..
7+
// LGEnsemble is LightGBM model (ensemble of trees)
88
type LGEnsemble struct {
99
Trees []LGTree
1010
MaxFeatureIdx uint32
@@ -14,6 +14,10 @@ func (e *LGEnsemble) NTrees() int {
1414
return len(e.Trees)
1515
}
1616

17+
// Predict calculates prediction from ensembles of trees. Only `nTrees` first
18+
// trees will be used. If `len(fvals)` is not enough function will quitely
19+
// return 0.0. Note, that result is a raw score (before sigmoid function
20+
// transformation and etc)
1721
func (e *LGEnsemble) Predict(fvals []float64, nTrees int) float64 {
1822
if e.MaxFeatureIdx+1 > uint32(len(fvals)) {
1923
return 0.0
@@ -31,6 +35,11 @@ func (e *LGEnsemble) Predict(fvals []float64, nTrees int) float64 {
3135
return ret
3236
}
3337

38+
// PredictCSR calculates predictions from ensembles of trees. `indptr`, `cols`,
39+
// `vals` represent data structures from Compressed Sparse Row Matrix format (see CSRMat).
40+
// Only `nTrees` first trees will be used.
41+
// Note, that result is a raw score (before sigmoid function transofrmation and etc).
42+
// Note, `predictions` slice should be properly allocated on call side
3443
func (e *LGEnsemble) PredictCSR(indptr []uint32, cols []uint32, vals []float64, predictions []float64, nTrees int) {
3544
fvals := make([]float64, e.MaxFeatureIdx+1)
3645
for i := 0; i < len(indptr)-1; i++ {
@@ -50,6 +59,11 @@ func (e *LGEnsemble) PredictCSR(indptr []uint32, cols []uint32, vals []float64,
5059
}
5160
}
5261

62+
// PredictDense calculates predictions from ensembles of trees. `vals`, `rows`,
63+
// `cols` represent data structures from Rom Major Matrix format (see DenseMat).
64+
// Only `nTrees` first trees will be used.
65+
// Note, that result is a raw score (before sigmoid function transofrmation and etc).
66+
// Note, `predictions` slice should be properly allocated on call side
5367
func (e *LGEnsemble) PredictDense(vals []float64, nrows uint32, ncols uint32, predictions []float64, nTrees int) error {
5468
if ncols == 0 || e.MaxFeatureIdx > ncols-1 {
5569
return fmt.Errorf("incorrect number of columns")

mat.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import (
44
"fmt"
55
)
66

7+
// DenseMat is dense matrix data structure
78
type DenseMat struct {
89
Values []float64
910
Cols uint32
1011
Rows uint32
1112
}
1213

14+
// DenseMatFromArray converts arrays of `values` to DenseMat using shape
15+
// information `rows` and `cols`
1316
func DenseMatFromArray(values []float64, rows uint32, cols uint32) (DenseMat, error) {
1417
mat := DenseMat{}
1518
if uint32(len(values)) != cols*rows {
@@ -21,19 +24,23 @@ func DenseMatFromArray(values []float64, rows uint32, cols uint32) (DenseMat, er
2124
return mat, nil
2225
}
2326

27+
// CSRMat is Compressed Sparse Row matrix data structure
2428
type CSRMat struct {
2529
RowHeaders []uint32
2630
ColIndexes []uint32
2731
Values []float64
2832
}
2933

34+
// Rows returns number of rows in the matrix
3035
func (m *CSRMat) Rows() uint32 {
3136
if len(m.RowHeaders) == 0 {
3237
return 0
3338
}
3439
return uint32(len(m.RowHeaders)) - 1
3540
}
3641

42+
// CSRMatFromArray converts arrays of `values` to CSRMat using shape information
43+
// `rows` and `cols`. See also DenseMatFromArray to store dense data in matrix
3744
func CSRMatFromArray(values []float64, rows uint32, cols uint32) (CSRMat, error) {
3845
mat := CSRMat{}
3946
if uint32(len(values)) != cols*rows {

0 commit comments

Comments
 (0)