Difficulty with Octave's “javaMethod”

江枫思渺然 提交于 2019-12-24 11:18:05

问题


In this question, I was trying to import java classes into Octave. In my particular example, I was (and am) working with javaplex, a set of java tools with code for implementation in Matlab. The answer to the question shows that, whereas in Matlab you would do the following:

import edu.stanford.math.plex4.*;

api.Plex4.createExplicitSimplexStream();

The answer provided in the question showed that the way to do this in Octave is

javaMethod( 'createExplicitSimplexStream', 'edu.stanford.math.plex4.api.Plex4')

This was working excellently, but then I ran into a strange problem. There is another method called createVietorisRipsStream. In Matlab, I would run this with a line such as the following:

api.Plex4.createVietorisRipsStream(parameters); 

So I would think that the equivalent command in Octave would be

javaMethod( 'createVietorisRipsStream', 'edu.stanford.math.plex4.api.Plex4')

However, when I do this, I get the following error:

error: [java] java.lang.NoSuchMethodException: createVietorisRipsStream

I'm not sure why this error is coming up, and both are in the same JAVA file ('Plex4'). I did take a look at the Plex4 file, and there are two differences between createExplicitSimplexStream and createVietorisRipsStream that I noticed:

  1. There are two instances of createExplicitSimplexStream and six instances of createVietorisRipsStream

  2. There is bit that says <double[]>. I don't know if that is relevant however (I haven't read or wrote much java, up to this point, I've been able to use the tutorial they provided to only use Matlab and not have to look under the hood).

Here is one example of the code from the Plex4 file for a createExplicitSimplexStream:

public static ExplicitSimplexStream createExplicitSimplexStream(double maxFiltrationValue) {
    return new ExplicitSimplexStream(maxFiltrationValue);
}

Here is one example of the code from the Plex4 file for a createVietorisRipsStream:

public static VietorisRipsStream<double[]> createVietorisRipsStream(double[][] points, int maxDimension, double maxFiltrationValue, int numDivisions) {
    return FilteredStreamInterface.createPlex4VietorisRipsStream(points, maxDimension, maxFiltrationValue, numDivisions);
}

Any idea of why I'm getting the error I'm getting?


回答1:


Read the octave documentation for the Java section properly, it's only 4 pages, and it explains this well!

As I mentioned in the comments in the previous question, the way to call a java method with arguments is:

javamethod(
name of method as a string,
name of class fully qualified with packages as a string,
method's first argument,
method's second argument,
... etc
)

This is the only way to call 'static' methods; with normal 'instance' methods, you can either use javaMethod and replace the name of the class by the java object itself, or simply use it as you would in java, i.e. objectname.methodname(arg1, arg2, ... etc)

I have implemented here the tutorial for you to have a look at (page 14 in the pdf). (don't forget to run the modified 'load_javaplex' script first).

octave:2> max_dimension = 3;
octave:3> max_filtration_value = 4;
octave:4> num_divisions = 1000;
octave:5> point_cloud = javaMethod( 'getHouseExample', 'edu.stanford.math.plex4.examples.PointCloudExamples')
point_cloud =

<Java object: double[][]>

octave:6> stream = javaMethod( 'createVietorisRipsStream', 'edu.stanford.math.plex4.api.Plex4', point_cloud, max_dimension, max_filtration_value, num_divisions) 
stream =

<Java object: edu.stanford.math.plex4.streams.impl.VietorisRipsStream>

octave:7> persistence = javaMethod( 'getModularSimplicialAlgorithm', 'edu.stanford.math.plex4.api.Plex4', max_dimension, 2)
persistence =

<Java object: edu.stanford.math.plex4.autogen.homology.IntAbsoluteHomology>

octave:8> intervals = persistence.computeIntervals(stream)
intervals =

<Java object: edu.stanford.math.plex4.homology.barcodes.BarcodeCollection>

(I have not gone further because plot_barcodes needs to be modified a bit too; it's only a couple of lines but it would be too much to post here, the reasoning is the same though).

Also, if you're not sure what is meant by class constructors, class methods, and static vs instance-specific methods, unfortunately this is more to do with java, although it should be pretty introductory stuff. It is well worth reading up a bit about it first.

Good luck!



来源:https://stackoverflow.com/questions/51852094/difficulty-with-octaves-javamethod

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!