Tensorflow.js tf.initializers.orthogonal() Function
Last Updated :
30 Aug, 2021
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
import * as tf from "@tensorflow/tfjs"
let geek = tf.initializers.orthogonal(2)
console.log(geek);
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
import * as tf from "@tensorflow/tfjs
const inputValue = tf.input({shape:[4]});
const funcValue = tf.initializers.orthogonal(4)
const dense_layer_1 = tf.layers.dense({
units: 6,
activation: 'relu' ,
kernelInitialize: funcValue
});
const dense_layer_2 = tf.layers.dense({
units: 8,
activation: 'softmax'
});
const outputValue = dense_layer_2.apply(
dense_layer_1.apply(inputValue)
);
const model = tf.model({
inputs: inputValue,
outputs: outputValue
});
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...