Dividing Variables into "bins"

Pages: 123
Aug 8, 2011 at 8:18pm
closed account (zbREy60M)
I wasn't talking about you. I was talking about real life. I'm alone with my computer and ya'll are the only people I could turn to for help. How could you think I was talking about you guys? Are you around me at all? Calm down, bro. Just needin tech advice.
Aug 9, 2011 at 12:16am
closed account (zbREy60M)
Last question! Hopefully :)

In the histogram loop i have my variable "hxrf" which is defined within a previous loop as a mathematical operation. It seems that variables within loops dont exist inside different loops? If that is right, how do I transfer that value to my other loop?
Aug 9, 2011 at 12:23am
If the two loops can't be merged, you need to keep the values in a vector or array. Generally speaking, it's best to avoid designs that lead you to this situation, if at all possible.
Aug 9, 2011 at 12:30am
closed account (zbREy60M)
So I should put the loop you gave me INSIDE of the larger loop that computes the values? And that would work? It wouldn't run the histogram loop m times everytime i ran the larger loop?
Aug 9, 2011 at 12:39am
closed account (zbREy60M)
I placed everything inside the loop but moved the line that initializes the array outside the loop. I then run the program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
double hxrf = hxr/1000000000;

	for (int R = 0; R < m; R++)
		{	
	double f = hxr;
	histogram[size_t((f<1E-6)?0:log10(f)+6)]++;
		}

	for (int a=0;a<650;a++)
		{
		std::cout << histogram[a] << std::endl;
		}
if (myfile.is_open())
{
	for (int a=0;a<650;a++)
		std::cout << histogram[a] << std::endl;
}


}

myfile.close();


On the screen I just see:

0
0
0
0
0
0

m times.

In my file, I see nothing.
Aug 9, 2011 at 2:09am
Like I said before, it makes no sense to print the histogram before it's been filled with data.
Aug 9, 2011 at 2:19am
closed account (zbREy60M)
I understand what that means. but I don't understand what that means code-wise.

I THOUGHT you meant that I should remove the print part of the histogram outside of the loop, but that didn't fix my problem.
Aug 9, 2011 at 3:30am
If you leave the code as I left it on the other post, it should work fine. What's the problem?
Aug 9, 2011 at 3:35am
closed account (zbREy60M)
On the screen I just see:

0
0
0
0
0
0

m times.

In my file, I see nothing.
Aug 9, 2011 at 7:46am
Oh, sorry. I misinterpreted the structure of the code in your last post. It helps to have a sensible indentation style, you know?

Can you post the entire code exactly as it is right now?
Aug 9, 2011 at 4:49pm
closed account (zbREy60M)
Sorry about indentation problems. I've just been learning to code on my own, so its probably convoluted and messy. I have no idea how the proper way to do it is.

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <ctime>
#include <fstream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include "boost/random.hpp"
#include "boost/generator_iterator.hpp"
#include "boost/random/normal_distribution.hpp"
#include <boost/random/uniform_int.hpp>
#include <boost/random/uniform_01.hpp>

using namespace std;
using std::vector;  

