cuml4go

package module
v0.0.0-...-9f99176 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KMeansPlusPlus = iota
	Random
	Array
)
View Source
const (
	Svd = 0
	Eig = 1
	Qr  = 2
)
View Source
const (
	/** evaluate as dist_ij = sum(x_ik^2) + sum(y_ij)^2 - 2*sum(x_ik * y_jk) */
	L2Expanded = 0
	/** same as above, but inside the epilogue, perform square root operation */
	L2SqrtExpanded = 1
	/** cosine distance */
	CosineExpanded = 2
	/** L1 distance */
	L1 = 3
	/** evaluate as dist_ij += (x_ik - y-jk)^2 */
	L2Unexpanded = 4
	/** same as above, but inside the epilogue, perform square root operation */
	L2SqrtUnexpanded = 5
	/** basic inner product **/
	InnerProduct = 6
	/** Chebyshev (Linf) distance **/
	Linf = 7
	/** Canberra distance **/
	Canberra = 8
	/** Generalized Minkowski distance **/
	LpUnexpanded = 9
	/** Correlation distance **/
	CorrelationExpanded = 10
	/** Jaccard distance **/
	JaccardExpanded = 11
	/** Hellinger distance **/
	HellingerExpanded = 12
	/** Haversine distance **/
	Haversine = 13
	/** Bray-Curtis distance **/
	BrayCurtis = 14
	/** Jensen-Shannon distance**/
	JensenShannon = 15
	/** Hamming distance **/
	HammingUnexpanded = 16
	/** KLDivergence **/
	KLDivergence = 17
	/** RusselRao **/
	RusselRaoExpanded = 18
	/** Dice-Sorensen distance **/
	DiceExpanded = 19
	/** Precomputed (special value) **/
	Precomputed = 100
)

Variables

View Source
var (
	// ErrFILModelLoad is returned when fail to load model.
	ErrFILModelLoad = errors.New("fail to load model")
	// ErrFILModelFree is returned when fail to free model.
	ErrFILModelFree = errors.New("fail to free model")
	// ErrFILModelPredict is returned when fail to predict.
	ErrFILModelPredict = errors.New("fail to predict")
)
View Source
var (
	ErrAgglomerativeClustering = errors.New("fail to agglomerative clustering")
)
View Source
var (
	ErrDBScan = errors.New("fail to dbscan")
)
View Source
var (
	ErrKmeans = errors.New("fail to kmeans")
)

Functions

This section is empty.

Types

type AgglomerativeClustering

type AgglomerativeClustering struct {
	// contains filtered or unexported fields
}

func NewAgglomerativeClustering

func NewAgglomerativeClustering(
	pairwiseConn bool,
	metric Metric,
	initNumCluster int,
	numNeighbor int,
) (*AgglomerativeClustering, error)

func (*AgglomerativeClustering) Close

func (c *AgglomerativeClustering) Close() error

func (*AgglomerativeClustering) Fit

func (c *AgglomerativeClustering) Fit(
	x []float32,
	numRow int,
	numCol int,
) ([]int32, []int32, int32, error)

Fit returns agglomerative clustering result output: labels: cluster labels children: children of each node numCluster: number of cluster error: error

type DBScan

type DBScan struct {
	// contains filtered or unexported fields
}

func NewDBScan

func NewDBScan(
	minPts int,
	eps float64,
	metric Metric,
	maxBytesPerBatch int,
	verbosity LogLevel,
) (*DBScan, error)

func (*DBScan) Close

func (d *DBScan) Close() error

func (*DBScan) Fit

func (d *DBScan) Fit(
	x []float32,
	numRow int,
	numCol int,
) ([]int32, error)

type FILInferenceAlgorithm

type FILInferenceAlgorithm int

FILInferenceAlgorithm is the inference algorithm.

const (
	// AlgoAuto choose the algorithm automatically; currently chooses NAIVE for sparse forests
	//  and BatchTreeReorg for dense ones
	AlgoAuto FILInferenceAlgorithm = iota
	// Naive naive algorithm: 1 thread block predicts 1 row; the row is cached in
	//  shared memory, and the trees are distributed cyclically between threads
	Naive
	// TreeReorg tree reorg algorithm: same as naive, but the tree nodes are rearranged
	//  into a more coalescing-friendly layout: for every node position,
	//  nodes of all trees at that position are stored next to each other
	TreeReorg
	// BatchTreeReorg batch tree reorg algorithm: same as tree reorg, but predictions multiple rows (up to 4)
	//  in a single thread block
	BatchTreeReorg
)

type FILModel

type FILModel struct {
	// contains filtered or unexported fields
}

FILModel is a Forest Inference Library model.

func NewFILModel

func NewFILModel(
	modelType FILModelType,
	filePath string,
	algo FILInferenceAlgorithm,
	classification bool,
	threshold float32,
	storageType FILStorageType,
	blocksPerSm int,
	threadsPerTree int,
	nItems int,
) (*FILModel, error)

