variables in packages
- To: mathgroup at smc.vnet.net
- Subject: [mg25877] variables in packages
- From: Andre Heinemann <a.heinemann at ifw-dresden.de>
- Date: Sat, 4 Nov 2000 02:04:19 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hi mathgroup,
I wrote a small package for my special purposes in
Nonlinear Regression. The code as a function in a notebook
works well, but it dosn't work as a package.
The rules: (BestFitParameters /. nonlinregress) and
(ParameterCITable /. nonlinregress) did not work in the same
way, because NewRegress`Private`BestFitParameters does not exist.
This was the answer of mathematica during a test of my package.
How can I declare BestFitParameters that mathematica knows that
it is a variable in NonlinearRegress usable also from outside
of the package ?
I send the whole code, not because I like to bore you, but may
be the problem is situated in a othe part of the code.
I hope you can help me because I tried a lot of different thinks,
but nothink works.
Thanks,
Andre
__________snip, snip________________________________________
BeginPackage["NewRegress`",
(* needed for NonlinearRegress *)
"Statistics`NonlinearFit`",
(* needed for BooleanSelect*)
"Statistics`DataManipulation`"];
NewRegress::usage = "NewRegress[data, weights,
model_function,
{x,xmin,xmax},allparameter,fitparameter,precisition,options]
returns a list of a NonlinearRegression of the data with the
model_function.
and weights. output[[1]],output[[2]] are for compatibility. output[[3]]
is the full report 3."
Begin["`Private`"]
NewRegress[data_List, gewichte_List, modelFunction_, Xvariable_List,
parameter_List, fit_List, precision_Integer, opt___] :=
Block[{errlist = {},
fitselect = {},
fitinput = {},
fixselect = {},
fixinput = {},
nonlinregress = {},
out1 = {},
useddata = {},
usedgewichte = {},
xfree = Xvariable[[1]],
xmin = Xvariable[[2]],
xmax = Xvariable[[3]],
pll, j, i
},
For[j = 1; useddata = {}; usedgewichte = {}, j <= Length[data], j++,
If[data[[j]][[1]] >= xmin && data[[j]][[1]] <= xmax,
useddata = Join[useddata, {data[[j]]}];
usedgewichte = Join[usedgewichte, {gewichte[[j]]}]]];
pll = Length[parameter];
fitselect = Table[MemberQ[fit, parameter[[i, 1]]], {i, 1, pll}];
fitinput = BooleanSelect[parameter, fitselect];
fixselect = Table[Not[fitselect[[i]]], {i, 1, pll}];
fixinput =
Table[(BooleanSelect[parameter, fixselect])[[i,
1]] -> (BooleanSelect[parameter, fixselect])[[i, 2]], {i, 1,
Length[(BooleanSelect[parameter, fixselect])]}];
nonlinregress =
NonlinearRegress[useddata, Evaluate[modelFunction] /. fixinput,
Xvariable[[1]], fitinput, ShowProgress -> False,
Weights -> usedgewichte, opt];
out1 = Join[fixinput, (BestFitParameters /. nonlinregress)];
For[j = 1; outlist = {}, j <= pll, j++,
For[i = 1, i <= pll, i++,
If[parameter[[j]][[1]] === out1[[i]][[1]],
outlist =
Join[outlist, {parameter[[j]][[1]] ->
SetPrecision[out1[[i]][[2]], precision]}]]]];
errlist =
Table[{fitinput[[j, 1]],
SetPrecision[(ParameterCITable /. nonlinregress)[[1]][[j, 1]],
precision],
SetPrecision[
Max[Abs[(ParameterCITable /. nonlinregress)[[1]][[j,
3]] - (ParameterCITable /. nonlinregress)[[1]][[j,
1]]]],
precision]}, {j, 1, Length[fitinput]}];
{outlist, errlist, nonlinregress}
]
End[]
EndPackage[]
______________snip * snip__________________________
--
+-----------------------------------+-----------------------------+
| email: a.heinemann at ifw-dresden.de | Andre Heinemann |
+-----------------------------------+-----------------------------+