Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

wrldwzrd89

macrumors G5
Jun 6, 2003
12,110
77
Solon, OH
Hi all,
I have trouble importing any .jar packages, like this one
http://www.icsa.inf.ed.ac.uk/research/groups/hase/simjava/distributions/

I've tried putting it under src and reference library, with command

import eduni.*;
or
import java.eduni.*;

What is going on? Has anyone imported successfully? How did you do it? thanks!
Remember, a star import does NOT also import subpackages of the package you're importing. It merely imports all classes in that package. Since the eduni package doesn't have any classes in it, this will fail.
 

kulimer

macrumors 6502
Original poster
Aug 30, 2011
330
2
Remember, a star import does NOT also import subpackages of the package you're importing. It merely imports all classes in that package. Since the eduni package doesn't have any classes in it, this will fail.

I could be doing something wrong there, but I've also tried, which also didn't work:
1. SSJ from University of Montreal
http://www.iro.umontreal.ca/~simardr/ssj/indexe.html

2. The JSC library
http://www.jsc.nildram.co.uk/downloads/download.html

On another onte, I was told by someone else "JRE requirements are different for [different] packages".

while someone else said, "It ought to work on any version newer than Java5", which I think the Lion has?
 
Last edited:

wrldwzrd89

macrumors G5
Jun 6, 2003
12,110
77
Solon, OH
I could be doing something wrong there, but I've also tried, which also didn't work:
1. SSJ from University of Montreal
http://www.iro.umontreal.ca/~simardr/ssj/indexe.html

2. The JSC library
http://www.jsc.nildram.co.uk/downloads/download.html

On another onte, I was told by someone else "JRE requirements are different for [different] packages".

while someone else said, "It ought to work on any version newer than Java5", which I think the Lion has?
Nope. Lion has Java 6...
 

naples98

macrumors member
Sep 9, 2008
95
3
Houston
1. Can you post some code to show how you are using the import statements and describe what errors you are getting?

2. What IDE are you using? Have you added the jars to your classpath?
 

kulimer

macrumors 6502
Original poster
Aug 30, 2011
330
2
1. Can you post some code to show how you are using the import statements and describe what errors you are getting?

2. What IDE are you using? Have you added the jars to your classpath?

Would the screenshot below help?

I am using Eclipse (Ver. Helios Service Release 2)

I right clicked GibbsSampling > Java Build Path > Add External JARs, does that sound like the normal procedure?

I've also tried, import eduni.*;
which the screenshot doesn't show.
 

Attachments

  • Screen Shot 2012-03-05 at 12.23.19 AM.png
    Screen Shot 2012-03-05 at 12.23.19 AM.png
    173.7 KB · Views: 94

kulimer

macrumors 6502
Original poster
Aug 30, 2011
330
2
I think I figured it out, the files should be located under "/SRC" NOT under "/Referenced Libraries".

And then, add External Jars. Won't work if it's "/Referenced Libraries".
 

naples98

macrumors member
Sep 9, 2008
95
3
Houston
I think I figured it out, the files should be located under "/SRC" NOT under "/Referenced Libraries".

And then, add External Jars. Won't work if it's "/Referenced Libraries".

I usually put external jars in a "lib" folder and then add them to the build path. The "/Referenced Libraries" you refer to is not the location of the jars but just that your project is using them.
 

kulimer

macrumors 6502
Original poster
Aug 30, 2011
330
2
I usually put external jars in a "lib" folder and then add them to the build path. The "/Referenced Libraries" you refer to is not the location of the jars but just that your project is using them.

Now I have them all in, still having some trouble using it.
API for the JSC package:
http://www.jsc.nildram.co.uk/api/jsc/distributions/Gamma.html

I want to generate numbers from gamma(shape=2.5, scale=0.5).
I have this:

double theta;
theta = rand.Gamma(2.5, 3);

I get "rand cannot be resolved", how should I use it? Unlike R, there are no reproducible examples.

Screenshot has the codes.
 

Attachments

  • Screen Shot 2012-03-05 at 3.24.48 PM.png
    Screen Shot 2012-03-05 at 3.24.48 PM.png
    51.4 KB · Views: 93

naples98

macrumors member
Sep 9, 2008
95
3
Houston
"rand" is a variable name that you have never declared. You need to declare it, just like "theta" before you can call methods on it.