NewFILModel algo is the inference algorithm. threshold may be used for thresholding if classification == true, and is ignored otherwise. threshold is ignored if leaves store vectorized class labels. in that case, a class with most votes is returned regardless of the absolute vote count. blocksPerSm if nonzero, works as a limit to improve cache hit rate for larger forests suggested values (if nonzero) are from 2 to 7. if zero, launches ceildiv(num_rows, NITEMS) blocks. threadsPerTree determines how many threads work on a single tree at once inside a block can only be a power of 2 nItems is how many input samples (items) any thread processes. If 0 is given, choose most (up to 4) that fit into shared memory.

func (*FILModel) Close

func (m *FILModel) Close() error

Close frees the model.

func (*FILModel) NumClass

func (m *FILModel) NumClass() int

func (*FILModel) Predict

func (m *FILModel) Predict(
	x []float32,
	numRow int,
	outputClassProbability bool) ([]float32, error)

Predict returns the prediction result. result is a float array of size num_row * num_class if output_class_probability is true, or num_row otherwise. given a row r and class c, the probability of r belonging to c is stored in result[r * num_class + c].

func (*FILModel) PredictSingleClassScore

func (m *FILModel) PredictSingleClassScore(
	x []float32,
	numRow int,
) ([]float32, error)

PredictSingleClassScore returns the prediction result of the 1 class of {0,1} classification.

type FILModelType

type FILModelType int

FILModelType is the type of the forest.

const (
	// XGBoost xgboost model (binary model file)
	XGBoost FILModelType = iota
	// XGBoostJSON xgboost model (json model file)
	XGBoostJSON
	// LightGBM lighgbm model (binary model file)
	LightGBM
)

type FILStorageType

type FILStorageType int

FILStorageType is the storage type of the forest.

const (
	// Auto decide automatically; currently always builds dense forests
	Auto FILStorageType = iota
	// Dense import the forest as dense
	Dense
	// Sparse import the forest as sparse (currently always with 16-byte nodes)
	Sparse
	// Sparse8 (experimental) import the forest as sparse with 8-byte nodes; can fail if
	//  8-byte nodes are not enough to store the forest, e.g. there are too many
	//  nodes in a tree or too many features; note that the number of bits used to
	//  store the child or feature index can change in the future; this can affect
	//  whether a particular forest can be imported as SPARSE8 */
	Sparse8
)

type GlmSolverAlgo

type GlmSolverAlgo int

type Kmeans

type Kmeans struct {
	// contains filtered or unexported fields
}

func NewKmeans

func NewKmeans(
	k int,
	maxIter int,
	tol float64,
	init KmeansInit,
	metric Metric,
	seed int,
	verbosity LogLevel,
) (*Kmeans, error)

func (*Kmeans) Fit

func (k *Kmeans) Fit(
	x []float32,
	numRow int,
	numCol int,
	sampleWeight []float32,

) (
	labels []int32,
	centroids []float32,
	inertia float32,
	nIter int32,
	err error,
)

type KmeansInit

type KmeansInit int

type LinearRegression

type LinearRegression struct {
	// contains filtered or unexported fields
}

func NewLinearRegression

func NewLinearRegression(
	fitIntercept bool,
	normalize bool,
	algo GlmSolverAlgo,
) (*LinearRegression, error)

func (*LinearRegression) Close

func (m *LinearRegression) Close() error

func (*LinearRegression) Fit

func (m *LinearRegression) Fit(
	x []float32,
	numRow int,
	numCol int,
	labels []float32,
) error

func (*LinearRegression) GetParams

func (m *LinearRegression) GetParams() []float32

func (*LinearRegression) Predict

func (m *LinearRegression) Predict(
	x []float32,
	numRow int,
	numCol int,
	result []float32,
) ([]float32, error)

func (*LinearRegression) SetParams

func (m *LinearRegression) SetParams(coef []float32)

type LogLevel

type LogLevel int
const (
	Off      LogLevel = 0
	Critical LogLevel = 1
	Error    LogLevel = 2
	Warn     LogLevel = 3
	Info     LogLevel = 4
	Debug    LogLevel = 5
	Trace    LogLevel = 6
)

type Metric

type Metric int

type RidgeRegression

type RidgeRegression struct {
	// contains filtered or unexported fields
}

func NewRidgeRegression

func NewRidgeRegression(
	alpha float32,
	fitIntercept bool,
	normalize bool,
	algo GlmSolverAlgo,
) (*RidgeRegression, error)

func (*RidgeRegression) Close

func (m *RidgeRegression) Close() error

func (*RidgeRegression) Fit

func (m *RidgeRegression) Fit(
	x []float32,
	numRow int,
	numCol int,
	labels []float32,
) error

func (*RidgeRegression) GetParams

func (m *RidgeRegression) GetParams() []float32

func (*RidgeRegression) Predict

func (m *RidgeRegression) Predict(
	x []float32,
	numRow int,
	numCol int,
	result []float32,
) ([]float32, error)

func (*RidgeRegression) SetParams

func (m *RidgeRegression) SetParams(coef []float32)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL