cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

How to analyze nested objects?

ptc-4604403
1-Newbie

How to analyze nested objects?

OK, so I need to check whether the object is acceptable for further actions which means:

elements.jpg

Object is a matrix, all I care is that it has more than 1 row and more than 1 column (type 1).

Object is a vector (more than 1 row), its elements are type 1 objects of the same size (type 2).

Object is a vector, its elements are type 2 objects not only of the same size, but also all the type 1 objects within are of the same size (type 3).

In the same fashion we can define type 4, type 5 and so on indefinitely.

I hope you get the idea.

I'm pretty bad at recursion, but I tried, see project.xmcd .

EDIT: Corrected a mistype in the attached file. Still far from working I guess.

1 ACCEPTED SOLUTION

Accepted Solutions

Pranas Pranas wrote:

OK, so I need to check whether the object is acceptable for further actions which means:

Object is a matrix, all I care is that it has more than 1 row and more than 1 column (type 1).

Object is a vector (more than 1 row), its elements are type 1 objects of the same size (type 2).

Object is a vector, its elements are type 2 objects not only of the same size, but also all the type 1 objects within are of the same size (type 3).

In the same fashion we can define type 4, type 5 and so on indefinitely.

I hope you get the idea.

I'm pretty bad at recursion, but I tried, see project.xmcd .

EDIT: Corrected a mistype in the attached file. Still far from working I guess.

I'm not I've understood you correctly, but do you want a 'path' (signature) that indicates the total nesting for each nested element (ie, you could have, in Case 3, a top level object with 3 matrices at the lowest level in the first nested element and another with only 2 matrices) which will allow you to say the 'skeleton' or 'framework' of each nested array is the same?

Is the attached anywhere in the right ballpark?

Stuart

View solution in original post

5 REPLIES 5

Pranas Pranas wrote:

OK, so I need to check whether the object is acceptable for further actions which means:

Object is a matrix, all I care is that it has more than 1 row and more than 1 column (type 1).

Object is a vector (more than 1 row), its elements are type 1 objects of the same size (type 2).

Object is a vector, its elements are type 2 objects not only of the same size, but also all the type 1 objects within are of the same size (type 3).

In the same fashion we can define type 4, type 5 and so on indefinitely.

I hope you get the idea.

I'm pretty bad at recursion, but I tried, see project.xmcd .

EDIT: Corrected a mistype in the attached file. Still far from working I guess.

I'm not I've understood you correctly, but do you want a 'path' (signature) that indicates the total nesting for each nested element (ie, you could have, in Case 3, a top level object with 3 matrices at the lowest level in the first nested element and another with only 2 matrices) which will allow you to say the 'skeleton' or 'framework' of each nested array is the same?

Is the attached anywhere in the right ballpark?

Stuart

Thanks for your response!

I feel I need a signature only so that I could evaluate the specific symmetry I'm looking for (by this symmetry I mean type 1, 2, 3, 4... in the previous post).

Because in the end there will be only a boolean function like IsThisObjectSymmetric(M) .

Here are a few examples

examples.jpg

It is hard for me to describe in words, but there has to be like this perfect tree-like symmetry (number 2 is acceptable because further nesting inside the deepest matrix does not matter).

It might be sufficient to split and manipulate the result of your shapeOf() function in order to evaluate this symmetry, but it is very late in my country, I need some sleep and continue mywork tomorrow.

Best regards.

Edit:

I decided to express the actions which are done by my function in this particular situation:

info.jpg

IsThisObjectSymmetric(C)

If it's a string, scalar or one row matrix (this includes one item array) instantly return false (not the case here).

If it's at least 2x2 matrix instantly return true (not the case here).

If it's a vector continue through its elements (A and B in this case):

If we find a string, scalar or one row matrix instantly return false (not the case here).

If we find matrices of equal size return true (not the case here).

If we find vectors of equal length continue through all of their elements (M1-M6 in this case):

If inside we find a string, scalar or one row matrix instantly return false (not the case here).

If inside we find matrices of equal size return true.

Pranas Pranas wrote:

Thanks for your response!

I feel I need a signature only so that I could evaluate the specific symmetry I'm looking for (by this symmetry I mean type 1, 2, 3, 4... in the previous post).

Because in the end there will be only a boolean function like IsThisObjectSymmetric(M) .

Here are a few examples

It is hard for me to describe in words, but there has to be like this perfect tree-like symmetry (number 2 is acceptable because further nesting inside the deepest matrix does not matter).

It might be sufficient to split and manipulate the result of your shapeOf() function in order to evaluate this symmetry, but it is very late in my country, I need some sleep and continue mywork tomorrow.

Best regards.

Edit:

I decided to express the actions which are done by my function in this particular situation:

IsThisObjectSymmetric(C)

If it's a string, scalar or one row matrix (this includes one item array) instantly return false (not the case here).

If it's at least 2x2 matrix instantly return true (not the case here).

If it's a vector continue through its elements (A and B in this case):

If we find a string, scalar or one row matrix instantly return false (not the case here).

If we find matrices of equal size return true (not the case here).

If we find vectors of equal length continue through all of their elements (M1-M6 in this case):

If inside we find a string, scalar or one row matrix instantly return false (not the case here).

If inside we find matrices of equal size return true.

Unfortunately, I don't have time to look at it further for a day or so, but I would just like to say "My Brain Hurts".

Hello Pranas,

Have you made progress with determining whether an object is symmetric?

Unfortunately, I can' think of a way to test for symmetry, given what I think is your definition, that doesn't involve knowing the shape of an object at every level. AFAICT, every object can determine whether it is symmetric but it doesn't know whether its "sibling" objects have the same symmetry - only the parent can know this (well, there is at least one way but quite frankly it's brutal, inelegant and not worth the effort of programming).

I think it's possible, and fairly simply, to determine overall symmetry from the shapeOf function. If you're still interested, I'll post the method but I wouldn't want to ruin your fun if you're still trying to find a method (if you've solved the problem, I'd be interested to see how our methods compare though and whether I've understood the problem properly).

Stuart

Hello Stuart.

I was working on some other things for the past couple of days.

However I pretty much considered this problem solved even before then - I basically stuck to my own idea, but I believe it is fundamentally similar to evaluating certain patterns in a result provided by your shape function.

I will post more specific details as soon as I get home.

Thank you for such honest interest and congratulations on over 5 years of your membership here

Edit: Attached some thoughts...

Message was edited by: Pranas Pranas

Top Tags