compare several boolean matrix’s

Discussion in 'Java' started by keijaf2011@gmail.com, Feb 5, 2013.

  1. Guest

    Hi there,

    Is there any way to compare several boolean matrix’s(25 matrix’s) and pick up a final valid matrix of those 25.

    The elements in the valid matrix will be, an example:

    If matrix M(0) to M(5) element(21) have value false

    And if matrix M(6) to M(24) element(21) have value true, Then most probablythe value of element 21 is true, since much more matrix’s shows that that element 21 value is true

    Java code will be mostly appreciated

    Best regards/

    Keivan
    , Feb 5, 2013
    #1
    1. Advertising

  2. Eric Sosman Guest

    On 2/5/2013 2:19 PM, wrote:
    > Hi there,
    >
    > Is there any way to compare several boolean matrix’s(25 matrix’s) and pick up a final valid matrix of those 25.
    >
    > The elements in the valid matrix will be, an example:
    >
    > If matrix M(0) to M(5) element(21) have value false
    >
    > And if matrix M(6) to M(24) element(21) have value true, Then most probably the value of element 21 is true, since much more matrix’s shows that that element 21 value is true
    >
    > Java code will be mostly appreciated


    It sounds like you just want to count the number of true and
    false values at each position, and then decide which is more
    prevalent. Something like this:

    boolean[][] matrix = ...;
    // What's the maximum length of each boolean vector?
    int max = 0;
    for (boolean[] vec : matrix)
    max = Math.max(vec.length, max);
    // Tally the votes:
    int[] votes = new int[max];
    int[] trues = new int[max];
    for (boolean[] vec : matrix) {
    for (int i = 0; i < vec.length; ++i) {
    votes += 1;
    if (vec)
    trues += 1;
    }
    }
    // Announce the winners:
    for (int i = 0; i < max; ++i) {
    if (trues > win_fraction * votes)
    System.out.println(i + " is probably true");
    else if (trues < lose_fraction * votes)
    System.out.println(i + " is probably false");
    else
    System.out.println(i + " is too close to call");
    }

    This can probably be simplified: For example, if you know all
    the vectors have the same length there's no need for the first loop
    or for the `votes' array. On the other hand, finding good values
    for `win_fraction' and `lose_fraction' may be difficult; you may
    even want to adjust them depending on the `votes' value (an
    election that goes 7-to-3 is an overwhelming mandate, but one
    that goes 10000007-to-10000003 is lawsuit fodder).

    --
    Eric Sosman
    d
    Eric Sosman, Feb 5, 2013
    #2
    1. Advertising

  3. Roedy Green Guest

    On Tue, 5 Feb 2013 11:19:58 -0800 (PST), wrote,
    quoted or indirectly quoted someone who said :

    >
    >Is there any way to compare several boolean matrix=92s(25 matrix=92s) and p=
    >ick up a final valid matrix of those 25.


    Java's matrix handling is quite pedestrian because of the way they are
    stored. For heavy duty work use a C library with JNI glue.
    --
    Roedy Green Canadian Mind Products http://mindprod.com
    The first 90% of the code accounts for the first 90% of the development time.
    The remaining 10% of the code accounts for the other 90% of the development
    time.
    ~ Tom Cargill Ninety-ninety Law
    Roedy Green, Feb 6, 2013
    #3
  4. Arne Vajhøj Guest

    On 2/5/2013 2:19 PM, wrote:
    > Is there any way to compare several boolean matrix’s(25 matrix’s) and pick up a final valid matrix of those 25.
    >
    > The elements in the valid matrix will be, an example:
    >
    > If matrix M(0) to M(5) element(21) have value false
    >
    > And if matrix M(6) to M(24) element(21) have value true, Then most probably the value of element 21 is true, since much more matrix’s shows that that element 21 value is true
    >
    > Java code will be mostly appreciated


    I think you need to explain better what you really want.

    You have K matrixes of dimension NxM and you want
    to calculate the result like what?

    Arne
    Arne Vajhøj, Feb 6, 2013
    #4
  5. Arne Vajhøj Guest

    On 2/5/2013 7:26 PM, Roedy Green wrote:
    > On Tue, 5 Feb 2013 11:19:58 -0800 (PST), wrote,
    > quoted or indirectly quoted someone who said :
    >> Is there any way to compare several boolean matrix=92s(25 matrix=92s) and p=
    >> ick up a final valid matrix of those 25.

    >
    > Java's matrix handling is quite pedestrian because of the way they are
    > stored. For heavy duty work use a C library with JNI glue.


    Java does not have builtin matrixes, so it is entirely up
    to the developer how they are stored.

    If the developer stored them as a 1D array, then Java will
    store them exactly like C.

    So JNI would not make any sense in that case.

    ArrayList<ArrayList<Boolean>> would have some overhead that
    may or may not be significant.

    Arne
    Arne Vajhøj, Feb 6, 2013
    #5
  6. On 02/05/2013 08:43 PM, Arne Vajhøj wrote:
    > On 2/5/2013 7:26 PM, Roedy Green wrote:
    >> On Tue, 5 Feb 2013 11:19:58 -0800 (PST), wrote,
    >> quoted or indirectly quoted someone who said :
    >>> Is there any way to compare several boolean matrix=92s(25 matrix=92s)
    >>> and p=
    >>> ick up a final valid matrix of those 25.

    >>
    >> Java's matrix handling is quite pedestrian because of the way they are
    >> stored. For heavy duty work use a C library with JNI glue.

    >
    > Java does not have builtin matrixes, so it is entirely up
    > to the developer how they are stored.
    >
    > If the developer stored them as a 1D array, then Java will
    > store them exactly like C.
    >
    > So JNI would not make any sense in that case.
    >
    > ArrayList<ArrayList<Boolean>> would have some overhead that
    > may or may not be significant.
    >
    > Arne
    >

    Odd suggestion (on Roedy's part) to go to C and JNI for "heavy duty"
    work. Fact is, if your work with arrays/matrices is so "heavy duty" that
    Java even with decent 3rd party numerical libraries is getting painful,
    one had best consider a recent Fortran or Matlab or J or something
    similar...*not* use C (Numerical Recipes notwithstanding...)

    AHS
    Arved Sandstrom, Feb 6, 2013
    #6
  7. Den tisdagen den 5:e februari 2013 kl. 20:19:58 UTC+1 skrev Keivan Jafari:
    > Hi there,
    >
    >
    >
    > Is there any way to compare several boolean matrix’s(25 matrix’s) andpick up a final valid matrix of those 25.
    >
    >
    >
    > The elements in the valid matrix will be, an example:
    >
    >
    >
    > If matrix M(0) to M(5) element(21) have value false
    >
    >
    >
    > And if matrix M(6) to M(24) element(21) have value true, Then most probably the value of element 21 is true, since much more matrix’s shows that that element 21 value is true
    >
    >
    >
    > Java code will be mostly appreciated
    >
    >
    >
    > Best regards/
    >
    >
    >
    > Keivan


    Tankyou all,
    I will look on Eric's suggestion,
    Br/
    Keivan
    Keivan Jafari, Feb 6, 2013
    #7
  8. Hi again,
    some clarification;
    Is there any way to compare several boolean matrix’s(25 matrix’s) and bild a new matrix of those 25.

    The elements in the new matrix will be, an example:

    If matrix M(0) to M(5) element(2, 1) have value false

    And if matrix M(6) to M(24) element(2, 1) have value true,
    Then most probably the value of element(2, 1) is true, since much more matrix’s shows that element(2, 1) is true

    Java code will be mostly appreciated

    All the Matrixes have same size
    NXM

    Best regards/
    Keivan
    Keivan Jafari, Feb 6, 2013
    #8
  9. On 02/06/2013 07:23 AM, Keivan Jafari wrote:
    > Hi again,
    > some clarification;
    > Is there any way to compare several boolean matrix’s(25 matrix’s) and bild a new matrix of those 25.
    >
    > The elements in the new matrix will be, an example:
    >
    > If matrix M(0) to M(5) element(2, 1) have value false
    >
    > And if matrix M(6) to M(24) element(2, 1) have value true,
    > Then most probably the value of element(2, 1) is true, since much more matrix’s shows that element(2, 1) is true
    >
    > Java code will be mostly appreciated
    >
    > All the Matrixes have same size
    > NXM
    >
    > Best regards/
    > Keivan
    >

    One observation, Keivan. Right now this is all conceptual. There are no
    matrices in Java, so really we're talking about how you take many
    datasets (presumably the same size), let's say 25 such datasets, and
    process the combination to come up with one dataset with the same size.

    How others might do this would vary perhaps, but before I ever devised
    an approach I'd want to find out where the data is coming from. After
    all, since the objective is *one* "matrix" of size M x N, why construct
    25 intermediates?

    AHS
    Arved Sandstrom, Feb 6, 2013
    #9
  10. Den onsdagen den 6:e februari 2013 kl. 12:55:50 UTC+1 skrev Arved Sandstrom:
    > On 02/06/2013 07:23 AM, Keivan Jafari wrote:
    >
    > > Hi again,

    >
    > > some clarification;

    >
    > > Is there any way to compare several boolean matrix�s(25 matrix�s) and bild a new matrix of those 25.

    >
    > >

    >
    > > The elements in the new matrix will be, an example:

    >
    > >

    >
    > > If matrix M(0) to M(5) element(2, 1) have value false

    >
    > >

    >
    > > And if matrix M(6) to M(24) element(2, 1) have value true,

    >
    > > Then most probably the value of element(2, 1) is true, since much more matrix�s shows that element(2, 1) is true

    >
    > >

    >
    > > Java code will be mostly appreciated

    >
    > >

    >
    > > All the Matrixes have same size

    >
    > > NXM

    >
    > >

    >
    > > Best regards/

    >
    > > Keivan

    >
    > >

    >
    > One observation, Keivan. Right now this is all conceptual. There are no
    >
    > matrices in Java, so really we're talking about how you take many
    >
    > datasets (presumably the same size), let's say 25 such datasets, and
    >
    > process the combination to come up with one dataset with the same size.
    >
    >
    >
    > How others might do this would vary perhaps, but before I ever devised
    >
    > an approach I'd want to find out where the data is coming from. After
    >
    > all, since the objective is *one* "matrix" of size M x N, why construct
    >
    > 25 intermediates?
    >
    >
    >
    > AHS

    tankyou.

    Consider a matrix as a picture of size boolean[N][M]
    the elements can only get value true or false.
    So I have 25 picture's(Matrix's), I want to build a new picture(Matrix) based
    on 25 picture's(Matrix's)
    Keivan Jafari, Feb 6, 2013
    #10
  11. On 02/06/2013 08:11 AM, Keivan Jafari wrote:
    > Den onsdagen den 6:e februari 2013 kl. 12:55:50 UTC+1 skrev Arved Sandstrom:
    >> On 02/06/2013 07:23 AM, Keivan Jafari wrote:
    >>
    >>> Hi again,

    >>
    >>> some clarification;

    >>
    >>> Is there any way to compare several boolean matrix�s(25 matrix�s) and bild a new matrix of those 25.

    >>
    >>>

    >>
    >>> The elements in the new matrix will be, an example:

    >>
    >>>

    >>
    >>> If matrix M(0) to M(5) element(2, 1) have value false

    >>
    >>>

    >>
    >>> And if matrix M(6) to M(24) element(2, 1) have value true,

    >>
    >>> Then most probably the value of element(2, 1) is true, since much more matrix�s shows that element(2, 1) is true

    >>
    >>>

    >>
    >>> Java code will be mostly appreciated

    >>
    >>>

    >>
    >>> All the Matrixes have same size

    >>
    >>> NXM

    >>
    >>>

    >>
    >>> Best regards/

    >>
    >>> Keivan

    >>
    >>>

    >>
    >> One observation, Keivan. Right now this is all conceptual. There are no
    >>
    >> matrices in Java, so really we're talking about how you take many
    >>
    >> datasets (presumably the same size), let's say 25 such datasets, and
    >>
    >> process the combination to come up with one dataset with the same size.
    >>
    >>
    >>
    >> How others might do this would vary perhaps, but before I ever devised
    >>
    >> an approach I'd want to find out where the data is coming from. After
    >>
    >> all, since the objective is *one* "matrix" of size M x N, why construct
    >>
    >> 25 intermediates?
    >>
    >>
    >>
    >> AHS

    > tankyou.
    >
    > Consider a matrix as a picture of size boolean[N][M]
    > the elements can only get value true or false.
    > So I have 25 picture's(Matrix's), I want to build a new picture(Matrix) based
    > on 25 picture's(Matrix's)
    >

    What I'm getting at is, you say you've got 25 pictures (2D arrays I'd
    prefer to call them in this scenario). How exactly do you have them?
    Actual pixel data from images? Data from somewhere else?

    Regardless of where the data comes from, I doubt that I would ever
    construct 25 intermediate 2D arrays. If I had an intermediate at all
    there would only be one.

    AHS
    Arved Sandstrom, Feb 6, 2013
    #11
  12. Den onsdagen den 6:e februari 2013 kl. 13:24:27 UTC+1 skrev Arved Sandstrom:
    > On 02/06/2013 08:11 AM, Keivan Jafari wrote:
    >
    > > Den onsdagen den 6:e februari 2013 kl. 12:55:50 UTC+1 skrev Arved Sandstrom:

    >
    > >> On 02/06/2013 07:23 AM, Keivan Jafari wrote:

    >
    > >>

    >
    > >>> Hi again,

    >
    > >>

    >
    > >>> some clarification;

    >
    > >>

    >
    > >>> Is there any way to compare several boolean matrix�s(25 matrix�s) and bild a new matrix of those 25.

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> The elements in the new matrix will be, an example:

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> If matrix M(0) to M(5) element(2, 1) have value false

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> And if matrix M(6) to M(24) element(2, 1) have value true,

    >
    > >>

    >
    > >>> Then most probably the value of element(2, 1) is true, since much more matrix�s shows that element(2, 1) is true

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> Java code will be mostly appreciated

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> All the Matrixes have same size

    >
    > >>

    >
    > >>> NXM

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >>> Best regards/

    >
    > >>

    >
    > >>> Keivan

    >
    > >>

    >
    > >>>

    >
    > >>

    >
    > >> One observation, Keivan. Right now this is all conceptual. There are no

    >
    > >>

    >
    > >> matrices in Java, so really we're talking about how you take many

    >
    > >>

    >
    > >> datasets (presumably the same size), let's say 25 such datasets, and

    >
    > >>

    >
    > >> process the combination to come up with one dataset with the same size..

    >
    > >>

    >
    > >>

    >
    > >>

    >
    > >> How others might do this would vary perhaps, but before I ever devised

    >
    > >>

    >
    > >> an approach I'd want to find out where the data is coming from. After

    >
    > >>

    >
    > >> all, since the objective is *one* "matrix" of size M x N, why construct

    >
    > >>

    >
    > >> 25 intermediates?

    >
    > >>

    >
    > >>

    >
    > >>

    >
    > >> AHS

    >
    > > tankyou.

    >
    > >

    >
    > > Consider a matrix as a picture of size boolean[N][M]

    >
    > > the elements can only get value true or false.

    >
    > > So I have 25 picture's(Matrix's), I want to build a new picture(Matrix)based

    >
    > > on 25 picture's(Matrix's)

    >
    > >

    >
    > What I'm getting at is, you say you've got 25 pictures (2D arrays I'd
    >
    > prefer to call them in this scenario). How exactly do you have them?
    >
    > Actual pixel data from images? Data from somewhere else?
    >
    >
    >
    > Regardless of where the data comes from, I doubt that I would ever
    >
    > construct 25 intermediate 2D arrays. If I had an intermediate at all
    >
    > there would only be one.
    >
    >
    >
    > AHS


    I don't have them as exact, that's why I want to extract a exact picture ofthose 25 pictures.

    The pixels are as boolean element true or false.
    Br/
    Keivan
    Keivan Jafari, Feb 6, 2013
    #12
  13. Den tisdagen den 5:e februari 2013 kl. 20:19:58 UTC+1 skrev Keivan Jafari:
    > Hi there,
    >
    >
    >
    > Is there any way to compare several boolean matrix’s(25 matrix’s) andpick up a final valid matrix of those 25.
    >
    >
    >
    > The elements in the valid matrix will be, an example:
    >
    >
    >
    > If matrix M(0) to M(5) element(21) have value false
    >
    >
    >
    > And if matrix M(6) to M(24) element(21) have value true, Then most probably the value of element 21 is true, since much more matrix’s shows that that element 21 value is true
    >
    >
    >
    > Java code will be mostly appreciated
    >
    >
    >
    > Best regards/
    >
    >
    >
    > Keivan



    No, check below:

    matrix 1
    0 | 1 | 0
    1 | 1 | 0
    0 | 0 | 1

    matrix 2
    1 | 1 | 1
    0 | 1 | 0
    1 | 1 | 1

    matrix 3
    0 | 0 | 1
    0 | 0 | 1
    1 | 1 | 0


    Result will be as below:
    example:
    consider element (0,0) of matrix's above:
    since maximum amount of matrix's(matrix1 and matrix3) says that element(0,0) is false, then I chose false at element (0,0) in result matrix

    consider another element element (2,0) of matrix's above:
    since maximum amount of matrixes(matrix2 and matrix3) says that element(2,0) is true, then I chose true at element (2,0) in result matrix

    Here is result matrix:

    0 | 1 | 1
    0 | 1 | 0
    1 | 1 | 1
    Keivan Jafari, Feb 6, 2013
    #13
  14. Den tisdagen den 5:e februari 2013 kl. 20:19:58 UTC+1 skrev Keivan Jafari:
    > Hi there,
    >
    >
    >
    > Is there any way to compare several boolean matrix’s(25 matrix’s) andpick up a final valid matrix of those 25.
    >
    >
    >
    > The elements in the valid matrix will be, an example:
    >
    >
    >
    > If matrix M(0) to M(5) element(21) have value false
    >
    >
    >
    > And if matrix M(6) to M(24) element(21) have value true, Then most probably the value of element 21 is true, since much more matrix’s shows that that element 21 value is true
    >
    >
    >
    > Java code will be mostly appreciated
    >
    >
    >
    > Best regards/
    >
    >
    >
    > Keivan


    Yes,there will be always an odd number of input matrix's (25 matrix's)
    Keivan Jafari, Feb 6, 2013
    #14
  15. Den tisdagen den 5:e februari 2013 kl. 20:19:58 UTC+1 skrev Keivan Jafari:
    > Hi there,
    >
    >
    >
    > Is there any way to compare several boolean matrix’s(25 matrix’s) andpick up a final valid matrix of those 25.
    >
    >
    >
    > The elements in the valid matrix will be, an example:
    >
    >
    >
    > If matrix M(0) to M(5) element(21) have value false
    >
    >
    >
    > And if matrix M(6) to M(24) element(21) have value true, Then most probably the value of element 21 is true, since much more matrix’s shows that that element 21 value is true
    >
    >
    >
    > Java code will be mostly appreciated
    >
    >
    >
    > Best regards/
    >
    >
    >
    > Keivan


    Exactly!
    Do you know how to put the algorithm in java?
    I would appreciate java code.

    Br/
    Keivan
    Keivan Jafari, Feb 6, 2013
    #15
  16. Den tisdagen den 5:e februari 2013 kl. 20:19:58 UTC+1 skrev Keivan Jafari:
    > Hi there,
    >
    >
    >
    > Is there any way to compare several boolean matrix’s(25 matrix’s) andpick up a final valid matrix of those 25.
    >
    >
    >
    > The elements in the valid matrix will be, an example:
    >
    >
    >
    > If matrix M(0) to M(5) element(21) have value false
    >
    >
    >
    > And if matrix M(6) to M(24) element(21) have value true, Then most probably the value of element 21 is true, since much more matrix’s shows that that element 21 value is true
    >
    >
    >
    > Java code will be mostly appreciated
    >
    >
    >
    > Best regards/
    >
    >
    >
    > Keivan

    tankyou.
    yes maybe!
    Keivan Jafari, Feb 6, 2013
    #16
  17. Lars Enderin Guest

    2013-02-06 17:42, Keivan Jafari skrev:
    > tankyou.
    > yes maybe!
    >


    What post does your reply refer to?
    Google Groups is a bad interface to Usenet, granted, but you should not
    make all your posts replies to your first post. Please reply to the post
    you are commenting on!
    (And the plural of matrix is matrices.)

    --
    Lars Enderin
    Lars Enderin, Feb 6, 2013
    #17
  18. Den onsdagen den 6:e februari 2013 kl. 18:09:04 UTC+1 skrev Lars Enderin:
    > 2013-02-06 17:42, Keivan Jafari skrev:
    >
    > > tankyou.

    >
    > > yes maybe!

    >
    > >

    >
    >
    >
    > What post does your reply refer to?
    >
    > Google Groups is a bad interface to Usenet, granted, but you should not
    >
    > make all your posts replies to your first post. Please reply to the post
    >
    > you are commenting on!
    >
    > (And the plural of matrix is matrices.)
    >
    >
    >
    > --
    >
    > Lars Enderin


    sorry! I'm new.
    My reply was for lipska the kat
    Keivan Jafari, Feb 6, 2013
    #18
  19. Den onsdagen den 6:e februari 2013 kl. 18:19:58 UTC+1 skrev lipska the kat:
    > On 06/02/13 16:42, Keivan Jafari wrote:
    >
    > > Den tisdagen den 5:e februari 2013 kl. 20:19:58 UTC+1 skrev Keivan Jafari:

    >
    > >> Hi there,

    >
    > >>

    >
    >
    >
    > [snip]
    >
    >
    >
    > > yes maybe!

    >
    >
    >
    > Oh dear, I don't think your professor will be too pleased will he/she
    >
    >
    >
    > Have you used Java before ?
    >
    >
    >
    > lipska
    >
    >
    >
    > --
    >
    > Lipska the Kat©: Troll hunter, sandbox destroyer
    >
    > and farscape dreamer of Aeryn Sun


    I'm too old and busy!
    Please stick to the problem, take it as a challenge!
    Keivan Jafari, Feb 6, 2013
    #19
  20. Lars Enderin Guest

    2013-02-06 18:14, Keivan Jafari skrev:
    > sorry! I'm new.
    > My reply was for lipska the kat
    >


    I see that you are new (and that you probably are posting from Sweden,
    like me). You did reply to me correctly, so you do know how to do it. It
    helps to keep message threads consistent. A traditional news client may
    have a little trouble otherwise.

    --
    Lars Enderin
    Lars Enderin, Feb 6, 2013
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lvcargnini

    Matrix composed by two matrix

    lvcargnini, Jul 4, 2006, in forum: VHDL
    Replies:
    3
    Views:
    2,671
    Jonathan Bromley
    Jul 5, 2006
  2. J Leonard
    Replies:
    4
    Views:
    12,671
    Mark Space
    Jan 19, 2008
  3. Gustavo Rondina

    Storage of symmetric boolean matrix

    Gustavo Rondina, Jun 27, 2009, in forum: C Programming
    Replies:
    9
    Views:
    468
    Flash Gordon
    Jun 29, 2009
  4. Victor \Zverok\ Shepelev

    RDOC: several related modules in several C files

    Victor \Zverok\ Shepelev, Mar 6, 2007, in forum: Ruby
    Replies:
    3
    Views:
    182
    Max Lapshin
    Mar 16, 2007
  5. Metre Meter
    Replies:
    7
    Views:
    370
    Metre Meter
    Aug 6, 2010
Loading...

Share This Page