-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Reference.tex
1478 lines (1191 loc) · 60.3 KB
/
Reference.tex
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\chapter{Reference}
\section{Operations}\label{Operations}
\subsection{Special
constants}\label{Operation:euler}\label{Operation:pi}\label{Operation:zero}\label{Operation:one}
\label{Operation:inf}
Some special constants ($e=2.72\ldots$, $\pi=3.14\ldots$, 0, 1, $\infty$) can be placed on the canvas, via two methods:
\begin{itemize}
\item By clicking on the relevant icon on the Fundamental Constants
toolbar; or
\item By typing the constant name on the canvas, and pressing Enter
(or clicking OK) in the variable definition window. These names are:
\textit{Euler} for $e=2.72\ldots$; \textit{pi} for $\pi=3.14\ldots$;
and \textit{inf} for $\infty$.
\end{itemize}
\includegraphics{images/FundamentalConstants.png}
\subsection{Percent} \label{Operation:percent} The percent operator
takes one input, and multiplies its elements by 100. It is useful for
converting fractions into percentages for display purposes.
\includegraphics{images/PercentOperator.png}
The operator can be placed on the canvas in two ways:
\begin{itemize}
\item From the Fundamental Constants toolbar; or
\item By pressing the percent key anywhere on the wiring canvas.
\end{itemize}
\subsection{add +}\label{Operation:add} Add multiple numbers together.
The input ports allow multiple wires, which are all summed. If an
input port is unwired, it is equivalent to setting it to zero.
\includegraphics{images/PlusSymbol.png}
The operator can be placed on the canvas in two ways:
\begin{itemize}
\item From the Binary Operations toolbar; or
\item By pressing the plus key anywhere on the wiring canvas.
\end{itemize}
\subsection{subtract $-$}\label{Operation:subtract} Subtract two
numbers. The input ports allow multiple wires, which are summed prior
to the subtraction being carried out. If an input port is unwired, it
is equivalent to setting it to zero. Note the small `+' and `$-$'
signs on the input ports indicating which terms are added or
subtracted from the result.
\includegraphics{images/MinusKey.png}
The operator can be placed on the canvas in two ways:
\begin{itemize}
\item From the Binary Operations toolbar; or
\item By pressing the minus key anywhere on the wiring canvas, \textit{followed by pressing the Enter key, or clicking on OK in the text input window}. The reason for requiring the Enter key to be pressed---rather than immediately placing the minus operator on the keyboard, as with the plus and multiply operators---is that a user may wish to enter a negative number as a constant.
\end{itemize}
\includegraphics{images/MinusTextWindow.png}
\subsection{multiply $\times$}\label{Operation:multiply} Multiply numbers with each other. The input ports allow multiple wires, which are all multiplied together. If an input port is unwired, it is equivalent to setting it to one.
\includegraphics{images/MultiplyKey.png}
The operator can be placed on the canvas in two ways:
\begin{itemize}
\item From the Binary Operations toolbar; or
\item By pressing the multiply (asterisk: *) key anywhere on the
wiring canvas.
\end{itemize}
\subsection{divide $\div$}\label{Operation:divide} Divide a number by
another. The input ports allow multiple wires, which are multiplied
together prior to the division being carried out. If an input port is
unwired, it is equivalent to setting it to one. Note the small
`$\times$' and `$\div$' signs indicating which port refers to the
numerator and which the denominator.
\includegraphics{images/DivideKey.png}
The operator can be placed on the canvas in two ways:
\begin{itemize}
\item From the Binary Operations toolbar; or
\item By pressing the divide key (/) anywhere on the wiring canvas.
\end{itemize}
\subsection{log}\label{Operation:log} Take the logarithm of the $x$
input port, to base $b$. The base $b$ needs to be specified --- if the
natural logarithm is desired ($b=e$), use the \htmlref{ln
operator}{Operation:ln} instead.
\includegraphics{images/LogKey.png}
The operator can be placed on the canvas in two ways:
\begin{itemize}
\item From the Binary Operations toolbar; or
\item By typing the word ``log'' anywhere on the wiring canvas, and then
pressing the Enter key.
\end{itemize}
When you use the direct typing method to enter the log operations, the
text entry window pops up. This allows you to type a
variable/parameter name starting with log (like, for example,
``logical''. If you press Enter (or click on OK) with only the word log
in the window, the log operation will be placed on the canvas.
\subsection{pow $x^y$}\label{Operation:pow} Raise one number to the
power of another. The ports are labelled $x$ and $y$, referring the
the formula $x^y$.
\includegraphics{images/PowerKey.png}
The operator can be placed on the canvas in two ways:
\begin{itemize}
\item From the Binary Operations toolbar; or
\item By typing the word ``pow'' anywhere on the wiring canvas and then
pressing the Enter Key (or clicking on OK).
\end{itemize}
\subsection{lt $<$}\label{Operation:lt} Returns 0 or 1, depending on whether $x<y$ is true (1) or false (0).
\includegraphics{images/LessThanKey.png}
The operator can be placed on the canvas in two ways:
\begin{itemize}
\item From the Binary Operations toolbar; or
\item By typing the letters ``lt'' on the canvas and then pressing the Enter key.
\end{itemize}
\subsection{le $\le$}\label{Operation:le} Returns 0 or 1, depending on
whether $x\le y$ is true (1) or false (0).
\includegraphics{images/LessEqualKey.png}
The operator can be placed on the canvas in two ways:
\begin{itemize}
\item From the Binary Operations toolbar; or
\item By typing the letters ``le'' on the canvas and then pressing the
Enter key.
\end{itemize}
\subsection{eq $=$}\label{Operation:eq} Returns 0 or 1, depending on
whether $x=y$ is true (1) or false (0).
\includegraphics{images/EqualKey.png}
The operator can be placed on the canvas in two ways:
\begin{itemize}
\item From the Binary Operations toolbar; or
\item By typing the letters ``eq'' on the canvas and then pressing the
Enter key.
\end{itemize}
\subsection{min}\label{Operation:min} Returns the minimum of $x$ and $y$.
\includegraphics{images/minkey.png}
The operator can be placed on the canvas in two ways:
\begin{itemize}
\item From the Binary Operations toolbar; or
\item By typing the letters ``min'' on the canvas and then pressing
the Enter key.
\end{itemize}
\subsection{max}\label{Operation:max} Returns the maximum of $x$ and $y$.
\includegraphics{images/maxkey.png}
\subsection{and $\wedge$}\label{Operation:and_} Logical and of $x$ and $y$, where $x\le 0.5$ means false, and $x>0.5$ means true. The output is 1 or 0, depending on the result being true (1) or false (0) respectively.
\includegraphics{images/andkey.png}
The operator can be placed on the canvas in two ways:
\begin{itemize}
\item From the Binary Operations toolbar; or
\item By typing the letters ``and\_'' on the canvas and then pressing
the Enter key. Note the trailing underscore is required because
\verb+and+ is a reserved word in C++!
\end{itemize}
\subsection{or $\vee$}\label{Operation:or_} Logical or of $x$ and $y$,
where $x\le0.5$ means false, and $x>0.5$ means true. The output is 1
or 0, depending on the result being true (1) or false (0)
respectively.
\subsection{not $\neg$}\label{Operation:not_} The output is 1 or 0,
depending
on whether $x\le0.5$ is true (1) or false (0) respectively.
\subsection{time $t$}\label{Operation:time} Returns the current value
of system time.
\subsection{Gamma $\Gamma$}\label{Operation:Gamma} Returns the Gamma
function of its argument:
\begin{displaymath}
\Gamma(x)=\int_0^\infty t^{x-1}e^{-t}dt
\end{displaymath}
\subsection{Factorial !}\label{Operation:fact} Returns the factorial
of its argument:
\begin{eqnarray*}
0!&=&1\\
n! &=& \prod_{i=1}^n i\\
\end{eqnarray*}
Note:
\begin{displaymath}
n!=\Gamma(n+1)
\end{displaymath}
which is how it is implemented in Minsky.
\subsection{Polygamma $\psi^{(n)}(x)$}\label{Operation:polygamma} Returns the polygamma function
of the first argument $x$, with the order $n$ being given by the floor
of the second argument.
\begin{displaymath}
\psi^{(n)}(x)=\frac{d^{n+1}}{dx^{n+1}}\ln\Gamma(x)
\end{displaymath}
It relationship to the derivative of the Gamma function (and
factorials) is why Minsky provides this function.
\subsection{differentiate $d/dt$}\label{Operation:differentiate}
Symbolically differentiates its input with respect to system time,
producing d/dt[input]. For further explanation regarding
differentiation, see
\htmladdnormallink{this wikipedia page}{https://en.wikipedia.org/wiki/Derivative}.
\subsection{User defined
function}\label{Operation:userFunction}\label{UserFunction}
A user defined function is a functioned defined by an algebraic
expression. Support for this feature is courtesy of the wonderful
\htmladdnormallink{exprtk}{http://www.partow.net/programming/exprtk/index.html}
library developed by Arash Partow.
A user defined function has a {\em name}, {\em parameters} and an {\em
expression}. Example expressions are things like \verb'x+y' or
\verb'sin(x)'. More details of the sorts of expressions possible can
be found in the \htmlref{User Defined Functions}{ExprTk} section of
the manual.
The parameters are specified as part of the name, so a user defined
function adding x and y would be called \verb'useradd(a,y)' and the
sin example might be called \verb'mysin(x)'. Functions with up to two
arguments can be wired on the canvas. User defined functions can call
other user defined functions, so specifiying more than 2 parameters
can be a useful thing to do.
\subsection{copy}\label{Operation:copy} This just copies its input to its output,
which is redundant on wiring diagrams, but is needed for internal
purposes.
\subsection{integrate $\int dt$}\label{IntOp} Creates an integration (or stock)
variable. Editable attributes include the variable's name and its
initial value at $t=0$. The function to be integrated needs to be
connected to the top port, labelled `$f$'. The bottom port, labelled `0', can optionally be connected
to a constant, parameter or variable, which is used to specify the
initial value of the integral.
Note that the units of the integral operator are given by the units of
the input, multiplied by the \htmlref{time unit}{RungeKutta}, but the units of the {\em integral's
variable} are user specified. It is an error for these to be
mismatched, and running {\em dimensional analysis} from the
\htmlref{File menu}{File} will check for the
consistency of this. Note that the user specified units in the
integral variable can be used to dimension up the integral if the
integral variable is connected to the integral's input.
\subsection{sqrt $\surd$}\label{Operation:sqrt} This produces the square root of
the input value. For example, connecting the value of 9 with the
``sqrt'' block will produce the value of 3.
\subsection{exp}\label{Operation:exp} Connecting a variable (for example, ``time'')
to this block will produce the exponential function $e^{x}$ where x is
the input variable.
\subsection{ln}\label{Operation:ln} Produces a natural logarithm of the input, to the base of e.
This takes the equation $\log_{e} x$ where $x$ is the input.
\subsection{sin}\label{Operation:sin} Produces a sine function of the input. For example,
connecting a ``time'' block to this function, and then to a graph,
will produce a sine wave. For further explanation regarding
trigonemtric functions, see \htmladdnormallinkfoot{this wikipedia
page}{https://en.wikipedia.org/wiki/Trigonometric\_functions}.
\subsection{cos}\label{Operation:cos} Produces a cosine function of the input. For example,
connecting a ``time'' block to this function, and then to a graph,
will produce a cosine wave. For further explanation regarding
trigonemtric functions, see \htmladdnormallinkfoot{this wikipedia
page}{https://en.wikipedia.org/wiki/Trigonometric\_functions}.
\subsection{tan}\label{Operation:tan} Produces a tangent function of the input. For example,
connecting a ``time'' block to this function, and then to a graph,
will produce a tangent graph. For further explanation regarding
trigonemtric functions, see \htmladdnormallinkfoot{this wikipedia
page}{https://en.wikipedia.org/wiki/Trigonometric\_functions}.
\subsection{asin}\label{Operation:asin} Produces an arc sine function of the input,
or the inverse of the sine function. For further explanation regarding
trigonemtric functions, see \htmladdnormallinkfoot{this wikipedia
page}{https://en.wikipedia.org/wiki/Trigonometric\_functions}.
\subsection{acos}\label{Operation:acos} Produces an arc cosine function of the input,
or the inverse of the cosine function. For further explanation
regarding trigonemtric functions, see \htmladdnormallinkfoot{this
wikipedia
page}{https://en.wikipedia.org/wiki/Trigonometric\_functions}.
\subsection{atan}\label{Operation:atan} Produces an arc tangent function of the input,
or the inverse of the tangent function. For further explanation
regarding trigonemtric functions, see \htmladdnormallinkfoot{this
wikipedia
page}{https://en.wikipedia.org/wiki/Trigonometric\_functions}.
\subsection{sinh}\label{Operation:sinh} hyperbolic sine function
$\frac{e^x-e^{-x}}2$
\subsection{cosh}\label{Operation:cosh} hyperbolic cosine function
$\frac{e^x+e^{-x}}2$
\subsection{tanh}\label{Operation:tanh} hyperbolic tangent function
$\frac{e^x-e^{-x}}{e^x+e^{-x}}$
\subsection{abs $|x|$}\label{Operation:abs} absolute value function
\subsection{floor $\lfloor x\rfloor$}\label{Operation:floor} The
greatest integer less than or equal to $x$.
\subsection{frac}\label{Operation:frac} Fractional part of $x$, ie
$x-\lfloor x\rfloor$.
\section{Tensor operations}\label{tensor
operations}\index{tensor|operations}
In the following operations, an axis argument can be supplied in the
operation edit dialog. The axis name is symbolic and available in a
drop down box. If the axis name is not specified, then the operation
will be applied as though the input was flattened (unrolled to a
vector), and then the result reshaped to the original tensor.
\subsection{sum $\sum$}\label{Operation:sum} Sum along a given
axis.
\subsection{product $\prod$}\label{Operation:product} Multiply along a
given axis.
\subsection{infimum}\label{Operation:infimum} Return the least value
along a given axis.
\subsection{supremum}\label{Operation:supremum} Return the greatest value
along a given axis.
\subsection{any}\label{Operation:any} Return 1 if any value
along a given axis is nonzero, otherwise return 0 if all are zero.
\subsection{all}\label{Operation:all} Return 1 if all values
along a given axis are nonzero, otherwise return 0 if any are zero.
\subsection{infindex}\label{Operation:infIndex} Return the index of
the least value along a given axis.
\subsection{supindex}\label{Operation:supIndex} Return the index of
the greatest value along a given axis.
\subsection{running sum $\sum+$}\label{Operation:runningSum} Computes
the running sum of the input tensor along a given axis. For example,
take this rank 2 tensor:
\begin{displaymath}
\left(
\begin{array}{cccc}
1& 2& 3& 4 \\
5& 4& 3& 2 \\
8& 7& 6& 5
\end{array}
\right)
\end{displaymath}
The running sum of this tensor, along the horizontal dimension, is:
\begin{displaymath}
\left(
\begin{array}{cccc}
1& 3& 6& 10 \\
5& 9& 12& 14 \\
8& 15& 21& 26
\end{array}
\right)
\end{displaymath}
\subsection{running product $\prod+$}
\label{Operation:runningProduct} Computes the running product of the
input tensor along a given axis. For example, take this rank 2 tensor:
\begin{displaymath}
\left(
\begin{array}{cccc}
1& 2& 3& 4\\
5& 4& 3& 2\\
8& 7& 6& 5
\end{array}
\right)
\end{displaymath}
The running product of this tensor, along the horizontal dimension,
is:
\begin{displaymath}
\left(
\begin{array}{cccc}
1& 2& 6& 24\\
5& 20& 60& 120\\
8& 56& 336& 1680
\end{array}
\right)
\end{displaymath}
\subsection{difference $\Delta^-,\Delta^+$}\label{Operation:difference}\label{Operation:differencePlus}
Computes the nearest neighbour difference along a given direction. The
optional argument ($\delta$) can be used to specify the number of
neighbours to skip in computing the differences. The length of the
dimension being differenced is reduced by $\delta$ in the result.
It comes in two different forms which differ only in how the resultant
x-vector is calculated. $\Delta^-_i=x_i-x_{i-\delta}$, and
$\Delta^+_i=x_{i+\delta}-x_i$, where $i$ refers to the x-vector index.
\subsection{index}\label{Operation:index}
Returns the index within the hypecube where the input is true (ie
$>0.5$). For example, where
\begin{eqnarray*}
\iota(3,3) &=& \left(\begin{array}{ccc}
0 & 3 & 6 \\
1 & 4 & 7 \\
2 & 5 & 8 \\
\end{array}\right),\\
\mathrm{idx}(\iota(3,3)<5) &=&
\left(\begin{array}{ccc}
0 & 3 &\\
1 & 4 &\\
2 & &
\end{array}\right),\\
\end{eqnarray*}
Note that the output array has the same shape as the input, with
unused values padded with NANs (missing value).
Dimension and argument parameters are unused.
\subsection{gather}\label{Operation:gather}
Gather collects the values at index locations indexed by the second
argument. The output tensor has shape
$[i_0, \ldots i_{ir}, a_0,\ldots a_{j-1},a_{j+1},\ldots a_{ar}]$ where
$[a_0,\ldots,a_{ar}]$ is the shape of the first argument, and
$[i_0,\ldots,i_{ir}]$ is the shape of the second second (index)
argument, and $j$ is the axis along which the gather is performed.
If the index is not an integer, the gather will linearly interpolate
between the values on either side. So, for example,
$x[2.5] = 0.5 (x[2]+x[3])$.
If the index value is outside the range of the
\htmlref{x-vector}{x-vector} along the axis being gathered, then NAN is assigned
to that tensor element.
\subsection{inner product $\cdot$}\label{Operation:innerProduct}
Computes
\begin{displaymath}
z_{i_1,\ldots,i_{r_x-1},j_1,\ldots,j_{r_y-1}} =
\sum_k x_{i_1\ldots,i_{a-1},k,i_{a+1}\ldots,i_{r_x-1}}
y_{j_1,\ldots,j_{r_y-1},k},
\end{displaymath}
where $a$ is the given axis, and $r_x$ and $r_y$ are the ranks of $x$
and $y$ respectively.
\subsection{outer product $\otimes$}\label{Operation:outerProduct}
Computes
\begin{displaymath}
z_{i_1,i_2,\ldots,i_{r_x},j_1,\ldots,j_{r_y}} =
x_{i_1,,i_2,\ldots,i_{r_x}}y_{j_1,\ldots,j_{r_y}}.
\end{displaymath}
where $r_x$ and $r_y$ are the ranks of $x$ and $y$ respectively.
\subsection{Meld}\label{Operation:meld}
The meld operation merges the hypercubes of its input tensors. The
value at a given hypercube value is given by the value of the first
tensor that has a value defined at that hypercube point. So ordering of
input tensors does matter where the data is inconsistent between input
tensors.
For example, consider the following inputs and x-vectors:
\begin{enumerate}
\item \label{ex1} $\{1.0, 2.0, 3.0\}$ with x-vector $\{1,2,3\}$, and
\item \label {ex2} $\{0.0,1.5,4.0\}$ with x-vector $\{0,2,4\}$
\end{enumerate}
then the resultant output has x-vector $\{0,1,2,3,4\}$ and the values
are $\{0.0,1.0,2.0,3.0,4.0\}$ if \ref{ex1} is connected to port 1 and
\ref{ex2} connected to port 2. If they were connected the other way
around, the the values would be $\{0.0,1.0,1.5,3.0,4.0\}$.
\subsection{Merge}\label{Operation:merge}
The merge operation takes $n$ tensors, finds the union hypercube (ie
the hypercube that contains all the input tensor hypercubes) and
spreads the tensors as necessary to make them conformant. Finally,
the resultant tensor has an additional string dimensioned axis, each
element of which is one of the input tensors. This dimension should be
named using the operation edit dialog. It is an error for a hypercube
to contain more than one axis with the same name.
\subsection{Slice}\label{Operation:slice}
Slice will cut off a tensor along a given axis by the argument, as
configured in the operation edit dialog. For
example $\mathrm{slice}(\{x_1,x_2,\ldots x_n\},
3)=\{x_1,x_2,x_3\}$. If the tensor is rank one (ie a vector), it is
not necessary to specify the axis.
If the slice argument is negative, then it refers to the number of
elements from the end of that axis. For example $\mathrm{slice}(\{x_1,x_2,\ldots x_n\},
-3)=\{x_{n-3},x_{n-2},x_{n-1}\}$.
\subsection{Size}\label{Operation:size}
Size refers to the number of elements along a named dimension given by
the operation axisargument - eg a $3\times2$ rank 2 tensor with named
axes ``0'' and ``1'', size(``1'')==2.
If the axis argument is left blank, the size returns the total number
of elements present in the tensor. This may be less than the product
of axis sizes if the data is sparse.
\subsection{Shape}\label{Operation:shape}
Returns a vector of axis sizes. Coupling this operation with a
\htmlref{gather}{Operation:gather} operation
and variable would allow you interactively select axis size.
\subsection{Mean}\label{Operation:mean}
Returns the mean (or average) along a named dimension of all
elements present. If the dimension is not named, then the mean is
over all elements present in the tensor. Note that missing elements
are not counted.
\subsection{Median}\label{Operation:median}
Returns the median along a named dimension of all
elements present. If the dimension is not named, then the median is
over all elements present in the tensor.
\subsection{Standard Deviation}\label{Operation:stdDev}
Returns the standard deviation along a named dimension of all
elements present. If the dimension is not named, then the standard
deviation is over all elements present in the tensor. Note that
missing elements are not counted.
\begin{displaymath}
\sigma = \frac1{N-1}\sum_i^N (x_i-\langle x\rangle)^2
\end{displaymath}
\subsection{$k$-th moment}\label{Operation:moment}
Returns the $k$-th moment about the mean along a named dimension of
all elements present. $k$ is specified by the numerical argument of
the operation, which defaults to 1 (hence the result will be 0 in that
case). If the dimension is not named, then the $k$-th moment is over
all elements present in the tensor. Note that missing elements are not
counted.
\begin{displaymath}
\langle\Delta x^k\rangle = \frac1N\sum_i(x_i-\langle x\rangle)^k
\end{displaymath}
Also
\begin{displaymath}
\sigma^2 = \frac{N}{N-1}\langle\Delta x^2\rangle
\end{displaymath}
\subsection{Histogram}\label{Operation:histogram}
Computes the histogram along a named dimension of all
elements present. If the dimension is not named, then the histogram
is over all elements present in the tensor. The number of bins is
specified by the numeric argument to the operation.
\begin{center}
\resizebox{\textwidth}{!}{\includegraphics{images/histogram.eps}}
{\em An example usage of the histogram operation}
\end{center}
\subsection{Covariance}\label{Operation:covariance}
Computes the covariance of two tensors along named dimension. If the
inputs are of rank $N$ and $M$ respectively, the output will be a
$(N-1)\times(M-1)$ rank tensor, where the $(i,j)$ element is the
covariance of the $i$-th slice of the first argument along the named
dimension, and the $j$-th slice along the named dimension. As such, it
is conformant with the definition of {\tt cov} function in Octave, but
not with the equivalently named function in Matlab:
\begin{quote}
Compatibility Note:: Octave always treats rows of X and Y as
multivariate random variables. For two inputs, however, MATLAB
treats X and Y as two univariate distributions regardless of their
shapes, and will calculate ‘cov ([X(:), Y(:)])’ whenever the number
of elements in X and Y are equal. This will result in a 2x2
matrix. Code relying on MATLAB’s definition will need to be
changed when running in Octave.
\end{quote}
If only a single argument $x$ is supplied to the covariance, then the
result is equivalent to cov$(x,x)$, ie each slice is covaried with
each other slice.
The formula for covariance between stochastic variables $x$ and $y$
is
\begin{displaymath}
\mathrm{cov}(x,y)=\frac1{N-1}\sum_i(x_i-\langle
x\rangle)(y_i-\langle y\rangle)
\end{displaymath}
\subsection{Correlation coefficient $\rho$}\label{Operation:rho}
See
\htmlref{covariance}{Operation:covariance}
for the interpretation of tensor valued arguments. The correlation
coefficient is defined as
\begin{displaymath}
\rho(x,y)=\frac{\mathrm{cov(x,y)}}{\sigma(x)\sigma(y)}
\end{displaymath}
\section{Switch}\label{SwitchIcon}
\buttonIcon{switchIcon.eps} A switch block (also known as a case
block, or select in the Fortran world) is a way of selecting from a
range of alternatives according to the value of the input, effectively
defining a piecewise function.
\begin{center}
\resizebox{\textwidth}{!}{\includegraphics{images/switch.eps}} {\em
An example switch block with 3 cases}
\end{center}
The default switch has two cases, and can be used to implement an
if/then/else construct. However, because the two cases are 0 and 1, or
false and true, a two case switch statement will naturally appear
``upside down'' to how you might think of an if statement. In other
words, it looks like:
\parbox{\textwidth}{
{\tt if not }{\em condition} {\tt then}\\
\ldots
{\tt else}\\
\ldots }
You can add or remove cases through the context menu.
\section{Variables}\label{Variables}\label{Variable:constant}\label{VarConstant}\label{Variable:parameter}
\label{Variable:flow}\label{Variable:integral}\label{Variable:stock}
Variables represent values in a calculation, and come in a number of
varieties:
\begin{description}
\item[Constants] represent an explicit numerical value, and do not
have a name. Their graphical representation shows the actual value
of the constant.
\item[Parameters] are named constants. All instances of a given name
represent the same value, as with all other named variables, so
changing the value of one parameter, either through its edit menu,
or through a slider, will affect all the others of that
name. Parameters may be \htmlref{imported from a CSV file}{CSV
import}, which is one way of inserting a tensor into the
simulation.
\item[Flow variables] have an input port that defines how the value is
to be calculated. Only one flow variable of a given name can have
its input port connected, as they all refer to the same quantity. If
no input ports are connected, then flow variables act just like
parameters.
\item[Integral variables] represent the result of integrating its
input over time by means of the differential equation solver. The
integrand is represented by the input to an integral operator that
is attached to the integral variable.
\item[Stock variables] are the columns of Godley tables, and represent
the integral over time of the sum of the flow variables making up
the column.
\end{description}
Variables may be converted between types in the variable edit menu,
available from the context menu, subject to certain rules. For
example, a variable whose input is wired anywhere on the canvas cannot
be changed from ``flow''. Stock variables need to be defined in a
Godley table, and so on.
\subsection{Variable names}
Variable names uniquely identify variables. Multiple icons on the
canvas may have the same name --- they all refer to the same
variable. Variable names have scope, which is either local (no initial
`:'), belonging to an outer \htmlref{group}{Group} (indicated by a
leading `:' on the inner group variable, and the outer group variable
having no such leading `:'), or completely global otherwise. You may
select a variable name from a drop down list in the ``name'' combo
box, which makes for an easier way of selecting exactly which variable
you want.
\subsection{Initial conditions}\label{var:init}\index{initial
conditions}
Variable initial conditions can be defined through the ``init value''
field of the variable edit menu, or in the case of Godley table stock
variables, through the initial condition row of the Godley table. An
initial value can be a simple number, or it can be a multiple of
another named variable (or parameter). In case of symbolic
definitions, it would be possible to set up a circular reference where
the initial value of variable A is defined in terms of the initial
value of variable B, which in turn depends on the intial value of
A. Such a pathological situation is detected when the system is reset.
\subsection{Tensor valued initial
conditions}\label{tensor-init}\index{initial conditions|tensor}
There is also a simple functional language, which allows for the
generation of tensor-valued operations. These functions take the form
{\em func}$(n_1,n_2,\ldots,n_r)$ where $r$ is the desired rank, and
$n_1,n_2,$ etc are the dimensions of the tensor. Available functions
include:
\begin{tabular}{|r|l|}
\hline
name & description\\\hline
\verb+one+ & the tensor is filled with `1'\\
\verb+zero+ & the tensor is filled with `0'\\
\verb+iota+ & the arithmetic sequence $(0,1,...\prod_in_i)$\\
\verb+eye+ & diagonal elements filled with `1', offdiagonal `0'\\
\verb+rand+ & tensor filled with random numbers in the range $[0,1)$\\
\hline
\end{tabular}
\index{one}\index{zero}\index{iota}\index{eye}\index{rand}
\begin{itemize}
\item \verb+eye+ is equivalent to \verb+one+ for vectors.
\item \verb+rand+ generates different random numbers each time the
simulation is reset, and uses the clib \verb+rand()+ function.
\end{itemize}
\subsection{Sliders}
From the context menu, one can select a slider to be attached to a
variable, which is a GUI ``knob'' allowing one to control a variable's
initial value, or the value of a parameter or constant. Adjusting the
slider of an integral (or stock) variable while the system is running
actually adjusts the present value of the variable. The sliders can
also be adjusted using the keyboard arrow keys.
Slider parameters are specified in the edit menu: max, min and step
size. A relative slider means that the step size is expressed as a
fraction of max-min.
\subsection{Importing a parameter from a CSV file}\label{CSV import}
\index{CSV|import}\label{Operation:csvImport}
After creating a parameter from the ``Variable'' drop-down in the
``Insert'' menu, right-clicking the parameter and selecting the option
to ``Import CSV'', will open a dialogue box that allows you to select
a CSV file. Upon selecting the file, a dialog is opened, allowing you
to specify assorted encoding parameters.
An alternative is to click on the ImportData icon
\buttonIcon{importData.eps}, which will create a new parameter for you
to import the data into.
The dialog looks somewhat like this:
\begin{center}
\resizebox{\textwidth}{!}{\includegraphics{images/CSVimportDialog.eps}}
\end{center}
Quick instructions:
\begin{itemize}
\item Data is typically rightmost columns. Click to set the top left
cell of the data. Columns to the left will be marked as axes.
\item Select ``axis'' in the Dimension dropdown to include a column as
an axis. Column data turns blue.
\item Select ``ignore'' in the Dimension dropdown to exclude a
column. Column data turns red.
\item Select ``data'' in the Dimension dropdown to treat a column as a
data column. Column data turns black.
\item Select Type for included axis columns. Select one of three
types:
\begin{description}
\item[string] most general type, data treated as is.
\item[value] value data must be numerical and not quoted, e.g. 1, 2
\item[time] data must refer to date-time data. Format field may be
used to control interpretation of this data. Blank format assumes
data contains year/month/day/hour/minute/second separated by some
non-numerical character. If fewer than 6 numerical fields present,
smallest units are set to minimum value (0 or 1 respectively).
\end{description}
\item Click OK button.
\item Data is imported into the parameter.
\item You may now need to set units for the imported data field, which
is located at Edit $\rightarrow$ Dimensions.
\end{itemize}
In the case shown above, the system has automatically guessed that the
data is 3 dimensional, and that the first 3 columns give the axis
labels for each dimension (shown in blue), and the 4th column contains
the data. The first row has been automatically determined to be the
first row of the file --- with the dimension names are shown in green.
In this case, the automatic parsing system has worked things out
correctly, but often times it needs help from the computer user. An
example is as follows:
\begin{center}
\resizebox{\textwidth}{!}{\includegraphics{images/CSVimportDialogFail.eps}}
\end{center}
In this example, Minsky has failed to determine where the data starts,
probably because of the columns to the right of the ``Price''
columns. So the first thing to do is tell it where the data is located
by clicking on the first cell of the data region.
\begin{center}
\resizebox{\textwidth}{!}{\includegraphics{images/CSVimportDialogSelectData.eps}}
\end{center}
Note that this causes all columns to the right of ``Price paid'' to be
treated as data, which is not right since the columns to the right of
``Propieter'' are text based columns, not data. So we need to mark
those columns as either ``axis'' or ``ignore''. To do that, select
drag on the header field, which will cause those columns to be
selected, like so:
\begin{center}
\resizebox{\textwidth}{!}{\includegraphics{images/CSVimportDialogSelectedColumns.eps}}
\end{center}
Then in the dimensions row, select ``axis'', which flips the selected
columns:
\begin{center}
\resizebox{\textwidth}{!}{\includegraphics{images/CSVimportDialogSelectedAxes.eps}}
\end{center}
Now the axes index labels are rendered in blue, the axes names in
green and the data is in black. In this example, some axes have unique
values, which are not particularly useful to scan over. Other examples
might have columns that duplicate others, in effect the data is a
planar slice through the hypercube. We can remove these axes from the
data by marking the column ``ignore'' in the ``Dimension'' row. The
deselected columns are rendered in red, indicating data that is
commented out:
\begin{center}
\resizebox{\textwidth}{!}{\includegraphics{images/CSVimportDialogAxesDeselected.eps}}
\end{center}
In this example, the axis names has not been correctly
inferred. Whilst, one can manually edit the axis names in the ``Name''
line, a quick shortcut is to drag ``Header'' and drop it on
``Name''. (Note the intention is for this to be the case - currently
each column name has to be set individually).
\begin{center}
\resizebox{\textwidth}{!}{\includegraphics{images/CSVimportDialogAxesNamed.eps}}
\end{center}
The Date column is current parsed as strings, which not only will be
sorted incorrectly, but even if the data were in a YYYYMMDD format
which is sorted correctly, will not have a uniform temporal
spacing. It is therefore important to parse the Date column as
temporal data, which is achieved by changing the column type to
``time'', and specifying a format string, which follows strftime
conventions with the addition of a quarter specifier (\verb+%Q+).
\index{strftime format specifier}\label{strftime format specifier}
If your temporal data is in the form Y*M*D*H*M*S, where * signifies
any sequence of non-digit characters, and the year, month, day, hour
minutes, second fields are regular integers in that order, then it
suffices to use the blank format string \index{blank strftime
format}. If some of the fields are missing, eg minutes and seconds,
then they will be filled in with sensible defaults.
\begin{center}
\resizebox{\textwidth}{!}{\includegraphics{images/CSVimportDialogTimeFormat.eps}}
\end{center}
\begin{table}
\begin{tabular}{|c|l|}
\hline Code & Description \\\hline
\%a or \%A & The name of the day of the week according to the current locale,
in abbreviated form or the full name.\\
\%b or \%B & The month name according to the current locale, in abbreviated
form or the full name.\\
\%d & Day of month in range 01 to 31\\
\%H & Hour in range 0 to 23\\
\%I & Hour in range 1 to 12\\
\%m & Month as a decimal number (01 to 12)\\
\%M & Minute in range 00 to 59\\
\%Q & Quarter (0=1st January, 1=1st March etc)\\
\%p & AM or PM\\
\%s & Number of seconds since epoch (1st January 1970)\\
\%S & Seconds in range 00 to 59 \\
\%y & Two digit year YY\\
\%Y & Four digit year YYYY\\
\%z & numerical timezone offset\\
\%Z & Timezone name\\
\%\% & Literal \% character\\
\hline
\end{tabular}
\caption{Table of strftime codes}
\label{Strftime code}
\end{table}
Strftime formatted string consists of escape codes (with leading \%
characters). All other characters are treated as matching literally
the characters of the input. So to match a date string of the format
YYYY-MM-DD HH:MM:SS+ZZ (ISO format), use a format string
``\verb|%Y-%m-%d %H:%M:%S+%Z|''. Similarly, for quarterly data
expressed like 1972-Q1, use ``\verb+%Y-Q%Q+''. Note that only \%Y and
\%y can be mixed with \%Q (nothing else makes sense anyway).
Even in the current settings, you may still get a message ``exhausted
memory --- try reducing the rank'', or a similar message about hitting
a 20\% of physical memory threshold. In some cases, ``titles'' and
``addresses'' might be pretty much unique for each record, leading to
a large, but very sparse hypercube. If you remove those columns, then
you may encounter the ``Duplicate key'' message. In this case, we want
to aggregate over these records, which we can do by setting
``Duplicate Key Action'' to sum or maybe average for this
example. After some additional playing around with dimensions to
aggregate over, we can get the data imported.
\begin{center}
\resizebox{\textwidth}{!}{\includegraphics{images/CSVimportDialogFinal.eps}}
\end{center}
\subsection{Duplicate keys}
In a hypercube, data is indexed by a list of indices, collectively
known as a key. The indices may be strings, integers or date/time
values. If more than one value exists in the CSV file for a given key,
Minsky throws a ``Duplicate key'' exception. This exception gives you
the option of writing a report, which is basically a sorted version of
the original CSV file, with the errors listed at the beginning. You
can open this report in a spreadsheet to see if data needs to be
corrected or removed.
In the case where the data is correct, but there are still duplicate
keys, such as the example in the previous section, the duplicate keys
may be aggregated over by setting the ``Duplicate Key action'' option.
\subsection{Variable Browser}\label{VariableBrowser}
The {\em variable browser} is a popup window that shows all currently
defined variables in the system. This is a convenience toolbar that
allows one to select a variable for insertion into the design canvas,
instead of having to type the new variable's name from scratch.
At the top of the variable browser are some filter checkboxes, that
allow you filter the variables shown by variable type.
\section{Wires}
Wire represent the flow of values from one operation to the next. To
add a wire to the canvas, click on the output port of an operation or
variable (right hand side of the icon in its initial unrotated
orientation), and then drag it towards an input port (on the left hand
side of an unrotated icon). You can't connect an operator to itself
(that would be a loop, which is not allowed, unless passing through an