Edit: I don't think you want to use "rand" rather "g" on line 15.

Edit #2: I keep looking at this and thinking about ways to explain it without just giving you the answer but...

"g" is of type Gamma and the class Gamma has methods. I don't know what methods Gamma has but you are probably looking for something like

Code:
theta = g.calculateTheta(2.5, 2);

which means you are calling the calculateTheta method on the instance of Gamma called "g".
 
Last edited:

kulimer

macrumors 6502
Original poster
Aug 30, 2011
330
2
"rand" is a variable name that you have never declared. You need to declare it, just like "theta" before you can call methods on it.

Edit: I don't think you want to use "rand" rather "g" on line 15.

I don't know how to use Rand along with gamma, any clues? (API link in the last post)

So, I wrote:
Gamma g = new Gamma();
Random r = new Random();
theta = r.g(2.5, 3);

error: in the last line, under g
"The method g(double, int) is undefined for the type Random"
 

Attachments

  • Screen Shot 2012-03-05 at 3.47.11 PM.png
    Screen Shot 2012-03-05 at 3.47.11 PM.png
    50.7 KB · Views: 75
Last edited:

naples98

macrumors member
Sep 9, 2008
95
3
Houston
When you have an instance of a class stored in a variable, in this case "g", and you want to use methods for that class, you use "g.methodName()" where methodName is the method you want to use.

In the case of the Gamma class, it has 1 method called "sample" which returns a random number so you would call "g.sample()" to use that method.

I don't know why you think you have to use the Random class. :confused:
 

kulimer

macrumors 6502
Original poster
Aug 30, 2011
330
2
Code:
theta = g.calculateTheta(2.5, 2);

which means you are calling the calculateTheta method on the instance of Gamma called "g".
yeah, what you are saying makes sense. But something is not right.

First, call Gamma, so, I have g. Followed by, dot r, where r means random. I have,
Code:
theta = g.r(2.5, 3.0);
Also, should I declare
Code:
Rand r = new Rand(); 
//or 
Random r = new Random();
I'm going with the first one, it's the jsc method, but I get red underline under Rand.
 

naples98

macrumors member
Sep 9, 2008
95
3
Houston
First, call Gamma, so, I have g. Followed by, dot r, where r means random. I have,
Code:
theta = g.r(2.5, 3.0);

The class Gamma does NOT have a method called "r" so
Code:
theta = g.r(2.5, 3.0);
is not going to work. Also, you don't "call Gamma", you call a "method from the class Gamma".

Also, should I declare
Code:
Rand r = new Rand(); 
//or 
Random r = new Random();
I'm going with the first one, it's the jsc method, but I get red underline under Rand.

The first one may give you an instance of Rand if it has a no-arg constructor but I don't know what the class Rand is or where you are getting it from. The second will correctly give you an instance of Random although I don't see anywhere in your code that requires it. Exactly what are you looking at that makes you think you need to use Random (or Rand).
 

kulimer

macrumors 6502
Original poster
Aug 30, 2011
330
2
The class Gamma does NOT have a method called "r" so
Code:
theta = g.r(2.5, 3.0);
is not going to work. Also, you don't "call Gamma", you call a "method from the class Gamma".

The first one may give you an instance of Rand if it has a no-arg constructor but I don't know what the class Rand is or where you are getting it from. The second will correctly give you an instance of Random although I don't see anywhere in your code that requires it. Exactly what are you looking at that makes you think you need to use Random (or Rand).


exactly, like you said! To generate random I should use
Code:
g.random()
And I don't need to declare random like how I do in import java.util.Random;

So, it should be
Code:
double alpha=2.5;
	    double beta=r.nextInt(10)*1.0; 
	    Gamma g = new Gamma(alpha,beta);
	    System.out.println("Random value is "+g.random());

Also, you have to type
import jsc.distributions.Gamma;
import jsc.*; won't call Gamma out.

I don't know why, but I worked my way through. A screenshot for anyone else ever Googles here. This should help you!
 

Attachments

  • Screen Shot 2012-03-05 at 5.57.21 PM.png
    Screen Shot 2012-03-05 at 5.57.21 PM.png
    68.2 KB · Views: 98
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.