Tag Info

Hot answers tagged

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

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

I think this may be a duplicate of: How to avoid unpacking from Language`ExtendedFullDefinition 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 ...


8

The default SumCompileLength is 250. You can increase this number for example to 500 using: SetSystemOptions["CompileOptions" -> {"SumCompileLength" -> 500}]


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 = ...


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], ...


5

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 ...


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

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


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} ...


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 ...


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]]


1

How about Table[First@Timing[N[Sum[(MatrixPower[A, j] t^j)/j!, {j, 0, i}]]], {i, 0, 200}] ListLinePlot[%] If you want the iteration number side by side, just change the body of the Table to {i, First@...}.


1

I am reversing the order of this answer, putting new observations first, as I think that is most helpful. I suddenly realized that you are "prepending" a vector V that does not match the row dimension of the packed array M. This means that unpacking will occur, and it seems to be full unpacking. If instead we append a vector of length 1000 we will not ...


1

perhaps something like this: function[n_, x_, y_] := ({table1, table2} = Table[i {x/n^x, y/n^y}, {i, n}] // Transpose;) But note your example does not need Table at all: function[n_, x_, y_] := ({table1, table2} = {x/n^x, y/n^y} # & /@ Range[n] // Transpose;) Of course assigning to global variables inside a ...


1

If you other tool can wait for the existence of a file, you can use a "lock" file say "C:\Temp\lock.txt" 1) Before Mathematica writes your data, use DeleteFile["C:\\Temp\\lock.txt"] 2) Do all the operations you need. 3) Write one byte to the lock file: 1>>"C:\\Temp\\lock.txt". In the meantime, your other tool is waiting for lock file to appear. A ...


1

A fairly simple way to add a clock to your Manipulate is to use SessionTime. Manipulate[ f[x_] := x^3; Column[{ Graphics[{Thickness[0.01], Line[{{0, 0}, {n, f[n]}}]}, PlotRange -> 1], Row[{"Elapsed time (sec): ", SessionTime[] - start}]}, Frame -> All], {n, -1, 1}, {{start, SessionTime[]}, None}]


1

Yes! You have passed the same function f into a pure function so it is evaluated every time you calculate g. Specially you define f by = so Mathematica calculates it once and then re-use it in Do loop. For the sake of demonstration if I define f by :=: f1 := Interpolation[Table[{i, i^2}, {i, -5, 5}]]; f2 = Interpolation[Table[{i, i^2}, {i, -5, 5}]]; ...



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