Invoking Non-Existent Method: Matching Parameters to Method

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 986 Views - Last Post: 17 October 2014 - 03:12 PM Rate Topic: -----

#1 blodpropp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 17-October 14

Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 08:17 AM

Hi!
I need som help with my java-code, I dont really know what the problem is, and Im a rookie to java codes.
When i compile the java doc. I get output;
Perceptron.java:12: learn(Instance[],int,int) in Perceptron cannot be applied to (Instance[],int)
PerceptronModel model = learn(train_data,5);
^

1 error

And here is the code
import java.io.*;

public class Perceptron {
    public static void main(String[] args) throws IOException {

	DataReader reader = new DataReader();
	reader.init(args);

	Instance[] train_data = reader.getInstances(args[0]);
	Instance[] test_data = reader.getInstances(args[1]);

    PerceptronModel model = learn(train_data,5);

	System.out.println("\n\nRegular Perceptron======================================================");
	System.out.println("Final Training Accuracy: " + model.accuracy(train_data));
	System.out.println("Final Testing Accuracy: " + model.accuracy(test_data));
	System.out.println("======================================================");

	model.setToAvgWeights();
	System.out.println("\n\nAveraged Perceptron\n======================================================");
	System.out.println("Final Training Accuracy: " + model.accuracy(train_data));
	System.out.println("Final Testing Accuracy: " + model.accuracy(test_data));
	System.out.println("======================================================");
    }

public static PerceptronModel learn(Instance[] train_data, int num_iters, int num_labels) {
    PerceptronModel model = new PerceptronModel();

    double[] w = model.weights;
        int prime;
        double score;
        for(int i = 0; i < num_iters; i++){
            for(int j = 0; j < train_data.length; j++){
                prime = 0;
                score = 0;
                for(int k = 0; k < num_labels ; k++){
                    if(score < train_data[j].getScore(w, k)){
                        score = train_data[j].getScore(w, k);
                        prime = k;
                    }
                }
                if(prime != train_data[j].real_label){
                    w = updateWeights(w, train_data[j].getFeatures(train_data[j].real_label)
                                        , train_data[j].getFeatures(prime));
                    model.update(w);
                }
            }
        }
        return model;
    }

    
    private static double[] updateWeights(double[] weights, double[] yOne, double[] yTwo){
        for(int i = 0; i < weights.length; i++){
            weights[i] += yOne[i] - yTwo[i];
        }
        return weights;
        
    }

}


This post has been edited by macosxnerd101: 17 October 2014 - 08:19 AM
Reason for edit:: Please avoid titles like "Help" and "Error"


Is This A Good Question/Topic? 0
  • +

Replies To: Invoking Non-Existent Method: Matching Parameters to Method

#2 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12278
  • View blog
  • Posts: 45,364
  • Joined: 27-December 08

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 08:20 AM

The method here requires three parameters:
public static PerceptronModel learn(Instance[] train_data, int num_iters, int num_labels)



However, you only pass two parameters:
PerceptronModel model = learn(train_data,5);



You need to pass an extra int parameter corresponding to num_labels.
Was This Post Helpful? 1
  • +
  • -

#3 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 593
  • View blog
  • Posts: 3,823
  • Joined: 12-January 10

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 08:20 AM

it's telling you that you are not adding enough variables

Perceptron.java:12: learn(Instance[],int,int) in Perceptron cannot be applied to (Instance[],int)
PerceptronModel model = learn(train_data,5);
^

learn(x,y,z)   but you only have (x,y)

This post has been edited by DarenR: 17 October 2014 - 08:21 AM

Was This Post Helpful? 1
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13962
  • View blog
  • Posts: 55,730
  • Joined: 12-June 08

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 08:20 AM

Quote

Perceptron.java:12: learn(Instance[],int,int) in Perceptron cannot be applied to (Instance[],int)

Look at the error. On face value you can see it is showing that the function 'learn' takes three input parameters. You are using it with only two input parameters. Not having the right number of parameters (or types) means you're going to have a bad time.

Edit: Daaaaaaaaayum everyone.
Was This Post Helpful? 0
  • +
  • -

