Classifying points in rectangle

  • Intro
  • Classifying points
  • Conclusion

Information

Primary software used PUG
Course Classifying points in rectangle
Primary subject AI & ML
Secondary subject Machine Learning
Level Intermediate
Last updated November 11, 2024
Keywords

Responsible

Teacher
Faculty

Classifying points in rectangle 0/2

Classifying points in rectangle link copied

This exercise serves as a simple demonstration of how Machine Learning can be applied to real-world classification problems.

Result of classifying points inside a rectangle with PUG

The PUG plugin will train a network using Supervised Learning to perform binary classification of points – classifying points as inside or outside a specified shape. This exercise serves as a simple demonstration of how Machine Learning can be applied to real-world classification problems. The Neural Network will be trained on labeled data and can classify new, unlabeled data based on the knowledge acquired during training.

Classifying points in rectangle 1/2

Classifying points link copied

Generate data

Generate 1000 points
Generate 1000 points

First, generate 1000 random points. For a neural network, it is advisable to normalize input values between 0 to 1.

Random generation points and remap  to 0-1
Random generation points and remap to 0-1

We will define a curve and set of points and determine whether the points of intersection are located inside or outside the curve.

The input tensor contains normalized coordinates of points. The output tensor in a classification task contains integer values related to each label. In this case, 0 means outside and 1 means inside the shape.

Define the boundary curve for inside/outside condition
Define the boundary curve for inside/outside condition

Training

Specifying 1000 in the
Specifying 1000 in the “H” input parameter

After defining the curve and points, we will initiate training by pressing the “run” button on the supervised learning component.

You can define a dense Neural Netowrk just by specifying the size of the hidden layers in the “H” input parameter.

Testing

To verify the accuracy of the trained model, we will generate random points and test if they are classified as inside or outside the curve.

Generating new points
Generating new points

Predictions

We will connect the tensor of test points to the prediction component to evaluate if they are classified as inside or outside the curve.

Evaluating the classification inside or outside the curve
Evaluating the classification inside or outside the curve

Classifying points in rectangle 2/2

Conclusion link copied

You now learned how to use the plug-in PUG for a simple classification problem in Grasshopper. 

Classification with PUG overview of Grasshopper script
Classification with PUG overview of Grasshopper script

Final exercise

Here you can find an overview of the script to classify if points are inside or outside a rectanlge.

Download final exercise file – Classification with PUG
application/zip (ZIP, 40 KB)