473,395 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Bivariate Gaussian Generator

Hi

Please take a look at the code below. I'm trying to generate an array of random numbers with mean(1.0,1.0) and covariance(1.0,0.0,0.0,1.0).

I'm stuck with how to make the number of samples(random numbers) up 10000.


import java.util.Random;

public class BivariateGaussianGenerator
{

static float mu1,mu2,co1,co2,co3,co4,covariance1,
covariance2,covariance3,covariance4,mean1,mean2;



public static void setMean(float mu1,float mu2 )
{
mean1=mu1;
mean2=mu2;
}

public void setCovariance(float co1,float co2,float co3,float co4)
{
covariance1=co1;
covariance2=co2;
covariance3=co3;
covariance4=co4;
}

public static float[] generateRandom()
{
int count = 100000;

Random generate = new Random();
float[] genNumbers = new float[2];


for(int i=0;i<count;i++)
{
genNumbers[i] = Math.abs((float)generate.nextGaussian());
}
return genNumbers;
}

public static void main(String[] args)

{

BivariateGaussianGenerator bgg = new BivariateGaussianGenerator();

bgg.setMean(1.0f,1.0f);
bgg.setCovariance(1.0f,0.0f,0.0f,1.0f);

float[] x = bgg.generateRandom();


System.out.println("["+x[0]+" , " +x[1]+"]");

}

}
Jul 21 '07 #1
3 1244
JosAH
11,448 Expert 8TB
You have your indexes all messed up, i.e. you define an array that can hold
two floating point numbers and you try to stick 100,000 N(0,1) numbers in it;
that will throws an ArrayIndexOutOfBoundsException.

kind regards,

Jos
Jul 21 '07 #2
You have your indexes all messed up, i.e. you define an array that can hold
two floating point numbers and you try to stick 100,000 N(0,1) numbers in it;
that will throws an ArrayIndexOutOfBoundsException.

kind regards,

Jos
Thanks

Yes I want to create array.length = 2. I also want each array to generate up 100,000 random numbers, which would be bound by a defined mean and covariance.
I want to also plot a graph. Like in Matlab, the more the random samples, the clearer the graph. What can I do?
Jul 21 '07 #3
JosAH
11,448 Expert 8TB
Thanks

Yes I want to create array.length = 2. I also want each array to generate up 100,000 random numbers, which would be bound by a defined mean and covariance.
I want to also plot a graph. Like in Matlab, the more the random samples, the clearer the graph. What can I do?
Didn't that method I copied from Abramowitz and Stegun help you? See your
other thread for that.

kind regards,

Jos
Jul 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Michael Allen | last post by:
Hi all you Java 2D gurus out there. I wonder if you might be able to help me. I've been dipping my toe into the world of Gaussian blurring and with the help of a few articles and some bashing my...
4
by: Xcal | last post by:
Anyone knows how to make a Gaussian fit to a histogram data using Python, or where I can find a library that helps me in this task? Tks everyone... Paxcal
2
by: GBartgo | last post by:
Is there someone who knows how to generate a gaussian mixture in c++?
14
by: Charles Banas | last post by:
I'm not sure if this is the right place to ask about this, but I've seen several posts in the past regarding Akima's Bivariate Interpolations routines, and i'm wondering if someone can give me some...
1
by: Ricardo | last post by:
Hello wizards, I need to get a Random number from an gaussian distribution in Visual Basic .NET , somebody knows how to make it. Thanks in advance.
1
by: j.f.c.neves | last post by:
Hello, I need some help in using the rlft3 (Numerical Recipes in c++ book, Chapter 12) to apply a Gaussian smoothing to a 2D image. How do I create a suitable filter function (page 535)? ...
3
by: bob | last post by:
I was wondering if anyone can recommend a way to generate a Gaussian random variable with standard deviation 1. Thank you.
1
by: olorunfunmi | last post by:
hello guys, i'm in dire need of algorithms and c programs for cramer's rule and gaussian elimination. the ones i've been getting seemm toooooo complex
10
by: Verbal Kint | last post by:
DEAR ALL, I just have a very short question. In the FAQ list question 13.20 the following text is mentioned: "These methods all generate numbers with mean 0 and standard deviation 1. (To adjust...
2
by: Gerdus van Zyl | last post by:
Does anyone have a relatively fast gaussian blur implemented in pure python? Below is my attempt but it takes 2.9 seconds for a 320x240 image. Image comes from byte string: self.array =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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...

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.