Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Calculated Inverse Matrix with Identity Matrix
const matrixT = math.matrix([[0, 1], [2, 3]]);
const matrixU = math.eye(2);
const matrixT_I = math.divide(matrixU, matrixT);
console.log('Calculated Inverse Matrix with Identity Matrix:');
console.log(matrixT_I.valueOf());
console.log('\n');
// Transpose Matrix
const matrixV = math.matrix([[0], [1], [2]]);
const matrixV_T = math.transpose(matrixV);
console.log('Transpose Matrix:');
console.log(matrixV_T.valueOf());
console.log('\n');
// Example: Predicting Housing Prices with 3 competing Hypotheses
console.log('Predicting Housing Prices with 3 competing Hypotheses:');
console.log('const HOUSE_SIZES = [2104, 1416, 1534, 852];');
console.log('const h1 = x => -40 + 0.25 * x;');
console.log('const h2 = x => 200 + 0.1 * x;');
console.log('const h3 = x => -150 + 0.4 * x;');
console.log('\n');
const houseSizeMatrix = math.matrix([
[1, 2104],
function computeForestMap({
forest,
rmax = 50,
rmin = 10,
width = 5,
N = 100
}) {
// some pre-calculations
const X = math.matrix(Array(N).fill(null).map(() => math.range(1, N + 1)));
const Y = math.transpose(X);
const treeStrengths = forest.trees.map(tree => tree.strength);
// Init empty output matrix (x and y coordinates for each tree)
let position = math.zeros(2, treeStrengths.length);
// Init empty NxN voting spaces for each tree
let votingMatrices = math.zeros(N, N, treeStrengths.length);
console.time('Computing forest map');
for (let t1 = 0; t1 < treeStrengths.length; t1++) {
// find tree with current maximal strength
const i = argmax(treeStrengths);
// if its the first tree, define position as center
if (t1 === 0) {
position = math.subset(position, math.index([0, 1], i), [[N / 2], [N / 2]])
const normalEqn = function normalEqn(X, y) {
// computing the equation theta = (X^T * X)^-1 * X^T * y
var thetas = math.multiply(math.transpose(X), X);
thetas = math.multiply(math.inv(thetas), math.transpose(X));
thetas = math.multiply(thetas, y);
// returning a vector containing thetas for hypothesis
return thetas;
};
const normalEqn = function normalEqn(X, y) {
// computing the equation theta = (X^T * X)^-1 * X^T * y
var thetas = math.multiply(math.transpose(X), X);
thetas = math.multiply(math.inv(thetas), math.transpose(X));
thetas = math.multiply(thetas, y);
// returning a vector containing thetas for hypothesis
return thetas;
}
const normalEqn = function normalEqn(X, y) {
// computing the equation theta = (X^T * X)^-1 * X^T * y
var thetas = math.multiply(math.transpose(X), X);
thetas = math.multiply(math.inv(thetas), math.transpose(X));
thetas = math.multiply(thetas, y);
// returning a vector containing thetas for hypothesis
return thetas;
};
transpose(): Array>{
return math.transpose(this.arr);
}
calAvg(flag=0 as number): Array{