# Debugging the context of a Package

I am working on a package of functions that complement the NeuralNetworks package that Wolfram provides. I am having a problem with the following code, which is essentially a wrapper for two commands that I run frequently:

runNetwork[data_,desc_,dlist_,{tlist_,vlist_}]:= Module[{fdfwd,m,r},
fdfwd = InitializeRBFNet[
desc[[tlist,dlist]],
data[[tlist]],
1,RandomInitialization->False];
{m,r} = NeuralFit[fdfwd,
desc[[tlist,dlist]],
data[[tlist]],
desc[[vlist,dlist]],
data[[vlist]],
100,Method->SteepestDescent,CriterionPlot->False];
{m,r}]


When I declare this function within my notebook, it runs as expected; however if I place it in a package (for instance, MyNeuralNetworks) then I get errors of the following type:

Set::shape: "Lists {SolarNeuralNetworkPrivatem\$2436,SolarNeuralNetworkPrivater\$2436} and SolarNeuralNetworkPrivateNeuralFit[<<1>>] are not the same shape."

which suggests to me that the list fdfwd that is returned by the first function is not being passed correctly to the second function. I have tried adding a Needs["NeuralNetworks"] line in both the Public and Private portions of the package as well as in the BeginPackage line following this question and answer. I'm new to package writing, so there may be something obvious I'm missing. It's possible that the answer I'm looking for is hidden somewhere in this discussion but I don't know how to implement those suggestions in my context.

-

Perhaps this question may be of use to future visitors. I had assumed that using

Needs["NeuralNetworks"]


or

BeginPackage["MyNeuralNetworks",{"NeuralNetworks"}]


was sufficient to establish the $ContextPath for my package; however when I loaded the neural networks package into a notebook, I noticed: $ContextPath
{"NeuralNetworksVQ", "NeuralNetworksUnsupervisedNet", "NeuralNetworksPerceptron",
"NeuralNetworksNeuralFit", "NeuralNetworksHopfield",
"NeuralNetworksFeedForwardRBFNet", "NeuralNetworksDynamicNet",
"NeuralNetworksCommon", "NeuralNetworksCommonCBV", "NeuralNetworks", ...}


I wrongfully thought that Needing NeuralNetworks would automatically include the rest of the needed packages into my context. Explicitly including all of the neural network packages in my custom package did the trick:

BeginPackage["MyNeuralNetwork",{"NeuralNetworksVQ", "NeuralNetworksUnsupervisedNet",
"NeuralNetworksPerceptron", "NeuralNetworksNeuralFit",
"NeuralNetworksHopfield", "NeuralNetworksFeedForwardRBFNet",
"NeuralNetworksDynamicNet", "NeuralNetworksCommon",
"NeuralNetworksCommonCBV", "NeuralNetworks"}]

-