Open In App

Tensorflow.js tf.initializers.orthogonal() Function

Last Updated : 30 Aug, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js.

The tf.initializers.orthogonal() function produces a random orthogonal matrix.

Syntax:

tf.initializers.orthogonal(arguments)

Parameters:

  • arguments: It is an object that contains seed (a number) which is the random number generator seed and a gain (a number) which is a multiplicative factor to be applied to the orthogonal matrix. Its default value is considered as1.

Returns value: It returns tf.initializers.Initializer

Example 1:

Javascript




// Importing the tensorflow.js library
import * as tf from "@tensorflow/tfjs"
 
// Initializing the .initializers.orthogonal() function
let geek = tf.initializers.orthogonal(2)
 
// Printing gain value
console.log(geek);
 
// Printing individual gain value
console.log('\nIndividual values:\n');
console.log(geek.DEFAULT_GAIN);
console.log(geek.gain);


Output:

{
  "DEFAULT_GAIN": 1,
  "gain": 1
}

Individual values:

1
1

Example 2:

Javascript




// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs
 
// Defining the input value
const inputValue = tf.input({shape:[4]});
 
// Initializing tf.initializers.orthogonal() function
const funcValue = tf.initializers.orthogonal(4)
 
// Creating dense layer 1
const dense_layer_1 = tf.layers.dense({
    units: 6,
    activation: 'relu',
    kernelInitialize: funcValue
});
 
// Creating dense layer 2
const dense_layer_2 = tf.layers.dense({
    units: 8,
    activation: 'softmax'
});
 
// Output
const outputValue = dense_layer_2.apply(
    dense_layer_1.apply(inputValue)
);
 
// Creation the model.
const model = tf.model({
    inputs: inputValue,
    outputs: outputValue
});
 
// Predicting the output.
model.predict(tf.ones([2, 4])).print();


Output:

Tensor
    [[0.0925488, 0.0833014, 0.1223793, 0.1189993, 
      0.0733501, 0.1645982, 0.1299256, 0.2148973],
     [0.0925488, 0.0833014, 0.1223793, 0.1189993, 
      0.0733501, 0.1645982, 0.1299256, 0.2148973]]

Reference: https://js.tensorflow.org/api/3.6.0/#initializers.orthogonal



Similar Reads

Tensorflow.js tf.initializers.ones() Function
Tensorflow.js is a very well-known machine learning library that used to develop a machine learning model using JavaScript. The main purpose to use this library is to run and deploy a machine learning model directly from the browser or in Node.js. Tensorflow.js is an open-source hardware-accelerated JavaScript library. In this article, we're going
2 min read
Tensorflow.js tf.initializers.glorotUniform() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The tf.initializers.glorotUniform() function extracts sam
2 min read
Tensorflow.js tf.initializers.glorotNormal() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The tf.initializers.glorotNormal() function extract sampl
2 min read
Tensorflow.js tf.initializers.heUniform() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The tf.initializers.heUniform() function draws samples fr
2 min read
Tensorflow.js tf.initializers.leCunNormal() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The tf.initializers.leCunNormal() function extracts sampl
2 min read
Tensorflow.js tf.initializers.leCunUniform() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The tf.initializers.leCunUniform() function takes samples
2 min read
Tensorflow.js tf.initializers.identity() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. The Initializer class is the base class of all initializers in Tensorflow.js. The initializers are used to initialize the Tensors with the specific values. It returns the tensor object
2 min read
Tensorflow.js tf.initializers.truncatedNormal() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The tf.initializers.truncatedNormal() function produces r
2 min read
Tensorflow.js tf.initializers.varianceScaling() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The tf.initializers.varianceScaling() function is capable
2 min read
Tensorflow.js tf.initializers.randomNormal() Function
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment. It also helps the developers to develop ML models in JavaScript language and can use ML directly in the browser or in Node.js. The tf.initializers.randomNormal() function produces rand
2 min read