Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9110 > unrolled thread

Mathematica results different on different computers !

Started byNabeel Butt <nabeel.butt@gmail.com>
First post2012-03-18 07:45 +0000
Last post2012-03-20 07:20 +0000
Articles 3 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Mathematica results different on different computers ! Nabeel Butt <nabeel.butt@gmail.com> - 2012-03-18 07:45 +0000
    Re: Mathematica results different on different computers ! David Bailey <dave@removedbailey.co.uk> - 2012-03-19 10:03 +0000
    Re: Mathematica results different on different Nabeel Butt <nabeel.butt@gmail.com> - 2012-03-20 07:20 +0000

#9110 — Mathematica results different on different computers !

FromNabeel Butt <nabeel.butt@gmail.com>
Date2012-03-18 07:45 +0000
SubjectMathematica results different on different computers !
Message-ID<jk43qf$dtt$1@smc.vnet.net>
Hi Guys ...
     I run a piece of code on two different computers (different hardwares)
and I get different results.I think its something to do with overflow or
different precision on systems ? Personally I think my laptop with an
inferior hardware is giving me correct results. The code does involve some
simulation but running the simulation gives the same result on one
particular computer but different for different computers ! You can run and
tell me what answers you are getting ....Thanks in advance....and my code
is below :
\[Lambda] = 0.05;
\[Mu] = 0.05;
T = 1;
nn = 4;
\[CapitalDelta]T = T/nn;
m1 = 0.08;
\[Sigma]1 = 0.2;
m2 = 0.14;
\[Sigma]2 = 0.8;
\[Rho] = 0.1;
mean1 = (m1 - (\[Sigma]1^2)/2)*\[CapitalDelta]T;
var1 = (\[Sigma]1^2)*\[CapitalDelta]T;
rmean1 = E^(mean1 + 1/2 var1);
rvar1 = ((E^var1 - 1) E^(2*mean1 + var1));
mean2 = (m2 - (\[Sigma]2^2)/2)*\[CapitalDelta]T;
var2 = (\[Sigma]2^2)*\[CapitalDelta]T;
rmean2 = E^(mean2 + 1/2 var2);
rvar2 = ((E^var2 - 1) E^(2*mean2 + var2));
b1 = {rk1l = 0.001, rk1u = (rmean1 + 5*Sqrt[rvar1])};
b2 = {rk2l = 0.001, rk2u = (rmean2 + 5*Sqrt[rvar2])};

dl = (rk1u - rk1l)/Num;
dk = (rk2u - rk2l)/Num;
\[ScriptCapitalD] =
  TransformedDistribution[
   Exp[ {u, v}], {u, v} \[Distributed]
    MultinormalDistribution[{(m1 - (\[Sigma]1^2)/
          2)*\[CapitalDelta]T, (m2 - (\[Sigma]2^2)/
          2)*\[CapitalDelta]T}, {{\[Sigma]1^2*\[CapitalDelta]T, \
\[Rho]*\[Sigma]1*\[Sigma]2*\[CapitalDelta]T}, {\[Rho]*\[Sigma]1*\
\[Sigma]2*\[CapitalDelta]T, \[Sigma]2^2*\[CapitalDelta]T}}]];
data = Parallelize[RandomVariate[\[ScriptCapitalD], 10^5]];
ParallelEvaluate[data];


