Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd4823b8

Browse files
committed
test(SVM): adding ONE_CLASS tests
1 parent8e8af2f commitd4823b8

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

‎test/SVM_asm.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,43 @@ describe('SVM:asm', () => {
3737
}
3838
});
3939
});
40+
41+
test('should train using ONE_CLASS and RBF kernel on random values',()=>{
42+
constsvm=newSVM({
43+
kernel:KernelTypes.RBF,
44+
type:SVMTypes.ONE_CLASS,
45+
gamma:1,
46+
cost:1,
47+
nu:0.1,
48+
quiet:true,
49+
});
50+
51+
constfeatures=[[0,0],[1,1],[1,0],[0,1]];
52+
consttoPredict=[[0.5,0.5],[1.5,1]];
53+
constexpected=[1,-1];
54+
constlabels=[0,0,0,0];
55+
56+
constexpectedModel={
57+
model:null,
58+
options:{
59+
kernel:'RBF',
60+
type:'ONE_CLASS',
61+
gamma:1,
62+
cost:1,
63+
nu:0.1,
64+
quiet:true,
65+
},
66+
loaded:false,
67+
};
68+
69+
expect(svm.toJSON()).toMatchObject(expectedModel);
70+
71+
svm.loadASM().then((loadedSVM)=>{
72+
loadedSVM.train({samples:features, labels});
73+
for(leti=0;i<toPredict.length;i++){
74+
constpred=loadedSVM.predictOne({sample:toPredict[i]});
75+
expect(pred).toBe(expected[i]);
76+
}
77+
});
78+
});
4079
});

‎test/SVM_wasm.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,43 @@ describe('SVM:wasm', () => {
3737
}
3838
});
3939
});
40+
41+
test('should train using ONE_CLASS and RBF kernel on random values',()=>{
42+
constsvm=newSVM({
43+
kernel:KernelTypes.RBF,
44+
type:SVMTypes.ONE_CLASS,
45+
gamma:1,
46+
cost:1,
47+
nu:0.1,
48+
quiet:true,
49+
});
50+
51+
constfeatures=[[0,0],[1,1],[1,0],[0,1]];
52+
consttoPredict=[[0.5,0.5],[1.5,1]];
53+
constexpected=[1,-1];
54+
constlabels=[0,0,0,0];
55+
56+
constexpectedModel={
57+
model:null,
58+
options:{
59+
kernel:'RBF',
60+
type:'ONE_CLASS',
61+
gamma:1,
62+
cost:1,
63+
nu:0.1,
64+
quiet:true,
65+
},
66+
loaded:false,
67+
};
68+
69+
expect(svm.toJSON()).toMatchObject(expectedModel);
70+
71+
svm.loadWASM().then((loadedSVM)=>{
72+
loadedSVM.train({samples:features, labels});
73+
for(leti=0;i<toPredict.length;i++){
74+
constpred=loadedSVM.predictOne({sample:toPredict[i]});
75+
expect(pred).toBe(expected[i]);
76+
}
77+
});
78+
});
4079
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp