# Tag Info

18

A nice question. Sampling from tCopula is done in stages. First a sample is generated from the copula with uniform marginal distributions, and then quantiles of appropriate marginal distributions are applied to the respective slots. Most of the time goes into evaluation of these quantiles, and they are expensive to compute. Being interested in $\geqslant ... 10 I think this may be a duplicate of: How to avoid unpacking from LanguageExtendedFullDefinition In Mathematica parallelism is only useful when processing takes longer than data transfer, otherwise the overhead of that transfer will make the parallel operation slower than the plain one. It should be somewhat faster than your original use of ParallelMap, but ... 10 This is a common limitation experienced in versions prior to 9. As Oleksandr explains: Are you by chance using Mathematica 8? Integers were based on 32-bit machine values in previous versions, and this was changed to 64-bit only in version 9. As a result, Range[2^31, 2^31 + 1] returns a packed array only in the most recent version. Fold automatically ... 9 The default SumCompileLength is 250. You can increase this number for example to 500 using: SetSystemOptions["CompileOptions" -> {"SumCompileLength" -> 500}] 9 I believe the difference you are observing is attributable to packed arrays. What is a Mathematica packed array? The difference between slow and fast is due to the behavior of RandomChoice. Observe: << Developer RandomChoice[{pr1, 1 - pr1} -> {1, 0}, 1350] // PackedArrayQ RandomInteger[1, 1350] // PackedArrayQ ... 7 The progress cell that you see when you load data from the Wolfram server is a "PrintTemporary" cell. The following example is based on what is used by Mathematica to print these cells. You can modify and adapt this to suit your use. monitorCell[i_] := CellPrint@Cell[ BoxData[ FrameBox[StyleBox[ToBoxes@StringForm["Progress: 1", i], ... 7 What about timer[s_] := Dynamic[s - Clock[{0, s, 1}, s, 1]] 6 To demonstrate the time saving using a linked list instead of AppendTo :- time1[myN_] := First@Timing[ finalList = {}; For[i = 1, i <= myN - 3, i++, For[j = i + 1, j <= myN - 2, j++, For[k = j + 1, k <= myN - 1, k++, l = RandomInteger[{k + 1, myN}]; AppendTo[finalList, {i, j, k, l}]]]]]; time2[myN_] := First@Timing[ ... 6 With the help of comments on this and other stackexchange pages I managed to solve the problem of how to use custom distributions in things like CopulaDistribution (and other functions like RandomVariate, Expectation, etc), and given that it took me a couple of days’ hard slog I thought I’d share my discoveries with this community. Please excuse the flippant ... 6 This isn't the most exciting example but I hope it helps. Use AbsoluteTiming to time the function and use Table to iterate over a set of values. We're simply going to time the Pause function which just waits x seconds, in this case x^2. The values will be stored as list. First gives us the first element of the output of AbsoluteTiming which is the time ... 6 I am not sure PrintTemporary doesn't do your job Module[{pTmp, etc}, pTmp = PrintTemporary["bla"]; Pause[3];(* do your stuff *) NotebookDelete[pTmp]; PrintTemporary["blo"]; Pause[2] (*do more stuff*) ] Your function would be something like SetAttributes[DynamicDisplayFunction, HoldFirst]; DynamicDisplayFunction[code_, message_] := Module[{tmp = ... 6 Your question are impossible to answer in detail. Let my try anyway: a) No one can tell you the exact reason of the different timings on your machine. You should keep in mind that it is very possible, that one run of your computation has side-effects you are not aware of. One obvious example for such a behavior can be demonstrated when you try this on a ... 5 You need your evaluations to take enough time for this to display. For example this works fine for me: DynamicModule[{tmp}, Monitor[ tmp = First @ Import["http://www.census.gov/foreign-trade/balance/country.zip", "*"], Grid[{{"imported data being downloaded..."}}, Frame -> All, FrameStyle -> Darker[Blend[{Blue, Green}], .1], ... 4 According to Leonid Shifrin recommendation: Put your Mathematica session in debug mode by going to Evaluation->Debugger F[x_] := Total[DigitCount[Mod[(2^10000) + 1, Prime[x]]]] Table[F[x], {100000}]; // RuntimeTools`Profile 4 If you don't want to change the system options just to make Sum auto-compile, then you could instead replace Sum by Total: Clear[vec, time]; vec = Table[i, {i, 100}, {j, 100}, {k, 300}]; time = Timing[ Table[Total[vec[[i, j, 1 ;; 250]]], {i, 1}, {j, 1}]][[1]]; time The resulting timing doesn't show any significant difference between 249 and 250, and is ... 4 When calculating indefinite integrals Mathematica does not care about the convergence in a domain {x_min,x_max}. In case of definite integrals, at times it is necessary to provide information on the constants in order to obtain the proper result. Check the tutorial on definite integrals. The example with 1/(1 + a Sin[x]) is very similar to your problem. 4 Change to delta := Module[{y}, NDSolve[{y''[n] + y'[n] - y[n] == 0, y[-3] == 1, y'[-3] == 1}, y, {n, -3, 0}]] This is a possible bug. 4 Update The original approach for one ellipse (below) may be adapted for several: eq = With[{p = {x, y} - {x0, y0}}, (RotationMatrix[-t0].p).{{1/a^2, 0}, {0, 1/b^2}}.(RotationMatrix[-t0].p)] - 1; sub[pt_] := Thread[{x, y} -> pt]; dir[t0_] := {Cos[t0], Sin[t0]}; ClearAll[next, cuts]; Block[{a, b, t0, x0, y0, x1, y1, α, x, y, t, ellipses}, next = ... 3 This has been fixed in 10.0.2. The longer time now remain in the status windows. On windows 7, 64 bit SetOptions[$FrontEnd, EvaluationCompletionAction -> "ShowTiming"] Plot[{BesselJ[1, x], BesselJ[2, x]}, {x, 0, 10}, PlotPoints -> 1*^5, Filling -> {1 -> {2}}]

