473,856 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sample without replacement+int ersect

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: "<<xEPS1cov er[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<NEPS1cov er;i++) oscover<<xEPS1c over[i]<<"\n";
cout<<"R :"<<R<<"\n";
system("PAUSE") ;
return 0;
}
Jun 27 '08 #1
1 2418
On May 6, 8:23 am, Francogrex <fra...@grex.or gwrote:
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: "<<xEPS1cov er[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<NEPS1cov er;i++) oscover<<xEPS1c over[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
1232
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 of keywords. It would be very simple to search for records where the user enters only one keyword, by searching for the keyword within the keyword string in the record. But I'd like to let the user enter more than one keyword, and be able to...
21
2510
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 *)? * Is the support for sets of sets necessary for your work and, if so, then is the implementation sufficiently powerful?
49
2891
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 Vainio http://www.students.tut.fi/~vainio24
1
714
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 show exactly what I want to do. My query in mysql console is working without using intersect or join. $query_objects = ""; for ($i=0; $i<$num_questions; $i++) { if ($i != 0)
3
1530
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 has something to do with an inherited class I have, but I fail to see anything wrong. Here is the problematic code. I've hunted the bug down to this function using gdb and commenting out parts of my code. I originally used CIntersect as a base...
7
1317
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, getLength, etc. The implementation may vary however: I may store tail and tip as Point objects or as pairs of integers, I may store length explicitly or compute it dynamically, etc. Now what I'd like is to be able to provide a common interface...
1
3882
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 from 0.; I found the intersect array $a3 have the correct values but keep the keys of $a1. When I use
14
1664
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 x in s1 return True
2
2595
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 table. For example: Lsts say I have a BlogPostTag table where I store the BlogPostId and the TagId that pertains to this blog post. Further, a BlogPost can be associated to multiple tags. So I could have a BlogPost associated to the tags C# and...
0
9911
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9762
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10696
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10780
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10383
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9530
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5761
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4575
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4174
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.