<commit_before>var linearAlgebra = require('linear-algebra')(),     // initialise it
    Vector = linearAlgebra.Vector,
    Matrix = linearAlgebra.Matrix;

const SPH_WEIGHT = 100;
const CYL_WEIGHT = 10;
const AXIS_WEIGHT = 1;

var rsph1 = 1;
var lsph1 = 1;
var rcyl1 = 2;
var lcyl1 = 2;
var raxis1 = 3;
var laxis1 = 3;
var rsph2 = 1;
var lsph2 = 1;
var rcyl2 = 2;
var lcyl2 = 2;
var raxis2 = 3;
var laxis2 = 3;

var weights = new Matrix([SPH_WEIGHT, SPH_WEIGHT, CYL_WEIGHT, CYL_WEIGHT, AXIS_WEIGHT, AXIS_WEIGHT]);

var prescription = new Matrix(weights.mul(new Matrix([rsph1, lsph1, rcyl1, lcyl1, raxis1, laxis1])).data[0]);
var glasses = new Matrix(weights.mul(new Matrix([rsph2, lsph2, rcyl2, lcyl2, raxis2, laxis2])).data[0]);

// dot product
var dotProduct = prescription.dot(glasses.trans()).data[0][0];

// norm function
function norm(matrix) {
	m = matrix.data;
	var squared_sum = 0;
	for (i = 0; i < m[0].length; i++) {
		squared_sum += Math.pow(m[0][i], 2);
	}
	return Math.sqrt(squared_sum);
}

var simScore = dotProduct / (norm(prescription) * norm(glasses));
simScore = Math.round(simScore * 10000) / 10000;
console.log(simScore);<commit_msg>Modified linear_algebra_test to look nicer<commit_after>var linearAlgebra = require('linear-algebra')(),     // initialise it
    Vector = linearAlgebra.Vector,
    Matrix = linearAlgebra.Matrix;

const SPH_WEIGHT = 100;
const CYL_WEIGHT = 10;
const AXIS_WEIGHT = 1;

var rsph1 = 1;
var lsph1 = 1;
var rcyl1 = 2;
var lcyl1 = 2;
var raxis1 = 3;
var laxis1 = 3;
var rsph2 = 1;
var lsph2 = 1;
var rcyl2 = 2;
var lcyl2 = 2;
var raxis2 = 3;
var laxis2 = 3;

function getSimScore(rsph1, lsph1, rcyl1, lcyl1, raxis1, laxis1, rsph2, lsph2, rcyl2, lcyl2, raxis2, laxis2) {
	var weights = new Matrix([SPH_WEIGHT, SPH_WEIGHT, CYL_WEIGHT, CYL_WEIGHT, AXIS_WEIGHT, AXIS_WEIGHT]);

	var prescription = new Matrix(weights.mul(new Matrix([rsph1, lsph1, rcyl1, lcyl1, raxis1, laxis1])).data[0]);
	var glasses = new Matrix(weights.mul(new Matrix([rsph2, lsph2, rcyl2, lcyl2, raxis2, laxis2])).data[0]);

	var simScore = inner_product(prescription, glasses) / (norm(prescription) * norm(glasses));
	simScore = Math.round(simScore * 10000) / 10000;
	return simScore;
	// console.log(simScore);
}

// inner product
function inner_product(a, b){
	return a.dot(b.trans()).data[0][0];
}

// norm function
function norm(matrix) {
	m = matrix.data;
	var squared_sum = 0;
	for (i = 0; i < m[0].length; i++) {
		squared_sum += Math.pow(m[0][i], 2);
	}
	return Math.sqrt(squared_sum);
}

// console.log(getSimScore(rsph1, lsph1, rcyl1, lcyl1, raxis1, laxis1, rsph2, lsph2, rcyl2, lcyl2, raxis2, laxis2));
{'fraction_non_alphanumeric': 0.14910612400152148, 'fraction_numerical': 0.05553442373526055, 'mean_word_length': 4.63169164882227, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '199867', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1077, 'n_words': 269}