• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to monitor a random trial experiment  RSS feed

 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Please help me with the below logical problem.




Below is the output i hope to get,

2:pass
2:pass
3:fail
3:fail
2:pass
3:fail
3:fail
4:pass
4:pass
0:pass
5:fail
0:pass
4:pass
0:pass
3:fail
3:fail
2:pass
1:fail
4:pass
0:fail
5:fail
3:fail
2:fail
5:fail
5:fail
1:fail
4:fail

I tried different methods. But eventually they all get very complicated.

Thanks,
John Eipe

 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



replace for with while(true) ... just iterate till your condition is met and break the loop.





 
Campbell Ritchie
Marshal
Posts: 56221
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you actually want a six-repetition loop you are better using a proper counter-controlled repetition
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read this requirement (from the code comments):
monitor if the function (changePosition) returned false consecutively for all 6 values
i.e., contiue the trials (and the loop) until i get the above result.

and I think


Now it is just a matter of building the inside of the while look so you count consecutiveFalses only. For example:
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is also a problem with this statement, though:
monitor if the function (changePosition) returned false consecutively for all 6 values

You are using a random number generator to generate the 6 consecutive values. It is unlikely you will get 'all 6 values' consecutively. For example, what if the number generates makes:
1,2,3,2,2,1

And the failure test returns failure for all 6 of those values? Does that fit your requirement to stop because it is 6 consecutive failures? Or should it keep going until 1-6 are picked consecutively AND all 6 values returned false?
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Steve,

If you look at my model output you'll get an idea. Actually, what i mean is to get false for all 6 [0,1,2,3,4,5] in any order
for eg:
0:fail
5:fail
3:fail
2:fail
5:fail
5:fail
1:fail
4:fail

One possible solution that I tried was to capture last 10 values [t] of the random test. (These 10 values will be updated as the trials progresses.) But once you get 10, check if all these had returned false and also check if all 6 values have been tested.

The value 10 is based upon one's discretion. It's better to use 10 or higher values so that there exits a possibility that all 6 values are tested within.

Did I messed it up?

Thanks,
John Eipe
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please let me know if I need to put the real complete code here.

Thanks,
John Eipe
 
John Bengler
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about using a set with the number as the unique elements?

If you receive false you store the number, if you receive true you remove it from the set.

When the set holds 6 values you know that you received false for all 6 numbers.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Bengler wrote:How about using a set with the number as the unique elements?

If you receive false you store the number, if you receive true you remove it from the set.

When the set holds 6 values you know that you received false for all 6 numbers.


This is what I was thinking. Then you don't have to worry about sizing the array. Though I think if you return true you would clear the Set. You start over again when a 'pass' comes along, correct?
 
John Bengler
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course, you're right, clearing the set would be correct.
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally found a working solution. Here is the complete code. [implemented in Knights Tour problem]


I never expected such a small requirement would lead me to such complicated code

Thanks,
John Eipe>
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Is there any way to ease this? Any other simpler method - just curious to know!

John Eipe>
 
Campbell Ritchie
Marshal
Posts: 56221
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never write == false or == true. It is only a matter of time before you write = by mistake and you can cause all sorts of errors.

It is

if (passOrFail) . . . //(for true) or

if (!passOrFail) . . . // (for false).
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the code for using the Set would be easier. I think your code would end up looking something like this:


There is probably a more efficient approach, as well. For example, you are testing 8 values. If 3 fails once, it will always fail for that position. So instead of generating a random number from 0-7, where 3 could be repeated why not use an array of values, 0-7, shuffle them, then only test each one once. That probably takes away the need for using the failureSet as well. The most possible comparisons for any one position then would be 8. I won't show you the code, but you can look up the the API. The base for this approach would be
1) An int[] = { 0,1,2,3,4,5,6,7 }
2) A method from the Arrays utility class which turns an int[] into a List<Integer>
3) A method from the Collections utility class which will shuffle the values in the List<Integer>

Then, for each success, you shuffle the possible moves to get a new random order, and test the first possible move. For each failure you test the next possible move till you get to the 8th, and if that fails, your done.
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Steve. That's some real thought there.

I haven't looked into Collection so I didn't think of implementing them :-(. I would look into it soon. It seems very useful.

Thanks everyone.

Regards,
John Eipe
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!