class Gravitar //creates a class called Gravitar
{
public: //public assesors
long	double GetRadius();
	void SetRadius(long double radius);
long	double GetAngle();
	void SetAngle(long double angle);
long	double GetZed();
	void SetZed(long double zed);
long	double GetAge();
	void SetAge(long double age);
long	double GetPeriod();
	void SetPeriod(long double period);

private: //private values
long	double Radius;
long	double Angle;
long	double Zed;
long	double Age;
long	double Period;
};
long double Gravitar::GetRadius() //GetRadius, public assessor function returns value of Radius
{
	return Radius; //returns the value Radius
}
long double Gravitar::GetAngle()
{
	return Angle; //returns the value of Angle
}
long double Gravitar::GetZed() 
{
	return Zed;
}
long double Gravitar::GetAge()
{
	return Age;
}
long double Gravitar::GetPeriod()
{
	return Period;
}
void Gravitar::SetRadius(long double radius)//sets radius to Radius
{
	Radius = radius;
}
void Gravitar::SetAngle(long double angle)
{
	Angle = angle;
}
void Gravitar::SetZed(long double zed)
{
	Zed = zed;
}
void Gravitar::SetAge(long double age)
{
	Age = age;
}
void Gravitar::SetPeriod(long double period)
{
	Period = period;
}
int main()
{
int m ;
cout << "How many Gravitars?\n\n";
cin >> m;
long double e ;
cout << "\n\nWhat is the ellipticity of the objects? Enter 6, 7, 8, 9, for gravitars of ellipticity of 10^-x.\n\n";
cin >> e;

long double Ellipse =  pow (10, -e); //the ellipticity should vary from 10^-6 to 10^-7 to 10^-8 to 10^-9


	boost::mt19937 rng( time(0) );
	boost::normal_distribution<> nd(5, .69);
	boost::variate_generator<boost::mt19937&,  boost::normal_distribution<> > var_nor(rng, nd);
	boost::minstd_rand intgen;
	boost::uniform_01<boost::minstd_rand> gen(intgen);
  
long double R;

ofstream myfile
//("agedata.txt"); 
//("positiondata.txt");
("postspindowndata.txt");
//("postspindowndata.dat");

unsigned histogram[650]={0};
for (int R = 0; R < m; R++)
{	

long double radius = sqrt(gen());
long double angle = gen();
long double zed = gen();
long double age = gen();
long double period = var_nor()*.001; // normal distribution of periods with a mean of 5 ms and a standard deviation of .69 mseconds 

Gravitar RadialComponents;
RadialComponents.SetRadius(radius);
Gravitar AngularComponents;
AngularComponents.SetAngle(angle);
Gravitar ZedComponents;
ZedComponents.SetZed(zed);
Gravitar AgeComponents;
AgeComponents.SetAge(age);
Gravitar PeriodComponents;
PeriodComponents.SetPeriod(period);

long double x = RadialComponents.GetRadius()*cos (AngularComponents.GetAngle()*6.283185307179586476925286766559)*15329.729; 
long double y = RadialComponents.GetRadius()*sin (AngularComponents.GetAngle()*6.283185307179586476925286766559)*15329.729;
long double z = ZedComponents.GetZed()*153.29729;
long double a = AgeComponents.GetAge() * 10000000.0 * 31556926.0; // Random number generated between 0 and 1, then multiplied by 10 millions years, multiplied by the number of seconds within a year
long double p = PeriodComponents.GetPeriod(); //p measured in seconds
long double prefrequency = 2.0 / p;
long double xde = x;
long double deltay = (y - 8500);
long double deltay2 = deltay*deltay;
long double yde = sqrt(deltay2);
long double zde = z;
long double xde2 = xde*xde;
long double yde2 = yde*yde;
long double zde2 = zde*zde;
long double dge = sqrt(xde2 + yde2 + zde2);
//WARNING:E is the  NOT mathematical constant e.
//It is the const var of ellipticity
long double Ellipse2=Ellipse*Ellipse;
const long double pi=3.1415926535897932384626433832795,
	pi4=pi*pi*pi*pi,
	pi2=pi*pi,
	G=6.673E-11;
long double beta= (32.0 * pi4 * G * 10E+44) / (2.421E+42);
int value = -4;
long double othervalue = -.25;
long double postfrequency = pow( (pow(prefrequency, value) + beta * Ellipse2 * a), othervalue);
long double h = ((4.0 * pi2 * G * 10E+44) / (8.077E+33)) * ((Ellipse * pow( postfrequency, 2)) / dge);
long double hx = h*1000000000;
long double hxr = floor (hx);
double hxrf = hxr/1000000000;

	for (int R = 0; R < m; R++)
		{	
	double f = hxrf;
	histogram[size_t((f<1E-6)?0:log10(f)+6)]++;
		}

	for (int a=0;a<650;a++)
		{
		std::cout << histogram[a] << std::endl;
		}


//printf("Gravitar # %4f %16f %16f %16f %16f %16f %32f %16f %16f %16f %16f \n" , R+1 ,  x , y , z , a , p , Ellipse , prefrequency , postfrequency, dge, h, hxrf );
}

if (myfile.is_open())
{
	for (int a=0;a<650;a++)
		std::cout << histogram[a] << std::endl;
}

myfile.close();

system("PAUSE");
return 0;
}
Aug 9, 2011 at 6:02pm
Here's the same code beautified. Try to follow a similar style in the future.
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <ctime>
#include <fstream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include "boost/random.hpp"
#include "boost/generator_iterator.hpp"
#include "boost/random/normal_distribution.hpp"
#include <boost/random/uniform_int.hpp>
#include <boost/random/uniform_01.hpp>

