libsvm-wasm
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,1 +0,21 @@ | ||
export default function SVM_FACTORY(): Promise<void>; | ||
export interface LibsvmModlue extends EmscriptenModule { | ||
stringToUTF8: typeof stringToUTF8; | ||
_train_model(samplesPointer: number, paramPointer: number): number; | ||
_free_model(modelPointer: number): void; | ||
_init_node(dataPointer: number, size: number): number; | ||
_save_model(modelPointer: number, filenamePointer: number): Boolean; | ||
_load_model(filenamePointer: number): number; | ||
_make_samples(dataPointer: number, labelPointer: number, nb_feat: number, nb_dim: number): number; | ||
_make_param(svm_type: number, kernel_type: number, | ||
degree: number, gamma: number, coef0: number, | ||
nu: number, cache_size: number, eps: number, C: number, | ||
p: number, shrinking: number, probability: number, | ||
nr_weight: number, weightLabelPointer: number, | ||
weightPointer: number): number; | ||
_free_sample(samplesPointer: number): void; | ||
_cross_valid_model(samplesPointer: number, paramPointer: number, kFold: number, targetPointer: number); | ||
_predict_one(modelPointer: number, dataPointer: number, size: number): number; | ||
_predict_one_with_prob(modelPointer: number, dataPointer: number, size: number, probEstimates: number): number; | ||
} | ||
export default function libsvmFactory(): Promise<LibsvmModlue>; |
@@ -1,2 +0,2 @@ | ||
import SVM from '../src/'; | ||
import { SVM } from '../src/'; | ||
import { readFileSync } from 'fs'; | ||
@@ -3,0 +3,0 @@ import { join } from 'path'; |
@@ -1,1 +0,21 @@ | ||
export default function SVM_FACTORY(): Promise<void>; | ||
export interface LibsvmModlue extends EmscriptenModule { | ||
stringToUTF8: typeof stringToUTF8; | ||
_train_model(samplesPointer: number, paramPointer: number): number; | ||
_free_model(modelPointer: number): void; | ||
_init_node(dataPointer: number, size: number): number; | ||
_save_model(modelPointer: number, filenamePointer: number): Boolean; | ||
_load_model(filenamePointer: number): number; | ||
_make_samples(dataPointer: number, labelPointer: number, nb_feat: number, nb_dim: number): number; | ||
_make_param(svm_type: number, kernel_type: number, | ||
degree: number, gamma: number, coef0: number, | ||
nu: number, cache_size: number, eps: number, C: number, | ||
p: number, shrinking: number, probability: number, | ||
nr_weight: number, weightLabelPointer: number, | ||
weightPointer: number): number; | ||
_free_sample(samplesPointer: number): void; | ||
_cross_valid_model(samplesPointer: number, paramPointer: number, kFold: number, targetPointer: number); | ||
_predict_one(modelPointer: number, dataPointer: number, size: number): number; | ||
_predict_one_with_prob(modelPointer: number, dataPointer: number, size: number, probEstimates: number): number; | ||
} | ||
export default function libsvmFactory(): Promise<LibsvmModlue>; |
{ | ||
"name": "libsvm-wasm", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "", | ||
"main": "src/index.ts", | ||
"scripts": { | ||
"build": "make" | ||
"build": "make && npx tsc", | ||
"clean": "make clean" | ||
}, | ||
@@ -20,6 +21,7 @@ "repository": { | ||
"devDependencies": { | ||
"@types/emscripten": "^1.39.6", | ||
"@types/node": "^14.18.1", | ||
"ts-node": "^9.0.0", | ||
"typescript": "^4.0.2" | ||
"typescript": "^4.5.4" | ||
} | ||
} |
@@ -1,5 +0,4 @@ | ||
import SVM_FACTORY from '../dist/libsvm'; | ||
import svmFactory, { LibsvmModlue } from '../dist/libsvm'; | ||
let libsvm: LibsvmModlue; | ||
let libsvm: any; | ||
enum SVM_TYPE { | ||
@@ -85,7 +84,8 @@ C_SVC, | ||
constructor(param?: SVMParam) { | ||
this.ready = new Promise(async (resolve) => { | ||
libsvm = await SVM_FACTORY(); | ||
resolve(); | ||
this.ready = new Promise((resolve, reject) => { | ||
svmFactory().then((lib) => { | ||
libsvm = lib; | ||
resolve(); | ||
}); | ||
}); | ||
if (!param) this.param = new SVMParam({} as ISVMParam); | ||
@@ -96,3 +96,3 @@ else this.param = param; | ||
public async train() { | ||
public train = async () => { | ||
await this.ready; | ||
@@ -104,5 +104,4 @@ if (this.paramPointer == -1 || this.samplesPointer == -1) return; | ||
public async predict(data: Array<number>): Promise<number> { | ||
public predict = async (data: Array<number>): Promise<number> => { | ||
await this.ready; | ||
if (this.modelPointer == null) { | ||
@@ -119,5 +118,4 @@ console.error("Model should be trained first"); | ||
public async feedSamples(data: Array<Array<number>>, labels: Array<number>) { | ||
public feedSamples = async (data: Array<Array<number>>, labels: Array<number>) => { | ||
await this.ready; | ||
if (this.samplesPointer == null) libsvm._free_sample(this.samplesPointer); | ||
@@ -136,3 +134,3 @@ | ||
public async feedParam() { | ||
public feedParam = async () => { | ||
await this.ready; | ||
@@ -173,5 +171,4 @@ const { | ||
public async save(name: string): Promise<boolean> { | ||
public save = async (name: string): Promise<boolean> => { | ||
await this.ready; | ||
if (this.modelPointer == null) { | ||
@@ -190,3 +187,3 @@ console.error("Model should be trained first"); | ||
public async load(name: string): Promise<boolean> { | ||
public load = async (name: string): Promise<boolean> => { | ||
await this.ready; | ||
@@ -206,3 +203,3 @@ if (this.modelPointer == null) libsvm._free_model(this.modelPointer); | ||
} | ||
public evaluate(label: Array<number>, pred: Array<number>): Array<string>{ | ||
public evaluate = (label: Array<number>, pred: Array<number>): Array<string> =>{ | ||
//from the python implementation libsvm/python/commonutil.py | ||
@@ -215,3 +212,3 @@ if(label.length != pred.length){ | ||
let total_error: number = 0; | ||
let sumv =0; | ||
let sumv = 0; | ||
let sumy = 0; | ||
@@ -254,2 +251,7 @@ let sumvv = 0; | ||
export default SVM; | ||
export { | ||
SVM, | ||
SVM_TYPE, | ||
KERNEL_TYPE, | ||
SVMParam | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
331965
15
1246
4