Prev: Rotate
Next: syntax extension
From: schochet123 on 15 Jan 2010 03:18 On Jan 14, 12:46 pm, DrMajorBob <btre...(a)austin.rr.com> wrote: > For some data, that works pretty well; for other samples it has HUGE > peaks, reaching far above any of the data: This problem can be avoided by using a transformation that is close to the identity for positive values: trans[x_]=(Sqrt[1 + x^2] + x)/2 inv[y_]=(4 y^2 - 1)/(4 y) Simplify[{trans[inv[y]], inv[trans[x]]}, y > 0] To compare the effects of this new transformation with the old one, modify the test code slightly: tryinterp := (data = Sort(a)RandomReal[{0.1, 1}, {20, 2}]; {min, max} = data[[{1, -1}, 1]]; f = Interpolation(a)data; logdata = data /. {x_, y_} -> {x, Log[y]}; invdata = data /. {x_, y_} -> {x, inv[y]}; expinterp = Exp[Interpolation[logdata]@#] &; transinterp = trans[Interpolation[data]@#] &; plota = Plot[Evaluate(a)Through[{f, expinterp}@x], {x, min, max}, PlotRange -> All]; plotb = Plot[Evaluate(a)Through[{f, transinterp}@x], {x, min, max}, PlotRange -> All]; GraphicsRow[{plota, plotb}]) Now evaluate tryinterp several times Steve > > data = Sort(a)RandomReal[{0.1, 1}, {20, 2}]; > {min, max} = data[[{1, -1}, 1]] > f = Interpolation(a)data; > logdata = data /. {x_, y_} -> {x, Log[y]}; > interp = Exp[Interpolation[logdata]@#] &; > Show[Plot[Evaluate(a)Through[{f, interp}@x], {x, min, max}, > PlotRange -> All]] > > (run it several times) >
From: DrMajorBob on 16 Jan 2010 06:10 That works much better, thanks! Bobby On Fri, 15 Jan 2010 02:18:54 -0600, schochet123 <schochet123(a)gmail.com> wrote: > On Jan 14, 12:46 pm, DrMajorBob <btre...(a)austin.rr.com> wrote: >> For some data, that works pretty well; for other samples it has HUGE >> peaks, reaching far above any of the data: > > This problem can be avoided by using a transformation that is close to > the identity for positive values: > > trans[x_]=(Sqrt[1 + x^2] + x)/2 > > inv[y_]=(4 y^2 - 1)/(4 y) > > Simplify[{trans[inv[y]], inv[trans[x]]}, y > 0] > > To compare the effects of this new transformation with the old one, > modify the test code slightly: > > tryinterp := (data = Sort(a)RandomReal[{0.1, 1}, {20, 2}]; > {min, max} = data[[{1, -1}, 1]]; > f = Interpolation(a)data; > logdata = data /. {x_, y_} -> {x, Log[y]}; > invdata = data /. {x_, y_} -> {x, inv[y]}; > expinterp = Exp[Interpolation[logdata]@#] &; > transinterp = trans[Interpolation[data]@#] &; > plota = > Plot[Evaluate(a)Through[{f, expinterp}@x], {x, min, max}, > PlotRange -> All]; > plotb = Plot[Evaluate(a)Through[{f, transinterp}@x], {x, min, max}, > PlotRange -> All]; GraphicsRow[{plota, plotb}]) > > Now evaluate tryinterp several times > > Steve > >> >> data = Sort(a)RandomReal[{0.1, 1}, {20, 2}]; >> {min, max} = data[[{1, -1}, 1]] >> f = Interpolation(a)data; >> logdata = data /. {x_, y_} -> {x, Log[y]}; >> interp = Exp[Interpolation[logdata]@#] &; >> Show[Plot[Evaluate(a)Through[{f, interp}@x], {x, min, max}, >> PlotRange -> All]] >> >> (run it several times) >> > -- DrMajorBob(a)yahoo.com
From: Ray Koopman on 17 Jan 2010 07:11 On Jan 15, 12:18 am, schochet123 <schochet...(a)gmail.com> wrote: > On Jan 14, 12:46 pm, DrMajorBob <btre...(a)austin.rr.com> wrote: > >> For some data, that works pretty well; for other samples >> it has HUGE peaks, reaching far above any of the data: > > This problem can be avoided by using a transformation that > is close to the identity for positive values: > > trans[x_] = (Sqrt[1 + x^2] + x)/2 > > inv[y_] = (4 y^2 - 1)/(4 y) There's a whole family of transformations here: trans[c_,x_] = (Sqrt[4c + x^2) + x)/2 inv[c_,y_] = y - c/y Extremely small values of c give results that approach those obtained by chopping the interpolation at 0.
From: Noqsi on 18 Jan 2010 02:35
On Jan 17, 5:11 am, Ray Koopman <koop...(a)sfu.ca> wrote: > On Jan 15, 12:18 am, schochet123 <schochet...(a)gmail.com> wrote: > > > On Jan 14, 12:46 pm, DrMajorBob <btre...(a)austin.rr.com> wrote: > > >> For some data, that works pretty well; for other samples > >> it has HUGE peaks, reaching far above any of the data: > > > This problem can be avoided by using a transformation that > > is close to the identity for positive values: > > > trans[x_] = (Sqrt[1 + x^2] + x)/2 > > > inv[y_] = (4 y^2 - 1)/(4 y) > > There's a whole family of transformations here: > > trans[c_,x_] = (Sqrt[4c + x^2) + x)/2 > > inv[c_,y_] = y - c/y > > Extremely small values of c give results that approach those obtained > by chopping the interpolation at 0. These transformations have the property that the interpolation behaves differently for small and large numbers, with the transition at a scale given by Sqrt[c]. The Log/Exp pair I suggested is scaleless. {Sqrt[x],y^2} is another scaleless transformation. All such transformations will exhibit artifacts from some point of view given some data set: there is no flawless universal interpolation procedure. The {Sqrt[x],y^2} pair is useful for data that's proportional to counts of independent events (like electric current over a potential barrier), as it approximately gives each point its proper "weight" in the analysis, given the correlation of the shot noise variance with the expectation. However, the interpolation may "bounce" off the x- axis... |