using namespace std;
using std::vector;

class Gravitar //creates a class called Gravitar
{
public: //public assesors
    long	double GetRadius();
    void SetRadius(long double radius);
    long	double GetAngle();
    void SetAngle(long double angle);
    long	double GetZed();
    void SetZed(long double zed);
    long	double GetAge();
    void SetAge(long double age);
    long	double GetPeriod();
    void SetPeriod(long double period);

private: //private values
    long	double Radius;
    long	double Angle;
    long	double Zed;
    long	double Age;
    long	double Period;
};

long double Gravitar::GetRadius() //GetRadius, public assessor function returns value of Radius
{
    return Radius; //returns the value Radius
}

long double Gravitar::GetAngle()
{
    return Angle; //returns the value of Angle
}

long double Gravitar::GetZed()
{
    return Zed;
}

long double Gravitar::GetAge()
{
    return Age;
}

long double Gravitar::GetPeriod()
{
    return Period;
}

void Gravitar::SetRadius(long double radius)//sets radius to Radius
{
    Radius = radius;
}

void Gravitar::SetAngle(long double angle)
{
    Angle = angle;
}

void Gravitar::SetZed(long double zed)
{
    Zed = zed;
}

void Gravitar::SetAge(long double age)
{
    Age = age;
}

void Gravitar::SetPeriod(long double period)
{
    Period = period;
}

