• Post Reply Bookmark Topic Watch Topic
  • New Topic

debugging code help required  RSS feed

 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I have a java program utilizing a data mining program called weka

http://www.cs.waikato.ac.nz/ml/weka/

My program loops through seven weka classifiers and I wish to printout the options for the current classifier


part of the code is as follows......................



etc..etc......

Many thanks

Natasha
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Natasha,

Welcome to CodeRanch!

Please, UseCodeTags(<-click) and TellTheDetails(<-click).

To be frank, I didn't understand your question. Is it related to debugging in general (i.e. debugging techniques etc.) or related to debugging specific methods (setFilter and buildClassifier)?

There are various debugging techniques. Typically, I use a combination of extra print statements, and taking assistance of an IDE like eclipse.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, tell us what the code should be doing, and what it is doing instead. Since it's part of something larger, we can't run it ourselves even if we wanted. And Weka is not all that widely used AFAIK, so you may have to explain to us how it works.
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anayonkar Shivalkar wrote:Hi Natasha,

Welcome to CodeRanch!

Please, UseCodeTags(<-click) and TellTheDetails(<-click).

To be frank, I didn't understand your question. Is it related to debugging in general (i.e. debugging techniques etc.) or related to debugging specific methods (setFilter and buildClassifier)?

There are various debugging techniques. Typically, I use a combination of extra print statements, and taking assistance of an IDE like eclipse.


Hi again

I am wanting to check that the program has picked up the correct set of options for each classifier

I am thinking something like ................

myConsole.getOut().println ("current set of options: " + ???);

Natasha
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean to print the contents of the array? Look in the Arrays class; it has a few methods for displaying arrays.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than having the data (eg class, options & attributes) spread across numerous arrays and code to patch it all together you would be better off having a class that encapsulates the details required to make a given Classifier. You can then create objects for each of the Classifiers and use their methods to build each Classifier.
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You mean to print the contents of the array? Look in the Arrays class; it has a few methods for displaying arrays.


Yes - that is exactly what I wish to do.................

 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:Rather than having the data (eg class, options & attributes) spread across numerous arrays and code to patch it all together you would be better off having a class that encapsulates the details required to make a given Classifier. You can then create objects for each of the Classifiers and use their methods to build each Classifier.


I agree with the concept completely but I am so new to Java and do not have the capability to do this at the moment
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You mean to print the contents of the array? Look in the Arrays class; it has a few methods for displaying arrays.


Hi Campbell

OK....so I tried the following

myConsole.getOut().println("Options: "+ Arrays.toString(optionsArray[j]));

and the result was

Options: [, , , ] for example

What am I doing wrong ?

Natasha
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wrong toString method. There are at least three of them. Try deepToString.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And you print out the whole array, not one of its elements.
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Wrong toString method. There are at least three of them. Try deepToString.


Hi

I tried myConsole.getOut().println("Options: "+ Arrays.deepToString(optionsArray[j]));

The result is still

Options: [,,,,]


Natasha
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
More discussion on this thread, which I closed so as to have a single thread.
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:More discussion on this thread, which I closed so as to have a single thread.


The loop was because I have 7 classifiers and I am trying to printout the set of options for each

At the moment I am getting [,,,]

How do I printout the actual option values inside the [,,,] ?

Natasha
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should not need to print the individual arrays; deepToString shows the entire array and recursively represents included arrays.
You did not say how what you received differs from what you wanted.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like your arrays are full of empty strings. Try setting the value of one or more elements to a known value eg optionsArray[0][0] = "TEST" before printing the array and see what you get then.
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code



prints OK for me:

Options:[[-B, 35, -M, a], [-C, 0.25, _M, 2]]

 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:It looks like your arrays are full of empty strings. . . .
D'oh!

I shall have to put my reading glasses on; I was mistaking the multiple commas for ellipses.
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Red Smith wrote:This code



prints OK for me:

Options:[[-B, 35, -M, a], [-C, 0.25, _M, 2]]



Hi Campbell

Thank you so much for this piece of code

