Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Matrix decomposition" of a matrix with holonic sub structure

Tags:

c++

python

c#

Before I start, I must say that for those with a background of linear algebra, this is NOT matrix decomposition as you know it. Please read the following paragraphs to get a clearer understanding of the problem I am trying to solve.

Here are the salient properties/definitions of the matrix and its submatrices:

  1. I have an SxP matrix which forms a grid like structure of S.P "boxes". This is the main matrix.

This is what the (empty) main matrix looks like. Each square in the matrix is simply referred to as a box. The matrix can be viewed as a a kind of "gameboard" e.g. a chess board. The vertical axis is measured using an interval scale (i.e. real numbers), and the horizontal axis is measured using monotonically increasing non-negative integers.

An empty matrix

  1. There is an additional concept of submatrices (as explained earlier). A submatrix is simply a collection of boxes in a particular configuration, and with specific numbers and piece types (see black and white pieces below), assigned to the boxes. I have a finite set of these sub matrices - which I refer to as my lexicon or vocabulary for carrying out valid matrix composition/decompositions.

The "formal" definition of a sub matrix is that it is a configuration of M boxes contained within the main matrix, that satisfy the criteria:

  • 1 <=M<= 4
  • the "gap" G (i.e. distance) between any two adjacent boxes satisfies: 1<= G<= 2*(vertical units).

A vertical unit is the gap between the vertical axis lines in the main matrix. In the image below, the vertical unit is 100.

simple submatrix addition

The image immediately above illustrates a simple sub matrix addition. The units with orange boarders/boxes are sub matrices - the recognized units that form part of my lexicon. You will notice that I have introduced further annotation in my sub matrices. This is because (using the chess analogy), I have two types of pieces I can use on the board. B means a black piece, and W (not shown in the image), represents a white piece. A recognized unit (or lexeme/sub matrix) There is a simple equivalence relation that allows conversion between a white piece and a black piece. This relationship can be used to further decompose a submatrix to use either exclusively black pieces, white pieces or a combination of both.

For the sake of simplicity, I have omitted specifying the equivalence relationship. However, if someone feels that the problem as posed is not "too difficult" without additional details, I shall gladly broaden the scope. For now, I am trying to keep things as simple as possible, to avoid confusing people with "information overload".

  1. Each box in a sub matrix contains a signed integer, indicating a number of units of an item. Each "configuration" of boxes (along with its signed integers and piece type i.e. black or white pieces) is said to be a "recognized unit".

  2. Submatrices can be placed in the main matrix in a way such that they overlap. Wherever the "boxes" overlap, the number of units in the resulting submatrix box is the sum of the number of units in the constituent boxes (as illustrated in the second image above).

The problem becomes slightly difficult because, the "recognized units" defined above themselves are sometimes combined with other "recognized units" to form another "recognized unit" - i.e. the sub matrices (i.e.recognized units) are "holons". For example, in the second image above, the recognized unit being added to the matrix can itself be further decomposed into "smaller" submatrices.

This sort of holarchy is similar to how (in Physical chemistry), elements form compounds, which then go on to form ever more complicated compounds (amino acids, proteins etc).

Back to our problem, given a main matrix M, I want to be able to do the following:

i. identify the submatrices (or recognized units) that are contained within the main matrix. This is the first "matrix decomposition". (Note: a submatrix has to satisfy the criteria given above)

ii. For each identified submatrix, I want to be able to recognize whether it can be decomposed further into 2 or more recognized submatrices. The idea is to iteratively decompose submatrices found in step i above, until either a specified hierarchy level is reached, or until we have a finite set of submatrices that can not be decomposed further.

I am trying to come up with an algorithm to help me do (i) and (ii) above. I will implement the logic in either C++, Python or C# (in increasing level of preference), depending on which ever is the easiest to do and/or in which I happen to get snippets to get me started in implementing the algorithm.

like image 415
skyeagle Avatar asked Sep 13 '10 21:09

skyeagle


1 Answers

I am not sure if i have a understand correctly the problem.

So first ypu want to find all submatrixes that conform with your 2 criterea. Thats like a graph decomposition problem or a set coverage problem i think, where you can have a recursive function and iterate the matrix to find all available submatrixes.

enum PieceTypes
{
    White,
    Black
}

class Box
{
    public PieceTypes PieceType { get; set; }

    public uint Units { get; set; }

    public int s, p;
    public Box(PieceTypes piecetype, uint units)
    {
        PieceType = piecetype;
        Units = units;
    }
}

class Matrix
{
    public Box[,] Boxes;
    public int Scale, S, P, MaxNum, MaxDist;
    public List<List<Box>> Configurations;
    public Matrix(int s, int p, int scale, int maxnum, int maxdist)
    {
        S = s;
        P = p;
        Scale = scale;
        Boxes = new Box[S, P];
        MaxNum = maxnum;
        MaxDist = maxdist;
        Configurations = new List<List<Box>>();
    }

    public void Find(List<Box> Config, int s, int p)
    {
        // Check the max number thats valid for your configuration
        // Check that the current p and s are inside matrix
        if (Config.Count() < MaxNum && s >= 0 && s < S && p >= 0 && p < P)
        {

            foreach (Box b in Config)
            {
                if (Valid(b, Boxes[s, p]))
                {
                    Boxes[s, p].s = s;
                    Boxes[s, p].p = p;
                    Config.Add(Boxes[s, p]);
                    break;
                }

            }
            Find(Config, s + 1, p);
            Find(Config, s - 1, p);
            Find(Config, s, p + 1);
            Find(Config, s, p - 1);
        }
        if (Config.Count() > 0) Configurations.Add(Config);
        Config.Clear();
    }

    public bool Valid(Box b1, Box b2)
    {
        // Create your dist funtion here
        // or add your extra validation rules like the PieceType
        if (Math.Sqrt((b1.s - b2.s) ^ 2 + (b1.p - b2.p) ^ 2) <= MaxDist && b1.PieceType == b2.PieceType) return true;
        else return false;
    }

}

I haven't used the best data structures and i have simplified the solution. I hope its some way helpful.

like image 155
Iraklis Avatar answered Nov 14 '22 22:11

Iraklis