int main()
{
    int m ;
    cout << "How many Gravitars?\n\n";
    cin >> m;
    long double e ;
    cout << "\n\nWhat is the ellipticity of the objects? Enter 6, 7, 8, 9, for gravitars of ellipticity of 10^-x.\n\n";
    cin >> e;

    long double Ellipse =  pow (10, -e); //the ellipticity should vary from 10^-6 to 10^-7 to 10^-8 to 10^-9


    boost::mt19937 rng( time(0) );
    boost::normal_distribution<> nd(5, .69);
    boost::variate_generator<boost::mt19937&,  boost::normal_distribution<> > var_nor(rng, nd);
    boost::minstd_rand intgen;
    boost::uniform_01<boost::minstd_rand> gen(intgen);

    long double R;

    ofstream myfile
//("agedata.txt");
//("positiondata.txt");
    ("postspindowndata.txt");
//("postspindowndata.dat");

    unsigned histogram[650]= {0};
    for (int R = 0; R < m; R++) {

        long double radius = sqrt(gen());
        long double angle = gen();
        long double zed = gen();
        long double age = gen();
        long double period = var_nor()*.001; // normal distribution of periods with a mean of 5 ms and a standard deviation of .69 mseconds

        Gravitar RadialComponents;
        RadialComponents.SetRadius(radius);
        Gravitar AngularComponents;
        AngularComponents.SetAngle(angle);
        Gravitar ZedComponents;
        ZedComponents.SetZed(zed);
        Gravitar AgeComponents;
        AgeComponents.SetAge(age);
        Gravitar PeriodComponents;
        PeriodComponents.SetPeriod(period);

        long double x = RadialComponents.GetRadius()*cos (AngularComponents.GetAngle()*6.283185307179586476925286766559)*15329.729;
        long double y = RadialComponents.GetRadius()*sin (AngularComponents.GetAngle()*6.283185307179586476925286766559)*15329.729;
        long double z = ZedComponents.GetZed()*153.29729;
        long double a = AgeComponents.GetAge() * 10000000.0 * 31556926.0; // Random number generated between 0 and 1, then multiplied by 10 millions years, multiplied by the number of seconds within a year
        long double p = PeriodComponents.GetPeriod(); //p measured in seconds
        long double prefrequency = 2.0 / p;
        long double xde = x;
        long double deltay = (y - 8500);
        long double deltay2 = deltay*deltay;
        long double yde = sqrt(deltay2);
        long double zde = z;
        long double xde2 = xde*xde;
        long double yde2 = yde*yde;
        long double zde2 = zde*zde;
        long double dge = sqrt(xde2 + yde2 + zde2);
//WARNING:E is the  NOT mathematical constant e.
//It is the const var of ellipticity
        long double Ellipse2=Ellipse*Ellipse;
        const long double pi=3.1415926535897932384626433832795,
                          pi4=pi*pi*pi*pi,
                          pi2=pi*pi,
                          G=6.673E-11;
        long double beta= (32.0 * pi4 * G * 10E+44) / (2.421E+42);
        int value = -4;
        long double othervalue = -.25;
        long double postfrequency = pow( (pow(prefrequency, value) + beta * Ellipse2 * a), othervalue);
        long double h = ((4.0 * pi2 * G * 10E+44) / (8.077E+33)) * ((Ellipse * pow( postfrequency, 2)) / dge);
        long double hx = h*1000000000;
        long double hxr = floor (hx);
        double hxrf = hxr/1000000000;

        for (int R = 0; R < m; R++) {
            double f = hxrf;
            histogram[size_t((f<1E-6)?0:log10(f)+6)]++;
        }

        for (int a=0; a<650; a++) {
            std::cout << histogram[a] << std::endl;
        }


//printf("Gravitar # %4f %16f %16f %16f %16f %16f %32f %16f %16f %16f %16f \n" , R+1 ,  x , y , z , a , p , Ellipse , prefrequency , postfrequency, dge, h, hxrf );
    }

    if (myfile.is_open()) {
        for (int a=0; a<650; a++)
            std::cout << histogram[a] << std::endl;
    }

    myfile.close();

    system("PAUSE");
    return 0;
}

Lines 169-172 don't make sense. You're incrementing the same histogram range m times for each data point. This should look more like
1
2
3
4
//for (int R = 0; R < m; R++) {
    double f = hxrf;
    histogram[size_t((f<1E-6)?0:log10(f)+6)]++;
//} 

No loop. Then lines 174-176 would go outside the loop that ends on 180.
Last edited on Aug 9, 2011 at 6:03pm
Aug 9, 2011 at 6:34pm
closed account (zbREy60M)
I did that! I'm still getting the same values.
Aug 9, 2011 at 6:38pm
I see no reason why that should be happening. Try changing the last snippet to:
1
2
3
size_t index=size_t((f<1E-6)?0:log10(f)+6);
histogram[index]++;
std::cout <<"histogram["<<index<<"]="<<histogram[index]<<std::endl;
Aug 9, 2011 at 7:03pm
Btw, for a beginner the ? syntax is very confusing.

 
 histogram[size_t((f<1E-6)?0:log10(f)+6)]++;

does in practice the same as
1
2
3
4
5
6
int indexInHistogram;
if (f<1E-6)
  indexInHistogram=size_t(0);
else
  indexInHistogram=size_t(log10(f)+6);
histogram[indexInHistogram]++;