#5 blodpropp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 17-October 14

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 08:25 AM

Okay, I understood what the problem was now! But I dont know how to implement it, Its my first java coding course. Can you just show me were to add the third.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12278
  • View blog
  • Posts: 45,364
  • Joined: 27-December 08

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 08:27 AM

You would pass the third parameter like you do the first two.
PerceptronModel model = learn(train_data,5, anotherIntHere);


Was This Post Helpful? 1
  • +
  • -

#7 blodpropp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 17-October 14

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 08:31 AM

So i should add int num_labels?.
Im sorry, I know I sound very stupid, but this is very hard for me. Thank you
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13962
  • View blog
  • Posts: 55,730
  • Joined: 12-June 08

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 08:31 AM

Wait - why are you using neural networking in your java 101 class?
Was This Post Helpful? 0
  • +
  • -

#9 blodpropp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 17-October 14

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 08:38 AM

So i should add int num_labels?.
Im sorry, I know I sound very stupid, but this is very hard for me. Thank you
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13962
  • View blog
  • Posts: 55,730
  • Joined: 12-June 08

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 08:43 AM

Again look at your method.
26	public static PerceptronModel 
learn(Instance[] train_data // parameter 1
, int num_iters // parameter 2
, int num_labels) // parameter 3



Look at how you are using it.
12	    PerceptronModel model = 
learn(train_data // parameter 1
,5); // parameter 2

--> // parameter 3?  Where are you?

Was This Post Helpful? 0
  • +
  • -

#11 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3536
  • View blog
  • Posts: 16,027
  • Joined: 20-September 08

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 09:29 AM

Quote

So i should add int num_labels?.
Im sorry, I know I sound very stupid, but this is very hard for me. Thank you

Presumably the number of labels might be chosen by the user. So it might be passed into the app as a 3rd parameter. Let''s say the number of labels, you hardcode as a literal is 4. It would be

PerceptronModel model = learn(train_data,5, 4);


Of course, as modi123_1 has suggested, if you're finding it difficult to grasp this concept, then the general level of the code must be stratospherically over your head, so you need to look into that and sort the bigger problem out
Was This Post Helpful? 0
  • +
  • -

#12 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12278
  • View blog
  • Posts: 45,364
  • Joined: 27-December 08

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 09:41 AM

I would suggest reading up on methods some more:

Some excellent DIC Tutorials:
http://www.dreaminco...or-beginners-3/
http://www.dreaminco...ts-to-a-method/
http://www.dreaminco...etween-methods/

And of course, the Tutoracles
Was This Post Helpful? 0
  • +
  • -

#13 blodpropp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 17-October 14

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 11:02 AM

I want to thank you all for helping me out!
I finally understood the problem and got out an result, although the result is not right. The train-accuracy should be in the high 90s, and the test accuracy in the low 80. How do I affect that?

java -Xmx500m Perceptron restaurant_train.txt restaurant_test.txt
Number of labels: 3
Number of input features: 9492


Regular Perceptron======================================================
Final Training Accuracy: 0.332
Final Testing Accuracy: 0.338
======================================================


Averaged Perceptron
======================================================
Final Training Accuracy: 0.332
Final Testing Accuracy: 0.338
======================================================
Was This Post Helpful? 0
  • +
  • -

#14 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12278
  • View blog
  • Posts: 45,364
  • Joined: 27-December 08

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 11:07 AM

View Postmodi123_1, on 17 October 2014 - 11:31 AM, said:

Wait - why are you using neural networking in your java 101 class?

I would pose the same question as Modi did, and ask about your understanding of the training algorithm. Are you familiar with the formulas? Work things out by hand until you understand what is going on. This is first a math issue. So make sure you understand the math.

Is this code you wrote or code you found somewhere?
Was This Post Helpful? 0
  • +
  • -

#15 blodpropp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 17-October 14

Re: Invoking Non-Existent Method: Matching Parameters to Method

Posted 17 October 2014 - 11:30 AM

Its mine, or not the whole code. Our teacher gave the codes, and we filled it in.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2