-
Notifications
You must be signed in to change notification settings - Fork 4
/
mse.m
99 lines (67 loc) · 4.21 KB
/
mse.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(* ::Package:: *)
(************************************************************************)
(* This file was generated automatically by the Mathematica front end. *)
(* It contains Initialization cells from a Notebook file, which *)
(* typically will have the same name as this file except ending in *)
(* ".nb" instead of ".m". *)
(* *)
(* This file is intended to be loaded into the Mathematica kernel using *)
(* the package loading commands Get or Needs. Doing so is equivalent *)
(* to using the Evaluate Initialization Cells menu command in the front *)
(* end. *)
(* *)
(* DO NOT EDIT THIS FILE. This entire file is regenerated *)
(* automatically each time the parent Notebook file is saved in the *)
(* Mathematica front end. Any changes you make to this file will be *)
(* overwritten. *)
(************************************************************************)
(* ::Input::Initialization:: *)
$HistoryLength=10;
(* ::Input::Initialization:: *)
{$OperatingSystem,$SystemWordLength,$ProcessorCount}
(* ::Input::Initialization:: *)
(*It used in import.nb ,inequalities.nb and dataarray.nb routines that are the most memory consuming ones*)
ClearAll[MSEresources];
MSEresources::usage="Set this global variable to \"Memory\" when working with big data. The default value is set to \"Speed\"";
MSEresources="Speed";
(* ::Input::Initialization:: *)
ClearAll[objectivecounter];
objectivecounter::usage="Increments everytime the objective function is called";
objectivecounter=0;
(* ::Input::Initialization:: *)
ClearAll[notebookslist];
notebookslist::usage="List of files that are loaded when mse.m is loaded";
notebookslist={"import.nb","export.nb","payoff.nb","matching.nb","inequalities.nb","dataArray.nb","objective.nb","PSO.nb","maximize.nb","confidence.nb","modifydata.nb"};
(* ::Input::Initialization:: *)
Get[directory<>#(*,Path\[Rule]directory*)]&/@{"import.m","export.m","payoff.m","matching.m","inequalities.m","dataArray.m","objective.m","PSO.m","maximize.m","confidence.m","modifydata.m"};
(* ::Input::Initialization:: *)
clearMemory:=Module[{},
Unprotect[In,Out];
Clear[In,Out];
Protect[In,Out];
ClearSystemCache[];
Share[];
];
(* ::Input::Initialization:: *)
memoryGraph=DynamicModule[{pm={}},Dynamic@Refresh[pm=Append[pm,MemoryInUse[]];
If[Length[pm]>300,pm=Drop[pm,1]];
ListPlot[pm/1024/1024,AxesLabel->{"Time [s]","Memory [MB]"},PlotRange->{0,All},ImageSize->Large],UpdateInterval->1,TrackedSymbols:>{}]];
(* ::Input::Initialization:: *)
Clear[$globalProperties];
$globalProperties={OwnValues,DownValues,SubValues,UpValues,NValues,FormatValues,Options,DefaultValues,Attributes,Messages};
ClearAll[getDefinitions];
SetAttributes[getDefinitions,HoldAllComplete];
getDefinitions[s_Symbol]:=Flatten@Through[Map[Function[prop,Function[sym,prop[sym],HoldAll]],$globalProperties][Unevaluated[s]]];
ClearAll[symbolMemoryUsage];
symbolMemoryUsage[sname_String]:=ToExpression[sname,InputForm,Function[s,ByteCount[getDefinitions[s]],HoldAllComplete]];
ClearAll[heavySymbols];
heavySymbols[context_,sizeLim_: 10^6]:=Pick[#,UnitStep[#-sizeLim]&@Map[symbolMemoryUsage,#],1]&@Names[context<>"*"];
(* ::Input::Initialization:: *)
ClearAll[myByteCount];
myByteCount[symbolName_String]:=Replace[ToHeldExpression[symbolName],Hold[x__]:>If[MemberQ[Attributes[x],Protected|ReadProtected],Sequence@@{},{ByteCount[Through[{OwnValues,DownValues,UpValues,SubValues,DefaultValues,FormatValues,NValues}[Unevaluated@x,Sort->False]]],symbolName}]];
(* ::Input::Initialization:: *)
ClearAll[memory];
memory[n_:20]:=With[{listing=myByteCount/@Names[]},Labeled[Grid[Reverse@Take[Sort[listing],-n],Frame->True,Alignment->Left],Column[{Style["ByteCount for symbols without attributes Protected and ReadProtected in all contexts",16,FontFamily->"Times"],Style[Row@{"Total: ",Total[listing[[All,1]]]," bytes for ",Length[listing]," symbols"},Bold]},Center,1.5],Top]]
(* ::Input::Initialization:: *)
clearMemory;
{MaxMemoryUsed[],MemoryInUse[],1}