Which way you chose to implement this snippet (there are many others) is largely a matter of taste. The distinct advantage of helios' code is that it's damn short. The distinct disadvantage (which helios might not be aware of) is that it will confuse most of the students/scientists who have no prior C++ experience. I am speaking here from personal experience.
Aug 9, 2011 at 10:33pm
closed account (zbREy60M)
I'm still getting the same thing.

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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <ctime>
#include <fstream>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include "boost/random.hpp"
#include "boost/generator_iterator.hpp"
#include "boost/random/normal_distribution.hpp"
#include <boost/random/uniform_int.hpp>
#include <boost/random/uniform_01.hpp>

using namespace std;
using std::vector;  

class Gravitar //creates a class called Gravitar
{
public: //public assesors
long	double GetRadius();
	void SetRadius(long double radius);
long	double GetAngle();
	void SetAngle(long double angle);
long	double GetZed();
	void SetZed(long double zed);
long	double GetAge();
	void SetAge(long double age);
long	double GetPeriod();
	void SetPeriod(long double period);

private: //private values
long	double Radius;
long	double Angle;
long	double Zed;
long	double Age;
long	double Period;
};
long double Gravitar::GetRadius() //GetRadius, public assessor function returns value of Radius
{
	return Radius; //returns the value Radius
}
long double Gravitar::GetAngle()
{
	return Angle; //returns the value of Angle
}
long double Gravitar::GetZed() 
{
	return Zed;
}
long double Gravitar::GetAge()
{
	return Age;
}
long double Gravitar::GetPeriod()
{
	return Period;
}
void Gravitar::SetRadius(long double radius)//sets radius to Radius
{
	Radius = radius;
}
void Gravitar::SetAngle(long double angle)
{
	Angle = angle;
}
void Gravitar::SetZed(long double zed)
{
	Zed = zed;
}
void Gravitar::SetAge(long double age)
{
	Age = age;
}
void Gravitar::SetPeriod(long double period)
{
	Period = period;
}
int main()
{
int m ;
cout << "How many Gravitars?\n\n";
cin >> m;
long double e ;
cout << "\n\nWhat is the ellipticity of the objects? Enter 6, 7, 8, 9, for gravitars of ellipticity of 10^-x.\n\n";
cin >> e;

long double Ellipse =  pow (10, -e); //the ellipticity should vary from 10^-6 to 10^-7 to 10^-8 to 10^-9


	boost::mt19937 rng( time(0) );
	boost::normal_distribution<> nd(5, .69);
	boost::variate_generator<boost::mt19937&,  boost::normal_distribution<> > var_nor(rng, nd);
	boost::minstd_rand intgen;
	boost::uniform_01<boost::minstd_rand> gen(intgen);
  
long double R;

ofstream myfile
//("agedata.txt"); 
//("positiondata.txt");
("postspindowndata.txt");
//("postspindowndata.dat");

unsigned histogram[650]={0};
for (int R = 0; R < m; R++)
{	

long double radius = sqrt(gen());
long double angle = gen();
long double zed = gen();
long double age = gen();
long double period = var_nor()*.001; // normal distribution of periods with a mean of 5 ms and a standard deviation of .69 mseconds 

Gravitar RadialComponents;
RadialComponents.SetRadius(radius);
Gravitar AngularComponents;
AngularComponents.SetAngle(angle);
Gravitar ZedComponents;
ZedComponents.SetZed(zed);
Gravitar AgeComponents;
AgeComponents.SetAge(age);
Gravitar PeriodComponents;
PeriodComponents.SetPeriod(period);

long double x = RadialComponents.GetRadius()*cos (AngularComponents.GetAngle()*6.283185307179586476925286766559)*15329.729; 
long double y = RadialComponents.GetRadius()*sin (AngularComponents.GetAngle()*6.283185307179586476925286766559)*15329.729;
long double z = ZedComponents.GetZed()*153.29729;
long double a = AgeComponents.GetAge() * 10000000.0 * 31556926.0; // Random number generated between 0 and 1, then multiplied by 10 millions years, multiplied by the number of seconds within a year
long double p = PeriodComponents.GetPeriod(); //p measured in seconds
long double prefrequency = 2.0 / p;
long double xde = x;
long double deltay = (y - 8500);
long double deltay2 = deltay*deltay;
long double yde = sqrt(deltay2);
long double zde = z;
long double xde2 = xde*xde;
long double yde2 = yde*yde;
long double zde2 = zde*zde;
long double dge = sqrt(xde2 + yde2 + zde2);
//WARNING:E is the  NOT mathematical constant e.
//It is the const var of ellipticity
long double Ellipse2=Ellipse*Ellipse;50

const long double pi=3.1415926535897932384626433832795,
	pi4=pi*pi*pi*pi,
	pi2=pi*pi,
	G=6.673E-11;
long double beta= (32.0 * pi4 * G * 10E+44) / (2.421E+42);
int value = -4;
long double othervalue = -.25;
long double postfrequency = pow( (pow(prefrequency, value) + beta * Ellipse2 * a), othervalue);
long double h = ((4.0 * pi2 * G * 10E+44) / (8.077E+33)) * ((Ellipse * pow( postfrequency, 2)) / dge);
long double hx = h*1000000000;
long double hxr = floor (hx);
double hxrf = hxr/1000000000;
		
	double f = hxrf;
	size_t index=size_t((f<1E-6)?0:log10(f)+6);
histogram[index]++;
std::cout <<"histogram["<<index<<"]="<<histogram[index]<<std::endl;


//printf("Gravitar # %4f %16f %16f %16f %16f %16f %32f %16f %16f %16f %16f \n" , R+1 ,  x , y , z , a , p , Ellipse , prefrequency , postfrequency, dge, h, hxrf );

}

if (myfile.is_open())
{
	for (int a=0;a<650;a++)
		std::cout << histogram[a] << std::endl;
}

myfile.close();

system("PAUSE");
return 0;
}


