Total members 11343 |It is currently Thu Jul 24, 2014 11:59 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

All times are UTC [ DST ]



  Inverse Transformation for some Statistical Distributions (C
Tue Apr 10, 2007 1:28 pm 

This a Statistical program to find the inverse transformation for some distributions depending on randomization that we are using them in most of our simulations programs. Some Distributions such that:
  • Uniform distribution.
  • Normal distribution.
  • Exponential distribution.

java code
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <unistd.h>
using namespace std;

double uniform(double randnum,double a, double b)
{
return (a+(randnum*(b-a)));
}

double exponential(double randnum,double lambda)
{
return (-lambda*(log(randnum)));
}

double normal(double mu, double sigma)
{
srand(time(NULL));
double random;
double tot=0.0;

for(int i=1;i<=12;i++)
{
random=(rand()%100)/100.0;
tot+=random;
}

return(mu+sigma*(tot-6));
}

int main()
{
double a;
double b;
double lambda;
double mu;
double sigma;
double val;
int choice;

cout << "Choose a distribution: " << endl;
cout << " - Press 1 for uniform\n"
<< " - Press 2 for exponential\n"
<< " - Press 3 for normal\n"
<< endl
<< endl
<< endl
<< endl
<< endl
<< "Choice:";
cin >> choice;

srand(time(NULL));

switch(choice)
{
case 1:
cout << "Enter lower limit for uniform distribution (a): ";
cin >> a;

cout << "Enter upper limit for uniform distribution (b): ";
cin >> b;

cout << "F(x)\t\t\t\tx" << endl;
cout << "------------------------------------" << endl;
for(int i=0;i<10;i++)
{
val=(rand()%100)/100.0;
cout << val << "\t\t\t\t" << uniform(val,a,b) << endl;
}
break;
case 2:
cout << "Enter the mean of exponential distrbution (lambda): ";
cin >> lambda;

cout << "F(x)\t\t\t\tx" << endl;
cout << "------------------------------------" << endl;
for(int i=0;i<10;i++)
{
val=(rand()%100)/100.0;
cout << val << "\t\t\t\t" << exponential(val,lambda) << endl;
}
break;
case 3:
cout << "Enter the mean of normal distribution (mu): ";
cin >> mu;

cout << "Enter the standard deviation of normal distribution (sigma): ";
cin >> sigma;
cout << "These are 10 normally distributed random variables" << endl;
for(int i=0;i<10;i++)
{
cout << normal(mu,sigma) << endl;
sleep(1);
}
break;
default:
cout << "Invalid choice" << endl;
}
return 0;
}


_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 109
Have thanks: 5 time
  Re: Inverse Transformation for some Statistical Distributions (C
Sat Jan 26, 2013 6:08 pm 
updated.

_________________
Please recommend / share my post if you found it helpful.


Author:
Mastermind
User avatar Posts: 2694
Have thanks: 73 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : Inverse Transformation for some Statistical Distributions (C
 cube 3d transformation     -  
 Generalized inverse filtering using threshold gamma     -  

All times are UTC [ DST ]









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team