Friday, September 19, 2025
HomeLanguagesJavascriptTensorflow.js tf.constraints.minMaxNorm() Function

Tensorflow.js tf.constraints.minMaxNorm() Function

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.

Syntax:

tf.constraints.minMaxNorm(config)

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:

Javascript




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


 
 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.

Javascript




// 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
output.print()


 
 Output: 

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

Reference: https://js.tensorflow.org/api/1.0.0/#constraints.minMaxNorm

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32301 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6665 POSTS0 COMMENTS
Nicole Veronica
11840 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11898 POSTS0 COMMENTS
Shaida Kate Naidoo
6781 POSTS0 COMMENTS
Ted Musemwa
7056 POSTS0 COMMENTS
Thapelo Manthata
6739 POSTS0 COMMENTS
Umr Jansen
6744 POSTS0 COMMENTS