Here, maybe you should try to run it and see what you get. I can only explain it so well.
Aug 9, 2011 at 10:57pm
I don't know what to tell you. It's working for me. Look:

8
0
0
206
9205
804
25
0
0
0
0
0
0
0
0
0

I did have to move the histogram even closer to zero to get that resolution (size_t((f<1E-10)?0:log10(f)+10)), plus I noticed that inside the if (myfile.is_open()) I accidentally sent the output to std::cout insteadof myfile. But other than that, it works fine.
Aug 9, 2011 at 11:00pm
closed account (zbREy60M)
What exactly are those numbers referring to? Its confusing me.
Aug 9, 2011 at 11:45pm
Ah... Wait. Did I completely misunderstand what it is you wanted to do?
I need to divide the frequencies into equally spaced bins into logarithm (base 10). Then, for each of my fake gravitars, work out which bin it lands in and add to that bin the value of h. At the end of this process, I will have a list of frequency values for each bin, and the sum of all the "h" values for that bin.

Where 'h' is a variable dependent on the frequency.
Reading it more closely, you want something that's a bit like a histogram, only instead of adding 1 each bucket, you add h(hxrf). Also you want to store the values of hxrf.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//unsigned histogram[650]={0};
double sums[650]={0};
std::vector<double> frequency_bins[650];

//...

size_t index=size_t((f<1E-10)?0:log10(f)+10);
sums[index]+=compute_h_value(f);
frequency_bins[index].push_back(f);

//...
//At the end of the program:
for (int a=0;a<650;a++){
    std::cout <<"Bucket "<<a<<":\n"
        "Sum of h values for bucket: "<<sums[a]<<"\n"
        "Frequencies in bucket:\n";
    for (size_t b=0;b<frequency_bins[a].size();b++)
        std::cout <<frequency_bins[a][b]<<" ";
    std::cout <<std::endl;
}
Last edited on Aug 9, 2011 at 11:49pm
Aug 10, 2011 at 12:16am
closed account (zbREy60M)
haha! Yes. I was wondering whats been going on here.

The idea is that we are needing to see how "intense" each bin is. so its a bit like a histogram.
Last edited on Aug 10, 2011 at 12:17am
Pages: 123