Total members 11889 |It is currently Fri Mar 29, 2024 9:57 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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

updated.

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 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     -  
 Feature selection: Statistical and Recursive examples     -  



cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com