how to control duplicate function names

I am using the Neural Network toolbox and attempting to determine how a trained patternnet would classify some test data. The documentation indicates I should use "classify" for this purpose. However, when I do so, I get an error message, because (as documented by "which classify") an unrelated function named "classify" is found preferentially on my matlabpath (/Applications/MATLAB_R2016a.app/toolbox/stats/stats/classify.m). If I "examine package contents" (I'm on a Mac), in fact that stats version of classify is the only one found. If I "doc classify" I get the stats version (re: Discriminant analysis), but at the top there is a notation: "Other uses of classify: nnet/SeriesNetwork.classify", and if I follow the offered link I find documentation on the version of classify appropriate for neural networks. How can I make that version of "classify" the one found in response to a command-line entry or a script? The same problem pertains to "predict". This overloading of function names seems like a very bad idea - what gives?

2 commentaires

per isakson
per isakson le 11 Août 2016
Modifié(e) : per isakson le 11 Août 2016
Doc says
"[Ypred,scores] = classify(net,X) estimates the classes for the data in X using the trained network, net."
In this case classify is a method of the class, SeriesNetwork, and net is an object of that class.
I guess your first input argument is not an object of SeriesNetwork.
Walter Roberson
Walter Roberson le 11 Août 2016
patternnet and SeriesNetwork are not the same, so classify() cannot be used with a patternnet.

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 11 Août 2016

0 votes

5 commentaires

jkr
jkr le 11 Août 2016
Modifié(e) : Walter Roberson le 11 Août 2016
I want to determine how the net will categorize new patterns (in my case, thousands of 32-sample waveforms). I shouldn't need to provide targets.
I can generate the nnet outputs (outputs = net(testData)), but these are continuous values between 0 and 1. I want classes (0 or 1 would do). I could classify them myself based on >, < 0.5, but I am not sure this is how the nnet would classify them.
In any case, the answer does not address the issue of overloaded function names and how to control which is used. There is a function "classify" documented for neural nets that does what I want, but the function "classify" for the stats package (which has different inputs and outputs) is taking precedence, so that I cannot use the nnet version.
Walter Roberson
Walter Roberson le 11 Août 2016
Notice that "object functions" is #6. Functions in the current folder is #8, functions in other folders is #9. The classify() that applies to SeriesNet takes a SeriesNetwork object as its first parameter. The classify() from the Statistics package takes a double as its first argument. MATLAB looks at the data types of the parameters to determine which calls are permitted.
If you were to construct a SeriesNetwork object using trainNetwork, then classify() applied to it would be the classify routine you are interested in.
When you are constructing the patternnet or SeriesNetwork you need to provide targets for the input samples. Without targets the routines cannot tell which samples are examples of the same class and which are not.
Consider for example a series of hand-drawn images, one a circle, one a circle with a small diagonal line, one a vertical line. Should the program, without being told what classes they are in, then deduce that the presence of a diagonal line creates a different class? If it does so and then you feed in a vertical line with a diagonal line near the top, the program would have to deduce that it was a different class than anything seen so far. But it isn't. The circle might have been a capital-O and the circle with diagonal line might have been a capital-Q and the vertical bar might have been the digit 1, but the vertical bar with the diagonal is also the digit 1. There are all kinds of circumstances like that where some changes are completely unimportant and other changes might be small but important. You cannot train your patterns accurately without multiple examples of the same pattern giving an idea of the range intended to all be considered the same thing, and all of those variations must be given the same target at training time.
After training is over and you have your network then you use perform() if you are using a patternnet: it takes input samples without any target information and predicts the target the samples belong to.
jkr
jkr le 11 Août 2016
The answer is supplemented by two helpful comments, one from the answer's author, another from per isakson. Walter's second answer spells out in the kind of detail I needed what I was getting wrong.
For my purposes, classifying the outputs as >= or < 0.5 (following the convention of confusion() for =) using find seems like it will do what I need.
Thanks to both per and Walter.
Walter Roberson
Walter Roberson le 11 Août 2016
You could use round() if the values from [0, 1]
The NNET Roolbox has functions that convert vector output to classindices and vice versa.
classindices = [ 1 3 5 2 4 ]
target = full(ind2vec(classindices))
classindices = vec2ind(target)
Hope this helps.
Greg

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Deep Learning Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by