3

Plot on its own does not take much CPU, added some dummy computation and count of how many refreshes has happened to make it more interesting. Is this what you meant? You do not wrap Timing around the whole of Manipulate. To measure the CPU taken for each Manipulate refresh of its expression, which happens each time a control dynamic changes, just make a ...

3

Timing under 20 seconds on my computer now. Ok, your original program took about 60 seconds on my computer meaning that my computer is faster. The dramatical gain of time is due to halfing the MaxRecursion option value. The plot still shows no visible difference. I replaced Pi-Symbol by Pi for increasing readability in forum. I tested some scenarios, and ...

3

I'm going to step out on the limb and answer re: what is almost certainly the "problem" - you are repeatedly evaluating to the same result, an aspect of recursive functions, so you're creating excess work. By example of Fibonacci numbers: fib[1] = 1; fib[2] = 1; fib[n_] := fib[n - 1] + fib[n - 2]; fib[5] // Timing fib[30] // Timing (* {0., 5} ...

3

Try this: Flatten@Position[Sqrt[2 Range[512] + 1], _Integer, 1] resulting in {4, 12, 24, 40, 60, 84, 112, 144, 180, 220, 264, 312, 364, 420, 480} You'll notice that the quasi-periodic oscillations are centered at the numbers in the list above. This is due to the fact that $\sqrt{2i+1}\in\mathbb{Z}$ for those values of $i$, and presumably Integrate's ...

2

I think that ParallelMap has bad implementation of the data distribution between kernels. However if computation of f takes a long time there is some speedup (tested on Core2Duo) LaunchKernels[]; f[x_] := Nest[Sin, x, 1000]; test = N@Range[100000]; Map[f, test]; // AbsoluteTiming ParallelMap[f, test]; // AbsoluteTiming {5.813099, Null} ...

2

ClearAll[f]; f = Transpose@Table[i {##2}/#^{##2} , {i, 1, #}] &; f[3, x] (*{{3^-x x,2 3^-x x,3^(1-x) x}} *) f[3, x, y, z] (* {{3^-x x,2 3^-x x,3^(1-x) x}, {3^-y y,2 3^-y y,3^(1-y) y}, {3^-z z,2 3^-z z,3^(1-z) z}} *)

2

If your n is a very big integer and your x and y are real values, and you need realy high speed, than you should try Compile: cf = Compile[{{x, _Real, 0}, {n, _Integer, 1}}, n*x/Length[n]^x, RuntimeAttributes -> {Listable}, Parallelization -> True, CompilationTarget -> "C" ] f[n_, x_, y_] := {cf[x, Range[n]], cf[y, Range[n]]} For ...

2

Here is what I would do: ClearAll[timed]; SetAttributes[timed, HoldFirst]; timed[expr_, timeItQ_] := Module[ { timing, time, result }, Switch[ timeItQ, True, ( timing = Timing[ expr]; Sow[ First @ timing ]; (* maybe use tags like SymbolName @ expr *) result = Last@timing; ), False, result = expr ]; result ...

2

I found a certain improvement using WolframAlpha. To get the rates for the last 20 days I wrote: GetRates[c1_, c2_] := With[{rt = WolframAlpha["Exchange rate " <> c1 <> " " <> c2, {{"History", 1}, "FormattedData"}]}, Round[#, 0.01]& @ Take[Cases[rt, {DateObject[__], a_Real} :> a/100, Infinity], -20]] GetRates["USDollars", ...

1

With data your time series and t your interval, e.g., {t1,t2}, the maximum time event in your interval is given by: TimeSeriesWindow[data,t]["Path"][[-1]]

Only top voted, non community-wiki answers of a minimum length are eligible