My code is now as follows:-
******************************************
// Run for each classifier model
for(int j = 0; j < models.length; j++) {

data.setClassIndex(attributesArray[j] - 1); // I have setup this array which is an array of the number of attributes for each of the seven classifiers

Remove filter = new Remove(); // First, we create the base object.
filter.setAttributeIndicesArray(filtersArray[j]); // Finally, we provide an array of integer indexes.

//build classifier
FilteredClassifier fc = new FilteredClassifier(); // Create a FilteredClassifier object
((OptionHandler)models[j]).setOptions(optionsArray[j]);
fc.setClassifier(models[j]);

try {
myConsole.getOut().println(Options: + Arrays.deepToString(optionsArray));
}
catch (Exception e)
{
myConsole.getOut().println(e);
}

fc.setFilter(filter);

fc.buildClassifier(training);
************************************************
As this is in a loop for the seven classifiers I would ideally wish to print out just the set of options for classifier[j]
However - as it stands we attempt to printout all seven sets of options each time - no big deal

The results are quite puzzling..............................

On the first iteration (i.e. j=0) we get

Options: [ [,,,], [-C 0.25, -M 2], etc for the remaining options i.e. option set one is blank but the remaining six are all OK

On the next iteration (j=1) we get

Options: [ [,,,], [,,,], [-F, 3, -N, 2.0, -O, 2, -S, 1, -E] etc for the remaining options i.e. option sets one and two are blank but the remaining five are all OK

On the last iteration (j=6) we get

Options: [ [,,,], [,,,], [ etc i.e. all option sets are blank !!!

Natasha
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Natasha Teokotai wrote:

The results are quite puzzling..............................

On the first iteration (i.e. j=0) we get

Options: [ [,,,], [-C 0.25, -M 2], etc for the remaining options i.e. option set one is blank but the remaining six are all OK

On the next iteration (j=1) we get

Options: [ [,,,], [,,,], [-F, 3, -N, 2.0, -O, 2, -S, 1, -E] etc for the remaining options i.e. option sets one and two are blank but the remaining five are all OK

On the last iteration (j=6) we get

Options: [ [,,,], [,,,], [ etc i.e. all option sets are blank !!!



The weka code could be setting the strings to "" after they use the option.

It looks like any weka class that has setOptions() also has a getOptions() .

You could try

myConsole.getOut().println( Arrays.toString( ((OptionHandler)models[j]).getOptions() ) ) ;

If that doesn't work you could print it out before you call setOptions() or create a separate copy of the optionsArray before using it, one that won't get nulled out by weka.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Natasha Teokotai wrote: . . .

Hi Campbell

Thank you so much for this piece of code

. . .
You're welcome but I think Red Smith gave you the code.
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Red Smith wrote:
Natasha Teokotai wrote:

The results are quite puzzling..............................

On the first iteration (i.e. j=0) we get

Options: [ [,,,], [-C 0.25, -M 2], etc for the remaining options i.e. option set one is blank but the remaining six are all OK

On the next iteration (j=1) we get

Options: [ [,,,], [,,,], [-F, 3, -N, 2.0, -O, 2, -S, 1, -E] etc for the remaining options i.e. option sets one and two are blank but the remaining five are all OK

On the last iteration (j=6) we get

Options: [ [,,,], [,,,], [ etc i.e. all option sets are blank !!!



The weka code could be setting the strings to "" after they use the option.

It looks like any weka class that has setOptions() also has a getOptions() .

You could try

myConsole.getOut().println( Arrays.toString( ((OptionHandler)models[j]).getOptions() ) ) ;

If that doesn't work you could print it out before you call setOptions() or create a separate copy of the optionsArray before using it, one that won't get nulled out by weka.


Hi Red Smith

Apologies for not realizing that the code came from you

I have tried the line of code above and it was perfect - it prints out just the current set of options for the current classifier................

It has shown that something really strange is going on with the options for classifier number seven

To recap:-

My program loops thru seven weka classifiers at each time interval
At the first time interval all seven are OK but from then on the seventh classifier spits out an error message

Now with your line of code I got the following results for classifier number seven..............

First loop

Options: [-S, 3, -K, 2 etc etc ] perfect!!!

Every other loop

Options: [-S, 0, -K, 2, etc etc ] the S option has reverted to zero from 3 - thus the error message

i.e. the option setting for S is being changed somehow----although I naively thought that the program goes back to my array of options and reads in the same old, same old each time

This I don't understand at all (and maybe I need to talk to the weka architects to find out what is going on?)

That is, unless you have any further suggestions ?

Natasha
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Natasha Teokotai wrote:

This I don't understand at all (and maybe I need to talk to the weka architects to find out what is going on?)

That is, unless you have any further suggestions ?

Natasha


It probably is a question for the Weka Mailing List and Forum but before you do that you might want to put

myConsole.getOut().println( Arrays.toString( ((OptionHandler)models[j]).getOptions() ) ) ;

after every line so you can say exactly what method-call/line is causing the change.
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Red

I shall do exactly as you suggest

While I wait for an answer on the weka forum I put the above line of code after each line of my program

The result shows that after the program line

((OptionHandler)models[j]).setOptions(optionsArray[j]));

the S option for LibSVM is set to 3 correctly on the first time interval but set to 0 incorrectly thereafter even though it is set to 3 in my optionsArray

Natasha
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tony Docherty wrote:Rather than having the data (eg class, options & attributes) spread across numerous arrays and code to patch it all together you would be better off having a class that encapsulates the details required to make a given Classifier. You can then create objects for each of the Classifiers and use their methods to build each Classifier.


Hi Tony

Your suggestion is really hitting home now..............
What I am doing which is terribly wasteful is building up each of my seven classifiers over and over at each new time interval with the same details (filter, attribute, options)

Can you show me the sort of code which will allow me to do this ONLY ONCE in my program ?

Natasha
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody

I have the following code which is very wasteful

At each new time interval, I rebuild the same seven classifiers with the same options, filter, class attribute etc.

What do I need to change so that I only build each of the seven classifiers just the ONCE!

*****************************************
// Choose a set of classifiers
Classifier[] models = new Classifier[] {
new KStar(),
new J48(),
new JRip(),
new NaiveBayes(),
new LMT(),
new KStar(),
new LibSVM() };


// Run for each classifier model
for(int j = 0; j < models.length; j++) {

data.setClassIndex(attributesArray[j] - 1); // I have setup this array which is an array of the number of attributes for each of the seven classifiers

Remove filter = new Remove(); // First, we create the base object.
filter.setAttributeIndicesArray(filtersArray[j]); // Finally, we provide an array of integer indexes.

//build classifier
FilteredClassifier fc = new FilteredClassifier(); // Create a FilteredClassifier object
((OptionHandler)models[j]).setOptions(optionsArray[j]);
fc.setClassifier(models[j]);

fc.setFilter(filter);

fc.buildClassifier(training);
******************************************

Natasha
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is unique between each run inside the for loop? Is the data object where changes between loop iterations take place? You can move things that only need to happen once to separate methods and just have what needs to occur each time interval in the method that does the processing for loop.

I think
((OptionHandler)models[j]).setOptions(optionsArray[j]);

can definitely be moved outside the processing loop as I am assuming that the options remain the same from one performance of the loop to another.

The call to setOptions should be in a separate initialization for loop right after the models() array is created. The models array should be created outside of the method that contains the processing for loop so the models aren't created over and over, assuming that they only need be created once.



Anything that can be created just once, can be added to the process() parameter list.

process(models, filtersArray, .... );
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Red
Thank you so much for answering my query.........................

I have tried to separate out all code which should only be run once !
********************************************
// called once
Classifier[] models = createModels(optionsArray);

// called repeatedly and contains the part of your current logic that must be done each processing cycle, versus being created once and forgotten about

for (int j = 0; j < models.length; j ++) {

training.setClassIndex(classAttributeArray[j]);
testing.setClassIndex(classAttributeArray[j]);

fc.buildClassifier(training);

// test the model
Evaluation eval = new Evaluation(training);
eval.evaluateModel(fc, testing);

// print out results, etc.

}

process(models);

Classifier [] createModels(Options[] optionsArray)
{

// Choose a set of classifiers
Classifier[] models = new Classifier[]
{
new KStar(),
new J48(),
new JRip(),
new NaiveBayes(),
new LMT(),
new KStar(),
new LibSVM()
};

for(int j = 0; j < models.length; j++)
{
Remove filter new Remove();
filter.setAttributeIndicesArray(filtersArray[j]);
FilteredClassifier fc = new FilteredClassifier();
((OptionHandler)models[j]).setOptions(optionsArray[j]);
fc.setClassifier(models[j]);
fc.setFilter(filter);
}

return models;
}
*********************************************

Question: In the repeated over and over section there are two references to 'fc' (filtered classifier) which originates in the once-only section

How do I refer to the current 'filtered classifier' in the repeated over and over section ?
'fc' will not cut it !

Natasha

p.s. The data is the only thing that changes at each new time interval
As you suspect - the seven classifiers with their options, filters, etc. is static
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Red

I am still puzzled over your response.............

Once-only jobs
1) create seven classifiers, each with static values of filter, options

Repeated job (looping every six hours)
1) build classifier with training data which changes every six hours
2) evaluate training data
3) print out results

I am unclear why you say "Anything that can be created just once, can be added to the process() parameter list." when it seems that process(models) is under the 'repeat over and over' section

Natasha
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way to do it is to pass the data that was created once per session in initialization (or setup) routines as parameters to the process method

process(filters, something_else, and_another_arg, ...). But since you process multiple times (6 hour intervals), maybe there should be process() and processData() routines.

But if everything is in one class, instead of passing the initialization data in for processing, you can also share any data between methods by having them as class member variables. Like this:

 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Natasha Teokotai wrote:

Hi Red
Thank you so much for answering my query.........................

I have tried to separate out all code which should only be run once !
********************************************
// called once
Classifier[] models = createModels(optionsArray);

// called repeatedly and contains the part of your current logic that must be done each processing cycle, versus being created once and forgotten about

for (int j = 0; j < models.length; j ++) {

training.setClassIndex(classAttributeArray[j]);
testing.setClassIndex(classAttributeArray[j]);

fc.buildClassifier(training);

// test the model
Evaluation eval = new Evaluation(training);
eval.evaluateModel(fc, testing);

// print out results, etc.

}

process(models);

Classifier [] createModels(Options[] optionsArray)
{

// Choose a set of classifiers
Classifier[] models = new Classifier[]
{
new KStar(),
new J48(),
new JRip(),
new NaiveBayes(),
new LMT(),
new KStar(),
new LibSVM()
};

for(int j = 0; j < models.length; j++)
{
Remove filter new Remove();
filter.setAttributeIndicesArray(filtersArray[j]);
FilteredClassifier fc = new FilteredClassifier();
((OptionHandler)models[j]).setOptions(optionsArray[j]);
fc.setClassifier(models[j]);
fc.setFilter(filter);
}

return models;
}
*********************************************

Question: In the repeated over and over section there are two references to 'fc' (filtered classifier) which originates in the once-only section

How do I refer to the current 'filtered classifier' in the repeated over and over section ?
'fc' will not cut it !

Natasha

p.s. The data is the only thing that changes at each new time interval
As you suspect - the seven classifiers with their options, filters, etc. is static


You can make fc member data, like the models data in my other answer today. But are you using fc correctly? You are looping and continually creating a new FilteredClassifier and assigning each object created to the same fc variable. Which means 6 of those you created will not be accessible, only the seventh one created. If you do it in a loop of seven in initialization, then there should be an array of FilteredClassifiers to store all seven creations of a FilteredClassifier.
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Absolutely correct
I wish to retain seven filtered classifiers

We start with a base classifier such as KStar
We then apply filters, options etc.
And end up with a filtered classifier e.g. KStar_filtered

However, whilst I have the base classifier array initialized near the beginning of my overall program I do not have the same initialization array for the filtered classifier
And this is where I am stuck

I need something along the lines of

// create an array of Filtered Classifiers
FilteredClassifier [] fcs = new FilteredClassifier[] {
???
???
}

but what exactly do I put in between the {} ??

Natasha
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Natasha Teokotai wrote:I need something along the lines of

// create an array of Filtered Classifiers
FilteredClassifier [] fcs = new FilteredClassifier[] {
???
???
}

but what exactly do I put in between the {} ??

Natasha

So there is a lot of stuff in this thread i'm not going to take the time to read.

based on looking at the what I quoted here, it looks like you are trying to build an array on the fly. that may not be the best options. Perhaps you should instead create an arrayList, Then you can add objects to it as needed.

 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Natasha Teokotai wrote:
Absolutely correct
I wish to retain seven filtered classifiers

We start with a base classifier such as KStar
We then apply filters, options etc.
And end up with a filtered classifier e.g. KStar_filtered

However, whilst I have the base classifier array initialized near the beginning of my overall program I do not have the same initialization array for the filtered classifier
And this is where I am stuck

I need something along the lines of

// create an array of Filtered Classifiers
FilteredClassifier [] fcs = new FilteredClassifier[] {
???
???
}

but what exactly do I put in between the {} ??

Natasha


Since you are going to do seven, you can either create seven different named variables KStar_filtered, etc., or put them in an array (or ArrayList as Fred suggested).

Assuming an array, since everything else is in an array, then you should have your same 7-times loop and inside is the statements you are currently using to do one fc:

 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Red and Fred - both helpful comments.................

I now have the following code..................



And the accompanying log..................

2013-12-27 04:56:17 Weka finished
2013-12-27 04:56:17 Weka exception occurred: java.lang.NullPointerException
2013-12-27 04:56:17 Options4: [-S, 3, -K, 2, -D, 3, -G, 0.0, -R, 0.0, -N, 0.5, -M, 40.0, -C, 1.0, -E, 0.001, -P, 0.1, -model, C:\Users\Stan\Downloads, -seed, 1]
2013-12-27 04:56:17 ClassIndex: RETURN_PREDICTED
2013-12-27 04:56:17 Options4: [-B, 35, -M, a, ]
2013-12-27 04:56:17 ClassIndex: RETURN_PREDICTED
2013-12-27 04:56:17 Options4: [-I, -1, -M, 15, -W, 0.0, -A, , , , ]
2013-12-27 04:56:17 ClassIndex: CLASS_PREDICTED
2013-12-27 04:56:17 Options4: [, , ]
2013-12-27 04:56:17 ClassIndex: CLASS_PREDICTED
2013-12-27 04:56:17 Options4: [-F, 3, -N, 2.0, -O, 2, -S, 1, -E, , ]
2013-12-27 04:56:17 ClassIndex: CLASS_PREDICTED
2013-12-27 04:56:17 Options4: [-C, 0.25, -M, 2, , , , , , , , , , , , ]
2013-12-27 04:56:17 ClassIndex: CLASS_PREDICTED
2013-12-27 04:56:17 Options4: [-B, 35, -M, a, ]
2013-12-27 04:56:17 ClassIndex: CLASS_PREDICTED
2013-12-27 04:56:15 No order to close
2013-12-27 04:56:15 DOW: 2, Hour: 0
*******************************************

I am quite pleased with this so far.................
I am only creating the filtered classifiers once and the options for each are correct!

I am unsure of the error explanation - Line 61 seems to be the problem line ?

Natasha
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Natasha Teokotai wrote:

// build classifier - do this once only for each classifier
fcs = new FilteredClassifier[models.length]; // Create a FilteredClassifier object



That line will not create a FilteredClassifier object. It will create an array of size 7 which can hold FilteredClassifier objects. Since you are doing it inside of a loop, you will end up creating 7 arrays to hold FilteredClassifiers, only the last of which will be accessible via the fcs variable. That line needs to be moved above the for loop and that should get rid of the Null Pointer Exception.


((OptionHandler)models[j]).setOptions(optionsArray[j]);


I would guess that line has already been used somewhere previously. It is out of place in that spot and I think it is just doing something that was already done. At least it appears that it should be done where you create the models array.



// Run for each classifier model
for(int j = 0; j < models.length; j++) {


Does that comment belong with the lower for loop?


61 fcs[j].buildClassifier(training);


Because you created the array inside the loop, only the array created in the seventh iteration is accessible, and it only has data in the index-6 element.
So when you go to access index-0 element in this loop, you get a null pointer exception since that is all the index-0 element has. As stated above, moving the creation of the array that fcs refers to outside of the for loop should get rid of the exception.


fcs = new FilteredClassifier[models.length]; // Create a FilteredClassifier object
comment should be "Create array to hold each FilteredClassifier"



 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too many questions I am confused enough

The OptionHandler line is not used anywhere else......................

Weka.App

I call weka from my main program as follows..........

new WekaApp.doInit();

I also have the following line near the top of my program

FilteredClassifier [] fcs;

You are so good at identifying what is wrong with my code - but I am having trouble keeping on track with what I want to do
Which is:-

(a) create seven filtered classifiers just the once
(b) run each across new data every six hours

Natasha
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Natasha and Red, please stop quoting entire posts in your replies. If you're responding to specific points of a post, quote only those points. Otherwise it really doesn't help, and only makes he discussion very hard to follow because of all the unnecessary duplication. I've edited several posts along those lines; please do that yourself in the future.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm surprised nobody has said this yet, but perhaps you should StopCoding (<---click that). Writing programs is actually very little writing of code. It is mostly THINKING about what you need to do. Until you know, you can't tell the computer.

So sit down, and think through the problem in English (or any other natural language of your choice). I mean literally write down everything you need your program to do, step by step, in English. Then refine the steps. Make them more and more simple. Get it to the point where a ten year old child could follow them.

THEN you start writing code.
 
Natasha Teokotai
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Fred - that is a fair call........................

I am very new to java

I learn the only way I know how............by taking examples of code and using them for my purpose

In this instance, although the code was inefficient - my program worked for 6 of the 7 classifiers I was wishing to use
The 7th one, LibSVM is a third party classifier - i.e. not a weka original

Somewhere in the LibSVM code or in the weka use of LibSVM is a 'bug' which means that if you repeatedly construct the LibSVM filtered classifier it would be constructed correctly the first time round but incorrectly thereafter
Specifically the 'S' option had the correct value of '3' the first time round and was incorrectly assigned the value '0' thereafter

If I return to my original code - what I was seeking originally was a simple way to explicitly set the 'S' option to '3' for every iteration after the first

Anyway, thank you all (especially Red) for your indulgence

Happy New Year

Natasha
(New Zealand)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!