# Using neural network to recognise patterns in matrices

I am trying to develop a neural network which can identify design features in CAD models (i.e. slots, bosses, holes, pockets, steps).

The input data I intend to use for the network is a n x n matrix (where n is the number of faces in the CAD model). A '1' in the top right triangle in the matrix represents a convex relationship between two faces and a '1' in the bottom left triangle represents a concave relationship. A zero in both positions means the faces are not adjacent. The image below gives an example of such a matrix. Lets say I set the maximum model size to 20 faces and apply padding for anything smaller than that in order to make the inputs to the network a constant size.

I want to be able to recognise 5 different design features and would therefore have 5 output neurons - [slot, pocket, hole, boss, step]

Would I be right in saying that this becomes a sort of 'pattern recognition' problem? For example, if I supply the network with a number of training models - along with labels which describe the design feature which exists in the model, would the network learn to recognise specific adjacency patterns represented in the matrix which relate to certain design features?

I am a complete beginner in machine learning and I am trying to get a handle on whether this approach will work or not - if any more info is needed to understand the problem leave a comment. Any input or help would be appreciated, thanks.

• This looks really interesting. But what triangle are you talking about? Can you draw it for clarity? – FelicityC Nov 9 '18 at 0:47

Would I be right in saying that this becomes a sort of 'pattern recognition' problem?

Technically, yes. In practice: no.

I think you might be interpreting the term "pattern recognition" a bit too literal. Even though wikipedia defines Pattern recognition as "a branch of machine learning that focuses on the recognition of patterns and regularities in data", it's not about solving problems that can "easily" be deduced by logical reasoning.

E.g. you say that

A '1' in the top right triangle in the matrix represents a convex relationship between two faces and a '1' in the bottom left triangle represents a concave relationship

This is true always. In a typical machine learning situation, you wouldn't (usually) have this prior knowledge. At least not to the extent that it would b be tractable to “solve by hand”.

Pattern recognition is conventionally a statistical approach to solving problems when they get too complex to analyze with conventional logical reasoning and simpler regression models. Wikipedia also states (with a source) that pattern recognition "in some cases considered to be nearly synonymous with machine learning".

That being said: you could use pattern recognition on this problem. However, it seems like overkill in this case. Your problem, as far as I can understand, has an actual "analytical" solution. That is: you can, by logic, get a 100% correct result all the time. Machine learning algorithms could, in theory, also do this, and in that case, and this branch of ML is referred to as Meta Modelling.

For example, if I supply the network with a number of training models - along with labels which describe the design feature which exists in the model, would the network learn to recognise specific adjacency patterns represented in the matrix which relate to certain design features?

In a word: Probably. Best way to go? Probably not. Why not, you ask?

There is always the possibility that your model doesn't learn exactly what you want. In addition you have many challenges like overfitting that you'd need to concern yourself about. It's a statistical approach, as I said. Even if it classifies all your test data as 100% correct, there is no way (unless you check the insanely intractable maths) to be 100% sure that it will always classify correctly. I further suspect that you're also likely to end up spending more time working on your model then the time it would take to just deduce the logic.

I also disagree with @Bitzel: I would not do a CNN (convolutional neural network) on this. CNNs are used when you want to look at specific parts of the matrix, and the relation and connectedness between the pixels are important — for example on images. Since you only have 1s and 0s, I strongly suspect that a CNN would be vastly overkill. And with all the sparsity (many zeros) you’d end up with a lot of zeros in the convolutions.

I'd actually suggest a plain vanilla (feed forward) neural network, which, despite the sparsity, I think will be able to do this classification pretty easily.

• Very thorough answer. One short version is that for questions that have an analytical solution, ML is usually not the right approach. – Amrinder Arora Dec 19 '18 at 15:43

As far as I understand, yes your problem is related to pattern recognition. Since the approach is to classify inputs with labels you previously provide for the neural net, I think a convolutional neural networks could work for you problem.

The Problem

The training data for the proposed system is as follows.

