C/C++ :: Statistical Analysis Of Vector Data Set Of Integers - Frequency Distribution?
Feb 16, 2014
I am working on my second c++ project that is a statistical analysis of a vector data set of integers. I created a struct called range with a maximum value, minimum value and count for occurrence. The frequencies are stored in a vector<range>.
I have tried messing around with the increment to get the high range test above the maximum element, though my ranges cumulatively increase by 9.9. I'm not sure how the professor's program has the distance between high and low ranges as 10 instead of 9.9, which is the increment. I'm also unsure why half way through his buckets, the ranges appear as 9.99 briefly and then return to 10 after (40.00 - 49.99 then 49.99 - 59.99). I feel like I am missing something very obvious on line 04 or 10 in my code.
Here is the code for the frequency that accepts a vector reference for my data set of integers.
Create a program that finds all numbers in an array that show up exactly 5 times. I am trying to solve this issue by making a frequency distribution via two loops and two arrays, but I am having trouble getting my loop to not recount a number it has already counted.
For example, if you enter ten 1's into the "entered Numbers" array I want it to store a count of 10 in frequencyarray[1]. Instead it is storing
I am trying to print out the letter frequency of a vector that the user inputs and what number that letter is in the ASCII. I am supposed to say, for example: "w" which is ASCII 119 occurs 2 times. How to do this?
In my problem I am to create a base class to represent a four vector (a concept in physics involving a four dimensional vector) then create a derived class specifically to represent the four momentum of a particle which inherits from the base class. I have been supplied a small piece of code to use to generate a 'random' x y and z component of the momentum magnitude. The code is as follows
#include <cstdlib> double triangular(double momentum){ double x, y; do{ x = momentum*rand()/RAND_MAX; y = x/momentum; } while (1.0*rand()/RAND_MAX > y); return x; }
It is said in my problem that this code is supposed to generate the magnitude, and then randomly split into x, y and z components. This code returns a single value and so I cannot see how it is doing what it says in the problem.
I'm implementing an normal_distribution to select objects on a vector. The thing is I can't use values greater then 1 or less then -1. Here is what could be done:
The question is if the distribution would loose it's power to be a normal distribution, because some of the gerated numbers wouldn't be used. Any way to set ranges for the distribution?
I am trying to make a 5x3 2D-vector of integers, then set its i-capacity to be 5 and j-capacity to be 3, i.e:
vec2D[i][j] i = 1,2,3,4,5 j = 1,2,3
and then assign integer values to it.
#include <vector> #include <iostream> using namespace std; int main () { vector<vector<int> > vec2D;
[Code] ....
It compiles, but does not work properly:
Test.exe exited with code -1073741819
i-capacity before reserve: 0 i-capacity after reserve: 5
i = 0 j-capacity before reserve: 336043326 j-capacity after reserve: 336043326 i = 1 j-capacity before reserve: 4282929217 j-capacity after reserve: 4282929217 Press <RETURN> to close this window...
I am trying to convert a C code with dynamic 2D arrays, to a C++ code. I prefer to keep the vec2D[i][j] = ... way of assignment instead of using vec2D.push_back(...).
1. Write a c++ program to create a vector of integers. copy the vector contents into list, sort the contents, then copy selected items into another vector(like elements less than 10 etc)
You are to write a C++ program to generate random integers in the range [ LOW = 1, HIGH = 10000 ] and to store them in a vector < int > of size VEC_SIZE = 250. Then, sort the contents of the vector (in ascending order) and display it on stdout.
To sort the contents of a vector, use the sort ( ) function from the STL. In addition to the main ( ) routine, implement the following subroutines in your program:
• void genRndNums ( vector < int >& v ) : This routine generates VEC_SIZE integers and puts them in vector v. Initializes the random number generator (RNG) by calling the function srand ( ) with the seed value SEED = 1, and generates random integers by calling the function rand ( ).
• void printVec ( const vector < int >& v ) : This routine displays the contents of vector v on stdout, printing exactly NO_ITEMS = 12 numbers on a single line, except perhaps the last line. The sorted numbers need to be properly aligned on the output. For each printed number, allocate ITEM_W = 5 spaces on stdout.
Programming Notes:
• You are not allowed to use any I/O functions from the C library, such as scanf or printf. Instead, use the I/O functions from the C++ library, such as cin or cout. • Let v be a vector of integers, then the call: sort ( v.begin ( ), v.end ( ) ) sorts the elements of v in ascending order. The detailed description of the sort ( ) routine can be found on the course web site and in the course textbook. • Execute the srand ( ) function only once before generating the first random integer with the given seed value SEED. The rand ( ) function generates a random integer in the range [ 0, RAND_MAX ], where the constant value RAND_MAX is the largest random integer returned by the rand ( ) function and its value is system dependent. To normalize the return value to a value in the range [ LOW, HIGH ], execute: rand ( ) % ( HIGH – LOW + 1 ) + LOW.
I tried to sort a large numbers of vector of random integers with std::sort(), but when the number increases over 10M, std::sort returns all zero in values. Does std::sort have a limitation of input numbers?
I am looking to write a program that, given a particular word, looks at a plain text document and gives a list of words that appear within x words of the given word along with a count of how many times it appears.
Do I need to use regex to do the pattern matching here? Is there a particular data structure that I should use that is particularly suited to a task like this? I don't want to reinvent the wheel, it seems like there should be libraries that would already do this sort of thing but searches have turned up nothing.
Undirected graph G = {V, E} is given by the list next to the DS. Let u, v of V. Construction of two paths algorithm A1 (u, v) and A2 (u, v) such that no edge in common and have the shortest total length.
I have the problem of trying to find the smallest natural number that makes two consecutive terms in single precision floating point notation in the riemann zeta function equal. So basically the riemann function of 2 is given by:
sum of 1/(k^2) from k=1 until infinity, so : 1/(1^2) + 1/(2^2) + 1/(3^2) + ...... until infinity.
Now the question asks to stop at the smallest natural number n, at which the sum 1/1^2 + 1/2^2 + ......+ 1/(n^2) is equal to the sum 1/1^2 + 1/2^2 + ..... + 1/((n+1)^2) in single precision floating point notation.
Now well the obvious way to look for n would be on this way:
float i = 1.0; float n = 1/(i); float n1 = 1/(i+1.0); while ( n != n1){ i += 1.0; n = 1/i; n1 = 1/(i+1.0);}
But first of all this is obviously completely inefficient and I dont think it will yield a valid answer for any float variable, i.e. I dont think the sum until 1/n^2 and 1/(n+1)^2 will ever differ. I tried it out with the largest possible value of a variable of type float and the values were still seen as unequal in C++. How to do this? Will C++ find a value for n for which the condition holds? Is the compiler or my hardware important for this, i.e. would I get different results on a different pc?
I have a text file which consists of 907 objects and 1000 feature vector for each object. Is there any Library (Eigen/Boost) to calculate Principle Component Analysis(PCA)?
I have this code which performs the analysis part of discrete wavelet transform. It works pretty well. However, I wish to reduce the time that it consumes even further. I did use reserve() and it worked upto few msec.
int rows = signal.size(); int cols = signal[0].size(); int cols_lp1 =(int) ceil( (double) cols / 2); vector<vector<double> > lp_dn1(rows, vector<double>(cols_lp1)); vector<double> temp_row; temp_row.reserve(512);
I am new to c++. I am writing a program that reads in a text file and gives a count of how many times each letter appeared in the file. I got it to read the text file and do the letter count. B
X = 102 Y = 126 Z = 165 etc...
THAT IS WORNG
The sample output should be E = 165 T = 126 A = 102 O = 93 etc...
I got it to sort from lowest to highest for the frequency, but cant seem to get the appropriate letter assigned to it.
I'm looking to code a completely random distribution of numbers that doesn't affect performance using rand. I believe this code would be ideal but I don't understand how to use it. Where would I input the range of numbers and the quantity?
double uniform_deviate ( int seed ){ return seed * ( 1.0 / ( RAND_MAX + 1.0 ) ); } int r = M + uniform_deviate ( rand() ) * ( N - M );
I wanted to generate a standard normal poisson distribution. So I used the template poisson distribution included in the header <random> by setting the value of mean to 0 and variance to 1.
I copied the entire example code for testing it but I get an error like "This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options."
I have taken a keen interest in writing trading programs. I have some Python background, a little C# but no C++.
The example below was provided in a book on HFT and I would love to see how the results look. I was hoping that I would just compile it and away you go!
That didn't happen. To start with the author listed this as a function, so I converted it to a main program. Still having issues with my path and where to see the output. Here it is..
However, when I print out the values stored by the pointer vector, the first 2 values are not the same as what the input was. I have tried it with 4 - 10 values and always, the first 2 are not the same as the input but the rest are. I tried printing out the values as they are stored in the vector in the first for-loop and it seems to contain them all, but after that first for-loop, when I try to print *station.front(), it is now changed to something else.