dist/svm/SvmLinear.js
function modelStringToModelMap(modelString) {
	var matches = LIB_LINEAR_MODEL_PATTERN.exec(modelString);
	if (!matches) {
		console.log(modelString);
		throw new Error("Model does not match SVM-Linear format");
	};
	var labels = matches[1].split(/\s+/);
	var mapLabelToMapFeatureToWeight = {};
	for (var iLabel in labels) {
		var label = labels[iLabel];
		mapLabelToMapFeatureToWeight[label]={};
	}

	var weightsMatrix = matches[3];
	// each line represents a feature; each column represents a label:

	var weightsLines = weightsMatrix.split(NEWLINE);
	for (var feature in weightsLines) {
		var weights = weightsLines[feature].split(/\s+/);
		weights.pop(); // ignore lal]st weight, which is empty (-space)
		if (weights.length==0)
			continue; // ignore empty lines
//		if (isNaN(parseFloat(weights[weights.length-1])))
//			weights.pop();
		if (weights.length==1 && labels.length==2)
			weights[1] = -weights[0];
		if (weights.length!=labels.length)
			throw new Error("Model does not match SVM-Linear format: there are "+labels.length+" labels ("+labels+") and "+weights.length+" weights ("+weights+")");
		for (var iLabel in labels) {
			var label = labels[iLabel];
			var weight = parseFloat(weights[iLabel]);
			if (Math.abs(weight)>=MIN_WEIGHT)
				mapLabelToMapFeatureToWeight[label][feature]=weight;
		}
	}

	return mapLabelToMapFeatureToWeight;
}
function modelStringToModelMap(modelString) {
	var matches = LIB_LINEAR_MODEL_PATTERN.exec(modelString);
	if (!matches) {
		console.log(modelString);
		throw new Error("Model does not match SVM-Linear format");
	};
	var labels = matches[1].split(/\s+/);
	var mapLabelToMapFeatureToWeight = {};
	for (var iLabel in labels) {
		var label = labels[iLabel];
		mapLabelToMapFeatureToWeight[label]={};
	}

	var weightsMatrix = matches[3];
	// each line represents a feature; each column represents a label:

	var weightsLines = weightsMatrix.split(NEWLINE);
	for (var feature in weightsLines) {
		var weights = weightsLines[feature].split(/\s+/);
		weights.pop(); // ignore lal]st weight, which is empty (-space)
		if (weights.length==0)
			continue; // ignore empty lines
//		if (isNaN(parseFloat(weights[weights.length-1])))
//			weights.pop();
		if (weights.length==1 && labels.length==2)
			weights[1] = -weights[0];
		if (weights.length!=labels.length)
			throw new Error("Model does not match SVM-Linear format: there are "+labels.length+" labels ("+labels+") and "+weights.length+" weights ("+weights+")");
		for (var iLabel in labels) {
			var label = labels[iLabel];
			var weight = parseFloat(weights[iLabel]);
			if (Math.abs(weight)>=MIN_WEIGHT)
				mapLabelToMapFeatureToWeight[label][feature]=weight;
		}
	}

	return mapLabelToMapFeatureToWeight;
}
function modelStringToModelMap ( modelString ) { var matches = LIB_LINEAR_MODEL_PATTERN . exec ( modelString ) ; if ( ! matches ) { console . log ( modelString ) ; throw new Error ( "Model does not match SVM-Linear format" ) ; } ; var labels = matches [ 1 ] . split ( / \s+ / ) ; var mapLabelToMapFeatureToWeight = { } ; for ( var iLabel in labels ) { var label = labels [ iLabel ] ; mapLabelToMapFeatureToWeight [ label ] = { } ; } var weightsMatrix = matches [ 3 ] ; // each line represents a feature; each column represents a label: var weightsLines = weightsMatrix . split ( NEWLINE ) ; for ( var feature in weightsLines ) { var weights = weightsLines [ feature ] . split ( / \s+ / ) ; weights . pop ( ) ; // ignore lal]st weight, which is empty (-space) if ( weights . length == 0 ) continue ; // ignore empty lines //		if (isNaN(parseFloat(weights[weights.length-1]))) //			weights.pop(); if ( weights . length == 1 && labels . length == 2 ) weights [ 1 ] = - weights [ 0 ] ; if ( weights . length != labels . length ) throw new Error ( "Model does not match SVM-Linear format: there are " + labels . length + " labels (" + labels + ") and " + weights . length + " weights (" + weights + ")" ) ; for ( var iLabel in labels ) { var label = labels [ iLabel ] ; var weight = parseFloat ( weights [ iLabel ] ) ; if ( Math . abs ( weight ) >= MIN_WEIGHT ) mapLabelToMapFeatureToWeight [ label ] [ feature ] = weight ; } } return mapLabelToMapFeatureToWeight ; }
weights smaller than this are ignored, to save space 
A utility that converts a model in the SvmLinear format to a matrix of feature weights per label.
@param modelString a string.
@returns mapLabelToMapFeatureToWeight.
weights smaller than this are ignored to save space A utility that converts a model in the SvmLinear format to a matrix of feature weights per label .