How to use the mathjs.transpose function in mathjs

To help you get started, we’ve selected a few mathjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github javascript-machine-learning / linear-algebra-matrix / index.js View on Github external
// 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],
github birnbaum / rfvis / src / _compute_coordinates.js View on Github external
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]])
github OpenGenus / cosmos / code / artificial_intelligence / src / linear_regression / linearregression.js View on Github external
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;
};
github OpenGenus / cosmos / code / artificial_intelligence / src / Linear_Regression / linearRegression.js View on Github external
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;
}
github OpenGenus / cosmos / code / artificial_intelligence / src / linear_regression / linearregression.js View on Github external
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;
};
github laoqiren / mlhelper / src / utils / matrix / index.ts View on Github external
transpose(): Array>{
        return math.transpose(this.arr);
    }
    calAvg(flag=0 as number): Array{

mathjs

Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif

Apache-2.0
Latest version published 1 day ago

Package Health Score

92 / 100
Full package analysis