@dheuv/xgboost-wasm 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/xgboost.d.ts +81 -0
- package/dist/xgboost_wasm.wasm +0 -0
- package/package.json +30 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a trained XGBoost booster model.
|
|
3
|
+
*/
|
|
4
|
+
export interface Booster {
|
|
5
|
+
/** Loads a model from a path in the virtual file system. */
|
|
6
|
+
loadModel(path: string): void;
|
|
7
|
+
/** Saves a model to a path in the virtual file system. */
|
|
8
|
+
saveModel(path: string): void;
|
|
9
|
+
/** Sets a booster parameter. */
|
|
10
|
+
setParam(name: string, value: string): void;
|
|
11
|
+
/** Updates the booster for one iteration using the given training data. */
|
|
12
|
+
updateOneIter(iter: number, dtrain: DMatrix): void;
|
|
13
|
+
/**
|
|
14
|
+
* Makes predictions on the given DMatrix.
|
|
15
|
+
* @returns A JSON string containing the predictions.
|
|
16
|
+
*/
|
|
17
|
+
predict(dmat: DMatrix, option?: number, ntreeLimit?: number): string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Represents a data matrix used by XGBoost.
|
|
21
|
+
*/
|
|
22
|
+
export interface DMatrix {
|
|
23
|
+
/** Sets additional float information (like labels) for the DMatrix. */
|
|
24
|
+
setFloatInfo(field: string, dataPtr: number, len: number): void;
|
|
25
|
+
/** Returns the number of rows in the DMatrix. */
|
|
26
|
+
getNumRow(): number;
|
|
27
|
+
/** Returns the number of columns in the DMatrix. */
|
|
28
|
+
getNumCol(): number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Interface for the internal Emscripten module.
|
|
32
|
+
*/
|
|
33
|
+
export interface XGBoostModule {
|
|
34
|
+
Booster: new () => Booster;
|
|
35
|
+
DMatrix: new (dataPtr: number, nrow: number, ncol: number, missing: number) => DMatrix;
|
|
36
|
+
XGBoostVersion(): string;
|
|
37
|
+
XGBGetLastError(): string;
|
|
38
|
+
UTF8ToString(ptr: number): string;
|
|
39
|
+
_malloc(size: number): number;
|
|
40
|
+
_free(ptr: number): void;
|
|
41
|
+
HEAPF32: Float32Array;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Initializes the XGBoost WASM module.
|
|
45
|
+
*/
|
|
46
|
+
export declare function init(): Promise<XGBoostModule>;
|
|
47
|
+
/**
|
|
48
|
+
* Main class for interacting with XGBoost WASM.
|
|
49
|
+
*/
|
|
50
|
+
export declare class XGBoost {
|
|
51
|
+
private module;
|
|
52
|
+
constructor(module: XGBoostModule);
|
|
53
|
+
/**
|
|
54
|
+
* Creates a new XGBoost instance by initializing the WASM module.
|
|
55
|
+
*/
|
|
56
|
+
static create(): Promise<XGBoost>;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the version of the underlying XGBoost library.
|
|
59
|
+
*/
|
|
60
|
+
version(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Creates an empty booster model.
|
|
63
|
+
*/
|
|
64
|
+
createBooster(): Booster;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a DMatrix from feature data and optional labels.
|
|
67
|
+
* @param data Feature data as a Float32Array.
|
|
68
|
+
* @param nrow Number of rows.
|
|
69
|
+
* @param ncol Number of columns.
|
|
70
|
+
* @param missing Value to treat as missing.
|
|
71
|
+
* @param label Optional training labels.
|
|
72
|
+
*/
|
|
73
|
+
createDMatrix(data: Float32Array, nrow: number, ncol: number, missing?: number, label?: Float32Array): DMatrix;
|
|
74
|
+
/**
|
|
75
|
+
* Trains a model for a specified number of rounds.
|
|
76
|
+
* @param dtrain Training data.
|
|
77
|
+
* @param params Training parameters (e.g., objective, max_depth).
|
|
78
|
+
* @param rounds Number of boosting rounds.
|
|
79
|
+
*/
|
|
80
|
+
train(dtrain: DMatrix, params: Record<string, string>, rounds: number): Promise<Booster>;
|
|
81
|
+
}
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dheuv/xgboost-wasm",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "XGBoost WebAssembly library for Node.js and Browser",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build:cpp": "./scripts/build_wasm.sh",
|
|
13
|
+
"build:js": "rollup -c",
|
|
14
|
+
"build": "npm run build:cpp && npm run build:js",
|
|
15
|
+
"test": "vitest"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@rollup/plugin-commonjs": "^25.0.0",
|
|
19
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
20
|
+
"@rollup/plugin-terser": "^0.4.0",
|
|
21
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
22
|
+
"rollup": "^4.0.0",
|
|
23
|
+
"typescript": "^5.0.0",
|
|
24
|
+
"vitest": "^0.34.0"
|
|
25
|
+
},
|
|
26
|
+
"type": "module",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"tslib": "^2.8.1"
|
|
29
|
+
}
|
|
30
|
+
}
|