• A Boolean matrix representing the surface adjacency of a solid geometric design
• Also represented in the matrix is differentiation between interior and exterior angles of edges
• Labels (described below)

Convex and concave are not the correct terms to describe surface gradient discontinuities. An interior edge, such as made by an end mill, is not actually a concave surface. Surface gradient discontinuity, from the point of view of the idealized solid model, has a zero radius. An exterior edge is not a convex portion of a surface for the same reason.

The intended output of the trained system proposed is a Boolean array indicating the presence of specific solid geometric design features.

• One or more slot
• One or more boss
• One or more holes
• One or more pockets
• One or more steps

This array of Boolean values is also used as labels for training.

Possible Caveats in Approach

There are mapping incongruities in this approach. They fall roughly into one of four categories.

• Ambiguity created by mapping the topology in the CAD model to the matrix — solid geometries that have primary not captured in the matrix encoding proposed
• CAD models for which no matrix exists — cases where edges change from inner to outer angles or emerge from curvature
• Ambiguity in the identification of features from the matrix — overlap between features that could identify the pattern in the matrix
• Matrices describing features that are not among the five — this could become a data loss issue downstream in development

These are just a few examples of topology issues that may be common in some mechanical design domains and obfuscate the data mapping.

• A hole has the same matrix as a box frame with internal radii.
• Holes that intersect with edges may be indistinguishable from other topology in matrix form.
• Two or more intersecting through holes may present adjacency ambiguities.
• Flanges and ribs supporting round bosses with center holes may be indistinguishable.
• A ball and a torus have the same matrix.
• A disk and band with a hexagonal cross with a 180 degree twist have the same matrix.

These possible caveats may or may not be of concern for the project defined in the question.

Setting a face size balances efficiency with reliability but limits usability. There may be approaches that leverage one of the variants of RNNs, which may permit coverage of arbitrary model sizes without compromising efficiency for simple geometries. Such an approach may involve splaying the matrix out as a sequence for each example, applying a well conceived normalization strategy to each matrix. Padding may be effective if there are no tight constraints on training efficiency and a practical maximum for number of faces exists.

Considering Count and Certainty as Output

To handle some of these ambiguities, a certainty $$\in [0.0, 1.0]$$ could be the range of the activation functions of the output cells without changing the labeling of the training data.

The possibility of using a non-negative integer output, as an unsigned binary representation created by aggregating multiple binary output cells, instead of a single Boolean per feature should be at least considered as well. Downstream, the capability to count features may become important.

This leads to five realistic permutations to consider, that could be produced by the trained network for each feature of each solid geometry model.

• Boolean indicating existence
• Non-negative integer indicating instance count
• Boolean and real certainty of one or more instance
• Non-negative integer representing most likely instance count and real certainty of one or more instances
• Non-negative real mean and standard deviation

Pattern Recognition or What?

In the current culture, applying an artificial network to this problem is not normally described as pattern recognition in the sense of computer vision or audio processing. It is thought of as learning a complex functional mapping via convergence in the rough direction of an idea mapping, given proximity, accuracy, and reliability criteria. The parameters of the function $$f$$, given inputs $$\mathcal{X}$$, are driven toward the associated labels $$\mathcal{Y}$$ during training.

$$f(\mathcal{X}) \implies \mathcal{Y}$$

If the concept class being functionally approximated by the network is sufficiently represented in the sample used for training and the sample of training examples is drawn in the same way as the target application will later draw, the approximation is likely to be sufficient.

In the world of information theory, there is a blurring of the distinction between pattern recognition and functional approximation, as there should be in that higher level AI conceptual abstraction.

Feasibility

Would the network learn to map matrices to [the array of] Boolean [indicators] of design features?

If the above listed caveats are acceptable to the project stakeholders, the examples are well labeled and provided in sufficient number, and the data normalization, loss function, hyper-parameters, and layer arrangements are set up well, it is likely convergence will occur during training and a reasonable automated feature identification system. Again, its usability hinges on new solid geometries being drawn from the concept class like the training examples were. System reliability relies on training being representative of later use cases.