Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   compare several boolean matrix’s (http://www.velocityreviews.com/forums/t957310-compare-several-boolean-matrix-s.html)

keijaf2011@gmail.com 02-05-2013 07:19 PM

compare several boolean matrix’s
 
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

Eric Sosman 02-05-2013 08:47 PM

Re: compare several boolean matrix’s
 
On 2/5/2013 2:19 PM, keijaf2011@gmail.com 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[i] += 1;
if (vec[i])
trues[i] += 1;
}
}
// Announce the winners:
for (int i = 0; i < max; ++i) {
if (trues[i] > win_fraction * votes[i])
System.out.println(i + " is probably true");
else if (trues[i] < lose_fraction * votes[i])
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[i]' value (an
election that goes 7-to-3 is an overwhelming mandate, but one
that goes 10000007-to-10000003 is lawsuit fodder).

--
Eric Sosman
esosman@comcast-dot-net.invalid

Roedy Green 02-06-2013 12:26 AM

Re: compare several boolean matrix’s
 
On Tue, 5 Feb 2013 11:19:58 -0800 (PST), keijaf2011@gmail.com 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

Arne Vajhøj 02-06-2013 12:40 AM

Re: compare several boolean matrix’s
 
On 2/5/2013 2:19 PM, keijaf2011@gmail.com 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 02-06-2013 12:43 AM

Re: compare several boolean matrix’s
 
On 2/5/2013 7:26 PM, Roedy Green wrote:
> On Tue, 5 Feb 2013 11:19:58 -0800 (PST), keijaf2011@gmail.com 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



Arved Sandstrom 02-06-2013 01:09 AM

Re: compare several boolean matrix’s
 
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), keijaf2011@gmail.com 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


Keivan Jafari 02-06-2013 07:21 AM

Re: compare several boolean matrix’s
 
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 02-06-2013 11:23 AM

Re: compare several boolean matrix’s
 
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

Arved Sandstrom 02-06-2013 11:55 AM

Re: compare several boolean matrix’s
 
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

Keivan Jafari 02-06-2013 12:11 PM

Re: compare several boolean matrix’s
 
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)



All times are GMT. The time now is 11:05 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57