bndry3[Num_, data_] :=
  Module[{UU, M, \[Lambda], \[Mu], \[CapitalDelta]T, s, m, \[Sigma],
    mean, var, rmean, rvar, rkl, rku, dr, ddist, rvals, pvals, amin,
    amax, da, tlist, JN, some, blist, tlist1, tlist2, sol1, sol2,
    templist, l, points, pu, pl, dp, a, b, c, zi, Nm, Nz, Na, zW,
    m1, \[Sigma]1, m2, \[Sigma]2, \[Rho], mean1, var1, rmean1, rvar1,
    mean2, var2, rmean2, rvar2, b1, b2, dl, dk, xvals, yvals, rk1l,
    rk1u, rk2l, rk2u, \[ScriptCapitalD]1, dist, \[ScriptCapitalD],
    prob, JJ},

   Off[InterpolatingFunction::dmval];
   sll[ll_, elem_] := ll[[Ordering[ll[[All, elem]]]]];
   M = 0.5;
   \[Lambda] = 0.05;
   \[Mu] = 0.05;
   \[CapitalDelta]T = T/nn;
   s = E^(0.05*\[CapitalDelta]T);
   m1 = 0.08;
   \[Sigma]1 = 0.2;
   m2 = 0.14;
   \[Sigma]2 = 0.8;
   \[Rho] = 0.1;
   UU = 7;
   mean1 = (m1 - (\[Sigma]1^2)/2)*\[CapitalDelta]T;
   var1 = (\[Sigma]1^2)*\[CapitalDelta]T;
   rmean1 = E^(mean1 + 1/2 var1);
   rvar1 = ((E^var1 - 1) E^(2*mean1 + var1));
   mean2 = (m2 - (\[Sigma]2^2)/2)*\[CapitalDelta]T;
   var2 = (\[Sigma]2^2)*\[CapitalDelta]T;
   rmean2 = E^(mean2 + 1/2 var2);
   rvar2 = ((E^var2 - 1) E^(2*mean2 + var2));
   b1 = {rk1l = 0.001, rk1u = (rmean1 + 5*Sqrt[rvar1])};
   b2 = {rk2l = 0.001, rk2u = (rmean2 + 5*Sqrt[rvar2])};

   dl = (rk1u - rk1l)/Num;
   dk = (rk2u - rk2l)/Num;
   \[ScriptCapitalD] =
    TransformedDistribution[
     Exp[ {u, v}], {u, v} \[Distributed]
      MultinormalDistribution[{(m1 - (\[Sigma]1^2)/
            2)*\[CapitalDelta]T, (m2 - (\[Sigma]2^2)/
            2)*\[CapitalDelta]T}, {{\[Sigma]1^2*\[CapitalDelta]T, \
\[Rho]*\[Sigma]1*\[Sigma]2*\[CapitalDelta]T}, {\[Rho]*\[Sigma]1*\
\[Sigma]2*\[CapitalDelta]T, \[Sigma]2^2*\[CapitalDelta]T}}]];

   \[ScriptCapitalD]1 = SmoothKernelDistribution[data];

   g[x_, y_] := Evaluate[CDF[\[ScriptCapitalD]1, {x, y}]];


   fx1[r_] := PDF[LogNormalDistribution[mean1, Sqrt[var1]], r];
   fx2[r_] := CDF[LogNormalDistribution[mean1, Sqrt[var1]], r];
   pu = 1;
   pl = 0;
   dp = (pu - pl)/Num;
   gx1[p_] := InverseCDF[LogNormalDistribution[mean1, Sqrt[var1]], p];
   xvals =
    Flatten[{rk1l, Table[gx1[i + dp], {i, pl, pu - 2*dp, dp}], rk1u}];

   fy1[r_] := PDF[LogNormalDistribution[mean2, Sqrt[var2]], r];
   fy2[r_] := CDF[LogNormalDistribution[mean2, Sqrt[var2]], r];
   pu = 1;
   pl = 0;
   dp = (pu - pl)/Num;
   gy1[p_] := InverseCDF[LogNormalDistribution[mean2, Sqrt[var2]], p];
   yvals =
    Flatten[{rk2l, Table[gy1[i + dp], {i, pl, pu - 2*dp, dp}], rk2u}];




   f[x_, y_] := Evaluate[PDF[\[ScriptCapitalD]1, {x, y}]];

   dist =
    Flatten[Table[{prob = (NIntegrate[

          f[x, y], {x, xvals[[i]], xvals[[i + 1]]}, {y, yvals[[j]],
           yvals[[j + 1]]}, AccuracyGoal -> 4]); {NIntegrate[
         x*(f[x, y])/prob
         , {x, xvals[[i]], xvals[[i + 1]]}, {y, yvals[[j]],
          yvals[[j + 1]]}, AccuracyGoal -> 4],
        NIntegrate[
         y*(f[x, y])/(prob), {x, xvals[[i]], xvals[[i + 1]]}, {y,
          yvals[[j]], yvals[[j + 1]]}, AccuracyGoal -> 4]},

       prob}, {i, 1, Num}, {j, 1, Num}], 1];


   amin = N[0.001];
   amax = N[0.999];
   da = 0.01;

   (*dist/.{{x_Real,y_Real},z_Real}->x+y+z*)
   tlist1 = Parallelize[ParallelEvaluate[
      Off[FindMinimum::reged]];
     ParallelEvaluate[Off[FindMaximum::lstol]]; Table[{a,
       {l =
         Max[templist = {(sol1 = Flatten[Last[NestList[{{#[[1, 1]]/2},

                    Reverse[
                    Last[sll[
                    Flatten[
                    Table[{{\[Xi]}, (Total[(dist /. {{r_Real, S_Real},
                     p_Real} -> (Log[(S + \[Xi] (r -
                    S) + \[Mu] (\[Xi] - a) S)]*p))])}, {\[Xi],
                    If[(#[[2, 2, 1]] - 2*#[[1, 1]]) >=
                    0, (#[[2, 2, 1]] - 2*#[[1, 1]]), 0],
                    If[(#[[2, 2, 1]] + 2*#[[1, 1]]) <=
                    a, (#[[2, 2, 1]] + 2*#[[1, 1]]), a], #[[1, 1]]}],
                    0], 2]]]} & ,
                   {{a/4}, {-100, {a/2}}}, UU]][[2]]])[[1]], (sol2 =
               Flatten[Last[NestList[{{#[[1, 1]]/2},

                    Reverse[
                    Last[sll[
                    Flatten[
                    Table[{{\[Xi]}, (Total[
                    dist /. {{r_Real, S_Real},
                    p_Real} -> (Log[(S + \[Xi] (r -
                    S) - \[Lambda] (\[Xi] - a) S)]*p)])}, {\[Xi],
                    If[(#[[2, 2, 1]] - 2*#[[1, 1]]) >=
                    a, (#[[2, 2, 1]] - 2*#[[1, 1]]), a],
                    If[(#[[2, 2, 1]] + 2*#[[1, 1]]) <= (
                    1 + a*\[Lambda])/(
                    1 + \[Lambda]), (#[[2, 2, 1]] + 2*#[[1, 1]]), (
                    1 + a*\[Lambda])/(1 + \[Lambda])], #[[1, 1]]}],
                    0], 2]]]} & ,
                   {{0.25*((1 + a*\[Lambda])/(1 + \[Lambda]) -
                    a)}, {-100, {0.5*(a + (1 + a*\[Lambda])/(
                    1 + \[Lambda]))}}}, UU]][[2]]])[[1]],
            Total[dist /. {{r_Real, S_Real}, p_Real} ->
               Log[(S + a (r - S))]*p]}],
        If[templist[[3]] == l, 3,
         Flatten[Position[templist, l]][[1]]],
        Piecewise[{{0, templist[[3]] == l}, {sol1[[2]],
           templist[[1]] == l}, {sol2[[2]],
           templist[[2]] == l}}]}}, {a, amin, amax, da}]];
   (*points=Select[tlist,#[[2,2]]==3&]/.{a_,{J_,
   I_,\[CapitalDelta]_}}->a
   Graphics[Point[points],Axes->True]*)
   (*points=Select[Flatten[templist/.{{x_,y_},{z_,w_}}->{{x,y},{w}},
   1],#[[2]][[1]]==3&]/.{{x_,y_},{w_}}->{x,y};*)
   (*points=Select[tlist,#[[2,2]]==3&]/.{x_,{z_,w_}}->x;
   points*)
   JN = Interpolation[tlist1 /. {x_, {z_, w_, y_}} -> {x, z}];
   (*PN=Interpolation[tlist/.{x_,{z_,w_,y_}}->{x,y}];*)
   (*Off[InterpolatingFunction::dmval];*)
   (*Plot[JN[x],{x,0,1}]*)
   some = NestList[(JJ = #[[2]]; {tlist = Parallelize[ParallelEvaluate[
           Off[FindMinimum::reged]];
          ParallelEvaluate[Off[FindMaximum::lstol]];
          ParallelEvaluate[Off[InterpolatingFunction::dmval]];
          Table[(*nlist=(#[[1]]/.{x_,{z_,w_,y_}}->y);*){a,
            {l =
              Max[templist = {(sol1 =
                    Flatten[Last[NestList[{{#[[1, 1]]/2},

                    Reverse[
                    Last[sll[
                    Flatten[
                    Table[{{\[Xi]}, (Total[
                    dist /. {{r_Real, S_Real},
                    p_Real} -> (((Log[(S + \[Xi] (r -
                    S) + \[Mu] (\[Xi] - a) S)] +
                    JJ[(\[Xi]*
                    r)/(S + \[Xi] (r - S) + \[Mu] (\[Xi] - a) S)])*
                    p))])}, {\[Xi],
                    If[(#[[2, 2, 1]] - 2*#[[1, 1]]) >=
                    0, (#[[2, 2, 1]] - 2*#[[1, 1]]), 0],
                    If[(#[[2, 2, 1]] + 2*#[[1, 1]]) <=
                    a, (#[[2, 2, 1]] + 2*#[[1, 1]]), a], #[[1, 1]]}],
                    0], 2]]]} & ,
                    {{a/4}, {-100, {a/2}}}, UU]][[2]]])[[1]], (sol2 =
                    Flatten[Last[NestList[{{#[[1, 1]]/2},

                    Reverse[
                    Last[sll[
                    Flatten[
                    Table[{{\[Xi]}, (Total[
                    dist /. {{r_Real, S_Real},
                    p_Real} -> ((Log[(S + \[Xi] (r -
                    S) - \[Lambda] (\[Xi] - a) S)] +
                    JJ[(\[Xi]*
                    r)/(S + \[Xi] (r - S) - \[Lambda] (\[Xi] -
                    a) S)])*p)])}, {\[Xi],
                    If[(#[[2, 2, 1]] - 2*#[[1, 1]]) >=
                    a, (#[[2, 2, 1]] - 2*#[[1, 1]]), a],
                    If[(#[[2, 2, 1]] + 2*#[[1, 1]]) <= (
                    1 + a*\[Lambda])/(
                    1 + \[Lambda]), (#[[2, 2, 1]] + 2*#[[1, 1]]), (
                    1 + a*\[Lambda])/(1 + \[Lambda])], #[[1, 1]]}],
                    0], 2]]]} & ,
                    {{0.25*((1 + a*\[Lambda])/(1 + \[Lambda]) -
                    a)}, {-100, {0.5*(a + (1 + a*\[Lambda])/(
                    1 + \[Lambda]))}}}, UU]][[2]]])[[1]],

                 Total[dist /. {{r_Real, S_Real},
                    p_Real} -> (Log[(S + a (r - S))] +
                    JJ[(a*r)/(a*r + (1 - a) S)])*p]}],
             If[templist[[3]] == l, 3,
              Flatten[Position[templist, l]][[1]]],
             Piecewise[{{0, templist[[3]] == l}, {sol1[[2]],
                templist[[1]] == l}, {sol2[[2]],
                templist[[2]] == l}}]}}, {a, amin, amax, da}]],
        Interpolation[
         tlist /. {x_, {z_, w_, y_}} -> {x, z}]}) &, {tlist1, JN},
     nn - 1]];
stuff = Table[{1/NN, bndry3[NN, data]}, {NN, 4, 7}];
listn[a_] := {#[[1]], #[[2]][[4, 2]][a]} & /@ stuff;
a = 0.5;
g1 = ListPlot[listn[a], PlotStyle -> {Red, PointSize[Large]}]
________________________________________________________________________________
<http://t2.gstatic.com/images?q=tbn:ANd9GcRd4WJa3qO12skxxSAppQ9HimoQsMP5o--uCIe7yxZahJqlkN4z>
"We have not succeeded in answering all our problems.The answers we have
found only serve to raise a whole set of new questions.In some ways we feel
that we are as confused as ever,but we believe we are confused on a higher
level and about more important things!! Haha"
"One day we  definitely get to see all the beauty present in this world
!!!"
"Life can only be understood going backwards but it must be lived going
forwards!"
________________________________________________________________________________
THIS MESSAGE IS ONLY INTENDED FOR THE USE OF THE INTENDED
RECIPIENT(S) AND MAY CONTAIN INFORMATION THAT IS PRIVILEGED,
PROPRIETARY AND/OR CONFIDENTIAL. If you are not the intended
recipient, you are hereby notified that any review, retransmission,
dissemination, distribution, copying, conversion to hard copy or
other use of this communication is strictly prohibited. If you are
not the intended recipient and have received this message in error,
please notify me by return e-mail and delete this message from your
system. Nabeel Butt Inc.





Nabeel Butt
UWO,London
Ontario, Canada

[toc] | [next] | [standalone]


#9152

FromDavid Bailey <dave@removedbailey.co.uk>
Date2012-03-19 10:03 +0000
Message-ID<jk70a4$12a$1@smc.vnet.net>
In reply to#9110
On 18/03/2012 07:45, Nabeel Butt wrote:
> Hi Guys ...
>       I run a piece of code on two different computers (different hardwares)
> and I get different results.I think its something to do with overflow or
> different precision on systems ? Personally I think my laptop with an
> inferior hardware is giving me correct results. The code does involve some
> simulation but running the simulation gives the same result on one
> particular computer but different for different computers ! You can run and
> tell me what answers you are getting ....Thanks in advance....and my code
> is below ........

When I run this on 8.0.4 on Windows 64-bit XP, I get a graph with 4 
points, in roughly a straight line. The last point is at (approx) 
{0.25,0.0040}, the first at approx {0.161,0.00245} .

Possible reasons for varying answers:

1)     Random numbers not initialised to the same point.

2)     Possible slight hardware differences between 32 and 64-bit PC's

Parallel constructions could give problems if used incorrectly. This 
might vary depending on the number of cores available.

David Bailey
http://www.dbaileyconsultancy.co.uk

[toc] | [prev] | [next] | [standalone]


#9161 — Re: Mathematica results different on different

FromNabeel Butt <nabeel.butt@gmail.com>
Date2012-03-20 07:20 +0000
SubjectRe: Mathematica results different on different
Message-ID<jk9b4o$bkg$1@smc.vnet.net>
In reply to#9110
Hi David
    Thanks for all your efforts :)
   Number of simulation was set to a large value so the final output should
have a fairly less noise.Infact , my laptop with version 8.0.1 is giving
results correctly.
 I did a step by step comparison of the output of two different versions of
Mathematica(8.0.1 and 8.0.4)  as suggested by Ralph .It seems that the only
thing that differs is the output from SmoothKernelDistribution[] ---in
version 8.0.4 the output is faulty.Parellization wasnt applied at this
point and so why did 8.0.4 result in faulty mechanism inside
SmoothKernelDist..[] function. Almost all hardware using 8.0.4 are giving
faulty outputs---I theoretically verified that SmoothKernelDist..[] with
default 'options' in 8.0.4 gives faulty output whereas in 8.0.1 it gives
the correct output.
    Your email much appreciated ! Have a great day !
         Nabeel
________________________________________________________________________________
<http://t2.gstatic.com/images?q=tbn:ANd9GcRd4WJa3qO12skxxSAppQ9HimoQsMP5o--uCIe7yxZahJqlkN4z>
"We have not succeeded in answering all our problems.The answers we have
found only serve to raise a whole set of new questions.In some ways we feel
that we are as confused as ever,but we believe we are confused on a higher
level and about more important things!! Haha"
"One day we  definitely get to see all the beauty present in this world
!!!"
"Life can only be understood going backwards but it must be lived going
forwards!"
________________________________________________________________________________
THIS MESSAGE IS ONLY INTENDED FOR THE USE OF THE INTENDED
RECIPIENT(S) AND MAY CONTAIN INFORMATION THAT IS PRIVILEGED,
PROPRIETARY AND/OR CONFIDENTIAL. If you are not the intended
recipient, you are hereby notified that any review, retransmission,
dissemination, distribution, copying, conversion to hard copy or
other use of this communication is strictly prohibited. If you are
not the intended recipient and have received this message in error,
please notify me by return e-mail and delete this message from your
system. Nabeel Butt Inc.





Nabeel Butt
UWO,London
Ontario, Canada



On Mon, Mar 19, 2012 at 6:00 AM, David Bailey <dave@removedbailey.co.uk>wrote:

> On 18/03/2012 07:45, Nabeel Butt wrote:
> > Hi Guys ...
> >       I run a piece of code on two different computers (different
> hardwares)
> > and I get different results.I think its something to do with overflow or
> > different precision on systems ? Personally I think my laptop with an
> > inferior hardware is giving me correct results. The code does involve
> some
> > simulation but running the simulation gives the same result on one
> > particular computer but different for different computers ! You can run
> and
> > tell me what answers you are getting ....Thanks in advance....and my code
> > is below ........
>
> When I run this on 8.0.4 on Windows 64-bit XP, I get a graph with 4
> points, in roughly a straight line. The last point is at (approx)
> {0.25,0.0040}, the first at approx {0.161,0.00245} .
>
> Possible reasons for varying answers:
>
> 1)     Random numbers not initialised to the same point.
>
> 2)     Possible slight hardware differences between 32 and 64-bit PC's
>
> Parallel constructions could give problems if used incorrectly. This
> might vary depending on the number of cores available.
>
> David Bailey
> http://www.dbaileyconsultancy.co.uk
>
>
>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web