Tag Info

New answers tagged

0

I finally found a better way using NthSubset function available in Combinatoria package, here is the code, << Combinatorica`; Block[{$ContextPath}, Needs["Combinatorica`"]]; ClearAll[tsmat, k, L, s, i]; L = 4; tstmat = ...


1

Thanks all for replying and sharing comments for this post, considering all comments I came up with my own solution, see the code below, ClearAll[tsmat, lst, k, i, t, L, s]; L = 20; tstmat = RandomInteger[L, {L, L}]; lst = Range@L; Do[t = L!/(k! (L - k)!); Print[{k, t}]; s = Range[k]; Do[ s = ...


0

This is a quick kludge to do what you're after. You'd probably want to properly modularize it for actual code use (i.e., not carrying around globals) or better yet incorporate the NextKSubset and your code into a Nest, NestList, Fold or FoldList as appropriate: Block[{$ContextPath}, Needs["Combinatorica`"]]; fss[lst_, siz_] := (tmp1 = stop = Take[lst, ...


1

I would suggest to take out of Do any evaluation that need to be done only once and make sure to clear variables between successive runs. Clear[L, LL, k, config] L = 50; LL = L!; Do[t = LL/(k! (L - k)!); Print[{k, t}], {k, 1, L}] As an alternative for using Do you may consider {Range @ L, Table[k! (L - k)!, {k, 1, L}] // L!/# &} // Thread ...


2

M9 under Windows 7, Intel Core i7 970. 24 GB RAM, Import without any problem. Alternatively you can read the file as a stream. str = OpenRead["z:\\temp\\omni_m_all_years.dat"] ReadList[str, Record] // StringSplit Close[str] You may add //ToExpression to get strings converted to numbers Example for 3 records (lines in text file): ReadList[str, ...


3

The large amount of memory used appears to arise from an internal memory leak from MemberQ. Hence, typical methods of clearing the kernel memory do not work as expected in this situation as long as the bug persists. See: Memory leak in pure function?


4

This appears to have been a bug that was present in version 10.0, but has been fixed in version 10.1. I can reproduce the behaviour using Mathematica version 10.0.1, but the leak does not occur in versions 7.0.1, 8.0.1, 9.0.1, or 10.1 (all on Win7 64-bit). I initially set $HistoryLength = 0 to remove saved results from consideration. I speculate that ...


6

A possible alternative for getting insight on how memory efficient two approaches are, could be by using Monitor and StepMonitor functions along with MemoryInUse. For convenience a rule for converting bytes into Kbytes, and initating the variable for monitoring memory usage: rlKB := n_ :> N[n/2^10]; mem = {MemoryInUse[]}; Illustrating the use of ...


3

It is a little known fact and probably not well documented, but since version 9 one can use just strings as variables (dependent and independent) in NDSolve, which in this case helps to solve the memory problem in a rather elegant way: mpl=1/Sqrt[6.70837*10^-39]; gsT=106.75; Sup[LamdaI_?NumericQ,GammaI_?NumericQ]:=Module[{ a,rhor,Trad,tf,s,t }, ...


0

From the comments that Szabolcs gave, Clear and ClearAll are ineffective, but using Remove works. So now the module reads: Sup[\[CapitalLambda]I_?NumericQ, \[CapitalGamma]I_?NumericQ] := Module[{a, \[Rho]r, Trad, tf, s, t, result}, tf = 10/\[CapitalGamma]I; s = NDSolve[{a'[t] ==a[t]*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[t] + ...


0

This will generate it in ~300 MB chunks. Takes about 30 seconds. You can work out what to do with the chunks. Do[ chunk = Prepend[#, i] & /@ Permutations[ DeleteCases[Range@11, i] ]; doSomethingWithChunk[chunk], {i, 11}];


3

This will write the permutations to permutations.txt in list blocks of ~50,000 each. Quiet@Block[{$ContextPath}, Needs["Combinatorica`"]] len = 11 numchunk = 1000 chunks = Partition[Clip[FindDivisions[{0, len! - 1, 1}, numchunk], {0, len! - 1}, {0,len! - 1}], 2, 1] // (# + Join[{{0, 0}}, ConstantArray[{1, 0}, Length@# ...



Top 50 recent answers are included