Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function exec(SVM, time) {
const MILISECONDS = time * 1000;
const features = data.getNumbers();
let labels = data.getClasses();
const classes = data.getDistinctClasses();
const c = {};
classes.forEach((v, idx) => (c[v] = idx));
labels = labels.map(l => c[l]);
// We precompute the gaussian kernel
const kernel = new Kernel('gaussian', {sigma: 1 / Math.sqrt(gamma)});
const KData = kernel.compute(features).addColumn(0, range(1, labels.length + 1));
const t1 = Date.now();
let t2 = Date.now();
let count = 0;
while (t2 - t1 < MILISECONDS) {
const svm = new SVM({
quiet: true,
cost: cost,
async function exec() {
const SVM = await require(`../../${argv[0]}`);
const data = require('ml-dataset-iris');
const features = data.getNumbers();
let labels = data.getClasses();
const classes = data.getDistinctClasses();
const c = {};
classes.forEach((v, idx) => c[v] = idx);
labels = labels.map(l => c[l]);
const cost = Array.from({length: COST_GRID_SIZE}).map(normalize(COST_GRID_SIZE, COST_MIN, COST_MAX)).map(pow10);
const gamma = Array.from({length: GAMMA_GRID_SIZE}).map(normalize(GAMMA_GRID_SIZE, GAMMA_MIN, GAMMA_MAX)).map(pow10);
const timeLabel = `iris-cv ${argv[0]}: `;
console.time(timeLabel);
for(let c of cost) {
for(let g of gamma) {
const svm = new SVM({
quiet: true,
cost: c,
function exec(SVM, precomputed) {
const data = require('ml-dataset-iris');
var trainData;
const features = data.getNumbers();
let labels = data.getClasses();
const classes = data.getDistinctClasses();
const c = {};
classes.forEach((v, idx) => (c[v] = idx));
labels = labels.map((l) => c[l]);
if (precomputed) {
const kernel = new Kernel('gaussian', { sigma: 1 / Math.sqrt(gamma) });
trainData = kernel
.compute(features)
.addColumn(0, range(1, labels.length + 1));
} else {
trainData = features;
}
const svm = new SVM({
quiet: true,
function exec(time) {
const MILISECONDS = time * 1000;
const data = require('ml-dataset-iris');
const features = data.getNumbers();
let labels = data.getClasses();
const classes = data.getDistinctClasses();
const c = {};
classes.forEach((v, idx) => (c[v] = idx));
labels = labels.map(l => c[l]);
const startTime = Date.now();
let endTime = Date.now();
let count = 0;
while (endTime - startTime < MILISECONDS) {
for (let c of cost) {
for (let g of gamma) {
const svm = new SVM({
C: c,
kernel: 'rbf',
kernelOptions: {
function exec(SVM, time, precomputed) {
const MILISECONDS = time * 1000;
const data = require('ml-dataset-iris');
var trainData;
const features = data.getNumbers();
let labels = data.getClasses();
const classes = data.getDistinctClasses();
const c = {};
classes.forEach((v, idx) => (c[v] = idx));
labels = labels.map((l) => c[l]);
let result;
const t1 = Date.now();
let t2 = Date.now();
let count = 0;
while (t2 - t1 < MILISECONDS) {
if (precomputed) {
const kernel = new Kernel('gaussian', { sigma: 1 / Math.sqrt(gamma) });
trainData = kernel.compute(features).addColumn(0, range(1, labels.length + 1));
} else {
trainData = features;
function exec(SVM, time) {
const MILISECONDS = time * 1000;
const data = require('ml-dataset-iris');
const features = data.getNumbers();
let labels = data.getClasses();
const classes = data.getDistinctClasses();
const c = {};
classes.forEach((v, idx) => (c[v] = idx));
labels = labels.map(l => c[l]);
const startTime = Date.now();
let endTime = Date.now();
let count = 0;
while (endTime - startTime < MILISECONDS) {
for (let c of cost) {
for (let g of gamma) {
const svm = new SVM({
quiet: true,
cost: c,
gamma: g
function exec(SVM, time) {
const MILISECONDS = time * 1000;
const data = require('ml-dataset-iris');
const features = data.getNumbers();
let labels = data.getClasses();
const classes = data.getDistinctClasses();
const c = {};
classes.forEach((v, idx) => (c[v] = idx));
labels = labels.map(l => c[l]);
const t1 = Date.now();
let t2 = Date.now();
let count = 0;
while (t2 - t1 < MILISECONDS) {
const svm = new SVM({
quiet: true,
cost: cost,
gamma: gamma
});