Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Tensorflow.js tf.constraints.minMaxNorm() Function

  • Last Updated : 21 Jul, 2021

Tensorflow.js is an open-source library that is being developed by Google for running machine learning models as well as deep learning neural networks in the browser or node environment.

The tf.constraints.minMaxNorm() function is used to create a minMaxNorm constraint based on the given config object. It is inherited from constraint class. Constraints are the attributes of layers like weight, kernels, biases. minMaxNorm is a weight constraint.



Parameters: This function takes the config object as a parameter which can have the following properties:

  • maxValue: It specifies the maximum norm for incoming weight.
  • mixValue: It specifies the minimum norm for incoming weight.
  • axis: It specifies the axis along which to calculate norm.
  • rate: It specifies the rate of enforcing the constraints.

Return value: It returns a tf.constraints.Constraint.

Example 1:


// Importing the tensorflow.Js library
import * as tf from "@tensorflow/tfjs"
// Use maxNorm() function
const constraint = tf.constraints.minMaxNorm(1,0)
// Print the output


  "defaultMinValue": 0,
  "defaultMaxValue": 1,
  "defaultRate": 1,
  "defaultAxis": 0,
  "minValue": 0,
  "maxValue": 1,
  "rate": 1,
  "axis": 0

Example 2: In this example we will create a dense layer using minMaxNorm constraint.


// Import tensorflow.js
import * as tf from "@tensorflow/tfjs"
// Create a new dense layer using
// minMaxNorm constraint
const denseLayer = tf.layers.dense({
    units: 4,
    kernelInitializer: 'heNormal',
    kernelConstraint: 'minMaxNorm',
    biasConstraint: 'minMaxNorm',
    useBias: true
// Create input and output tensors
const input = tf.ones([2, 2]);
const output = denseLayer.apply(input);
// Print the output


    [[1.5594537, 0.1787095, 0.3462192, -1.7434707],
     [1.5594537, 0.1787095, 0.3462192, -1.7434707]]


Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!