473,383 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Sample without replacement+intersect

Hi, I'm trying to sample without replacement some numbers (xons:70
values out of 1 to 200 and xEPS1cover:150 values out of 1 to 200).
Then I'm trying to intersect both samples to see how many are in
common. I have tried to write the code below, but I cannot seem to
sample without replacement (there are recurrent numbers within the
same sample, I don't want that) and I cannot either find the exact
intersection between the two samples. Can anyone please help or give
some hints. Thanks

#include <iostream>
#include <fstream>
using namespace std;

int main(){
ofstream osdis("dis.txt");
ofstream oscover("cover.txt");
srand(10);
int Ntot=200;
int Nons=70;
int i=0,j=0,r=0,t=0;
int xtot[200];
int xons[Ntot];
for (int i = 0; i < Ntot; i++){
xtot[i] = i;
}
for (int i = 0; i < Nons; i++) {
r = rand()%Ntot + 0;
t = xtot[r];
xtot[r] = xtot[i];
xons[i] = t;
}
int NEPS1cover=150;
int xEPS1cover[NEPS1cover];
for (int i = 0; i < NEPS1cover; i++) {
r = rand()%Ntot + 0;
t = xtot[r];
xtot[r] = xtot[i];
xEPS1cover[i] = t;
}
int R=0,u=0;
int xEPS1expected[NEPS1cover];
while(u<Nons){
int v=0;
while (v<NEPS1cover){
cout<<"dis: "<<xons[u]<<"\n";
cout<<"cover: "<<xEPS1cover[v]<<"\n";
if (xons[u]==xEPS1cover[v]){
printf("YES\n");
R=R+1;
}
v=v+1;
}
u=u+1;
}
for (j=0;j<Nons;j++) osdis<<xons[j]<<"\n";
for (i=0;i<NEPS1cover;i++) oscover<<xEPS1cover[i]<<"\n";
cout<<"R :"<<R<<"\n";
system("PAUSE");
return 0;
}
Jun 27 '08 #1
1 2392
On May 6, 8:23 am, Francogrex <fra...@grex.orgwrote:
Hi, I'm trying to sample without replacement some numbers (xons:70
values out of 1 to 200 and xEPS1cover:150 values out of 1 to 200).
Then I'm trying to intersect both samples to see how many are in
common. I have tried to write the code below, but I cannot seem to
sample without replacement (there are recurrent numbers within the
same sample, I don't want that) and I cannot either find the exact
intersection between the two samples. Can anyone please help or give
some hints. Thanks

#include <iostream>
#include <fstream>
using namespace std;

int main(){
ofstream osdis("dis.txt");
ofstream oscover("cover.txt");
srand(10);
int Ntot=200;
int Nons=70;
int i=0,j=0,r=0,t=0;
int xtot[200];
int xons[Ntot];
for (int i = 0; i < Ntot; i++){
xtot[i] = i;}

for (int i = 0; i < Nons; i++) {
r = rand()%Ntot + 0;
t = xtot[r];
xtot[r] = xtot[i];
xons[i] = t;}

int NEPS1cover=150;
int xEPS1cover[NEPS1cover];
for (int i = 0; i < NEPS1cover; i++) {
r = rand()%Ntot + 0;
t = xtot[r];
xtot[r] = xtot[i];
xEPS1cover[i] = t;}

int R=0,u=0;
int xEPS1expected[NEPS1cover];
while(u<Nons){
int v=0;
while (v<NEPS1cover){
cout<<"dis: "<<xons[u]<<"\n";
cout<<"cover: "<<xEPS1cover[v]<<"\n";
if (xons[u]==xEPS1cover[v]){
printf("YES\n");
R=R+1;}
v=v+1;
}
u=u+1;
}

for (j=0;j<Nons;j++) osdis<<xons[j]<<"\n";
for (i=0;i<NEPS1cover;i++) oscover<<xEPS1cover[i]<<"\n";
cout<<"R :"<<R<<"\n";
system("PAUSE");
return 0;

}
Add comments, document requirements and algorithm, use meaningful
variable and function names such that people can decipher your code
without spending an hour analyzing things like "what the hell is
NEPS1cover?" and "Whats a Nons?", "is there some reason a variable is
capitol R while others are lower case u and v? Is he trying to say
something there?". Glancing over the code as is, I don't have enough
kindness in my heart to try and figure it out and follow it.
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: glakk | last post by:
I want to build an application that would let people search records of content, based on keywords. The content record table would have a field called 'tags' which would be a comma-seperated string...
21
by: Raymond Hettinger | last post by:
I've gotten lots of feedback on the itertools module but have not heard a peep about the new sets module. * Are you overjoyed/outraged by the choice of | and & as set operators (instead of + and...
49
by: Ville Vainio | last post by:
I don't know if you have seen this before, but here goes: http://text.userlinux.com/white_paper.html There is a jab at Python, though, mentioning that Ruby is more "refined". -- Ville...
1
by: sunaina | last post by:
I am doing the following query using intersect but gives me an error 'error in sql syntax. I tried using join as well but gives me similar error. In the following code still has intersect just to...
3
by: Brad Moore | last post by:
Hey All, I need help with debugging some code, if this isn't the correct newsgroup to ask in, disregard this message. I'm having difficulty pinpointing a memory leak in my code, I believe it...
7
by: Mark P | last post by:
I working frequently with similar but distinct geometric objects. For example, a collection of Edge classes. All Edge classes should support certain basic functions, such as getTail(), getTip,...
1
by: duzhidian | last post by:
hello all, I only use indexed arrays. When I use array_intersect function, of $a3 = array_intersect( $a1, $a2 ), I just need the vales of intersect array and let keys to be re-numberred...
14
by: David Abrahams | last post by:
Here's an implementation of the functionality I propose, as a free-standing function: def intersects(s1,s2): if len(s1) < len(s2): for x in s1: if x in s2: return True else: for x in s2: if...
2
by: skumar2008 | last post by:
I've seen a number of solution for INTERSECT in MSSQL 2000 but all the examples I've seen go across two tables. What I need is to be able to INTERSECT records with multiple criteria from the same...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.