What's New in Analytica 4.6?
Analytica 4.6 was released on 24 May 2015. This page introduces the enhancements it adds to the previous Analytica 4.5 release.
Summary of Whats's new in Analytica 4.6
66% Faster: Analytica 4.6 introduces several significant optimizations to speed up model evaluation. Their effect depends on the specifics of each model. A comparison of nine large customer models found that Analytica 4.6 runs the models from 7% slower to 4.52 times faster than Analytica 4.5, with an average of 1.66 times faster. Equivalently, it reduces average run time by about 40%. And that average excludes the tenth model (using iteration inside a dynamic loop) which runs 94 times faster!
Buttons, OnClick and OnChange Events: You can now create Buttons in Analytica Professional and Free 101 (previously you needed Enterprise). When you click a button (or Picture) it runs the OnClick event. When you change a user input variable, such as a Choice menu or Checkbox, it runs the OnChange event. You can specify any expression, including assignments to Global variables, to OnClick or OnChange attributes. These replace the Script Attribute, which is retained for forward compatibility. Unlike Script, which uses a special Typescript language, OnClick and OnChange accept standard Analytica syntax, offer Expression assist, input/output navigation, and the other advantages of the Definition.
Associating Colors with Index values: The Color Series Dialog (right-click on a colored line, bar, or key in a Graph) lets you set colors for values in an Index, not just a particular graph. Thus, you can set all graphs using, say, the Technologies Index, to use the same colors for each Technology. You can even set it an Index that a subset of the Technologies to use the same colors.
Graphing: Some other graphing additions include Waterfall charts, Heat maps, and hyperlinks from Variable names on a graph. By default, graphs usually include zero on each axis, unless it wouldn't make sense -- e.g. it won't show the year zero when plotting results for years 2010 to 2050.
COM to integrate with other applications: Analytica Enterprise and Optimizer support COM (Component Object Model), a widely used method to access other applications, including Microsoft Excel and other Office programs. This lets you access the full API (Application Programming Interface) for these applications. You can also write your own COM objects in C++, VB, C# and other languages, to add new functions to Analytica. You can call COM asynchronously, to support concurrent computation, including ADE to parallelize Analytica computations on multiple processors or remote servers.
Multitable: This new type of table lets you combine editable and computed cells (slices) in a single table, very useful for user interfaces.
Max open windows: By default, Analytica now displays up to 8 Diagram, Object, Table, and Graph windows. When you show another, it closes the least-recent Window. This much simplifies the previous scheme that could open vast number of windows, which were overwhelming and slowed user interaction. You can modify Max open windows in the Preferences dialog.
Buttons, OnClick, and OnChange Events
- You can now create Buttons in Analytica Professional and Analytica Free 101 (previously, you needed Analytica Enterprise).
- You can specify any action as an expression in a Button's OnClick attribute. As you might guess, when you click the Button, it evaluates the expression.
- You can also add a expression in an OnChange attribute for any variable. If the variable is a user input, such as a Choice menu or Checkbox, it evaluates the OnChange expression when you change it.
- If it's not a user input, it evaluates the OnChange expression whenever the variable is evaluated.
- The expressions in OnClick and OnChange use the standard Analytica syntax used in a Definition.
- But, you can also include an assignment to a global variable in an OnClick in a Button or OnChange in a variable.
- Expression assist, input/output navigation, and other advantages of the Definition field are now available when editing the expressions in OnClick or OnChange.
- You can create an OnChange handler for any input variable, including text boxes. For edit tables, the event is run when the user finishes all cell edits, e.g., by clicking the green check. It isn't fired for each individual cell edits.
- You can use OnClick on Picture node. When a user clicks on the picture, your expression is evaluated and two variables,
click_x
andclick_y
can be used within your expression and give the coordinate of the click within your image. - If you want to run one button from another button, you can use the button's identifier by itself as an expression from within OnClick or OnChange.
- OnChange handlers can be cyclic. For example,
OnClick of Length_in_feet
can setLength_in_meters
, andOnClick of Length_in_meters
can setLength_in_feet
, allowing them to mutually synchronize each other when one is entered.
- The new OnClick and OnChange attributes replace the old Script attribute in Button, and user inputs with Checkboxes and Choice menus.
- OnClick and OnChange attributes use standard Analytica expressions, so you no longer have to learn the special Typescript syntax used by the Script attribute. They also support Expression Assist to make it easier to write the expressions.
- The Script attribute is now deprecated, meaning we discourage you from using it. But, any legacy models that use Scripts still work as they did before.
- If a button has an OnClick and Script attribute, it runs both. Or if a User input has both OnChange and Script, it runs both.
- The user interface won't show the Script attribute in an Object view or Attribute Panel unless it has an expression.
and take you to OnClick or OnChange instead, but it an object has a pre-existing Script attribute set, it will show that and take you there instead (e.g., with Ctrl+E).
- There are still a few things that can only be done through typescript. The most common are creating new objects and opening or closing user-interface windows. If you need to do any of these from a button, use the EvaluateScript function.
Graphing
Color Association with Indexes
You can now associate a custom color scheme with a particular index so that all graphs using that index in the Key have the same colors. For example, you can set the Technology index with Solar as yellow, Hydro as blue, Coal as black, etc. in all graphs with Technology as the Key index.
Right click on a point, line, or bar, or a key item in a graph, and select Change Series Color.... This gets you to the Color Series Dialog:
The new dropdown, Color to use for, lets you review and change the colors of all the Key labels in the same Change Series Color... dialog. So it's much faster to create or modify a color scheme.
After selecting the colors you want, select Apply these colors - To all graphs using Index Technology to associate this color series with the index so that all graphs using that Index as the color key use the same color sequence. You can also set the colors only for this graph, as the default for all graphs, or as a subset of another Index color sequence.
See Customization of Graph Colors for details.
Varying color in 1-D graph
You can vary color in a 1-D graph, where the independent (Y) axis and color vary together. In this case, the position along the independent axis and the color are redundant; however, this can be particularly desirable when a standardized color scheme is used.
Color varies by slice
When you have no graph key, the slicer now controls the color, so that as you toggle the slicer value, the color of the curve changes. When there are multiple slicer indexes, the first one with a color association is used. Hence, the color of the curve continues to reflect the slice being viewed.
Computed Color Role
You can now assign a Color (or Key) role to a categorical comparison variable (or to the main value if it is categorical). You may also use a continuous variable if it has fewer than 50 values, in which case it is treated as categorical. This gives you a tremendous amount of control over the use of color, creating many opportunities for creative uses of color to communicate information. It gives you complete control over the color of every point, line or bar in a graph, and the color doesn't necessarily have to correspond to an index. See below for examples of creative uses of this flexibility.
This graph shows how to assign a computed categorical value (Staff development) to the color role.
Waterfalls
A waterfall graph is a variation of a stacked bar graph, in which stacking dimension is the same as a cluster dimension, or in which the stacking dimension varies with the independent axis and there are no clusters. The result view's "smart pivoting" normally prevents you from setting these roles to be the same. So, to show a waterfall graph, select Stacked and the new Waterfall checkbox on Graph Setup...
In a Waterfall style graph, negative values are not stacked separately from positive values, as they are in a pure stacked graph. The new example model "Waterfall chart.ana" illustrates this style of graph.
Displaying a subset on a categorical axis
If you have a categorical axis with a lot of labels, you can display a subset by specifying the first and last to display from pulldown menus for Minimum and Maximum.
Include Zero
It is usually misleading not to include zero on the Y-axis. Compare these two graphs of the number of burglaries in San José, CA. The one on the left doesn't include zero, and it seems to exaggerate the change over time.
Analytica now usually defaults to include zero -- except, when it would not make sense -- for example if the Y axis is years from 2010 to 2040, it makes little sense to include the year zero.
Hyperlinks on graphs
Axis and key labels on a graph can now be hyperlinks to objects in the model. This happens automatically when the element is a handle. The corresponding label displays in blue.
Other graphing enhancements
- A graph doesn't display a data point whose value is Null or NaN, or, for a stacked graph, zero. It omits any item from the Key if none of its data points are displayed.
- Each item in the Graph Setup... dialog included a tooltip description.
- The filled area looks cleaner, when you select Area fill on the Chart type'.
Influence Diagrams
- When you press just to the left (or right) of a node, it pops up a menu of the nodes input (output) variables. Now this list also shows aliases and user inputs (user outputs) for the variable with the name of the module that contains them. You can select one one of these from the popup menu to jump to its diagram.
- Now you can Undo (ctrl-Z) when you Delete (Delete) a node or set of nodes.
Application Integration
- Analytica Enterprise and Optimizer users can now instantiate COM objects (Component Object Model) from external applications and call the methods on these objects. See COM Integration.
- You can use the workbook object returned from SpreadsheetOpen as a COM object, giving you full access to the entire Excel API An example here.
- You can call COM objects asynchronously, enabling concurrent computation.
- COM calls array-abstract automatically.
- You can use this mechanism to instantiate and call ADE instances.
- You can instantiate on remote computers and call their methods via DCOM. You may need to adjust Windows security settings appropriately to enable this.
- Many .NET libraries can be used via COM.
- Many applications support COM interfaces, and hence, this enables a very wide variety of opportunities to integrate with and make use of other application.
- Using C++, VB, C#, and a host of other programming languages, you can write your own COM objects. COM calls have low overhead, so it is possible to implement low-level functions efficiently in C to be used by your model.
- The Excel Spreadsheet functions for reading from a spreadsheet and writing to a spreadsheet can now be used from Analytica Professional and Free 101 editions. Formerly these required Analytica Enterprise. These include SpreadsheetOpen, SpreadsheetRange, SpreadsheetSetRange, etc.
Evaluation Engine and Built-in Functions
- A new build-in function,
Try(expr, catch:expr2)
, can be used to catch evaluation errors without Analytica stopping and reporting the error to the user. The new function Rethrow can be used from the catch expression to re-issue the error.
- The maximum number of dimensions for a single array has been increased in the 64-bit edition to 24. In Analytica 32-bit, the limit has not been changed, it is still 15. Keep in mind, however, that you will usually hit memory limits before this many dimensions.
- Speed-up using Evaluating Context: The evaluation engine can now detect several cases in which portions of a computation will not impact the final result, and in these cases will avoid computing the iterations that are used. In some cases, this can result in dramatically faster evaluation. For example, suppose x was a very large array, and you had this expression:
- by recognizing the all
I≠1
slices don't impact the final result, it can avoid evaluating the expense Sin and CumNormal for all slices other thanI=10
, as if you had instead written - This comes into play often when there are two nestings of array abstraction active, but where only some variables had been restricted. One very important example of this in when there are multiple local variable declarations with explicit dimensionality declared, such as:
- If it is the case that
F1()
is indexed byI,K
, then everything in the scope of a needs to be iterated overK
. IfF2()
is also indexed byK
, then a nested iteration results. This new enhancement is now able to coordinate these, so that a single iteration overK
results. In this example, this improves evaluation time from O(n^2) to O(n). - If you have intentional side-effects in your code, such as message boxes displayed to the user, data written to a file, or changes to local variables, this enhancement might alter your computation, since it may cause the code to go through fewer iterations. There are two ways to turn off this enhancement. You can turn it off globally by setting the EnableEvalContextUse system variable to 0. Or you can disable it within a single expression by using
SetEvaluationFlag("EvaluationContext",0,expression)
. - The speed-up optimization is not applied to explicit
FOR
loops. So inFor i1:=I Do For i2:=I Do F(i1,y2)
, F is called for every pair of I, n2 times, whereas inVar i1[]:=I Do Var i2[]:=I Do F(i1,i2)
, F is called only n times -- F(1,1), F(2,2), etc.
The final result of each of these would be the same in this example.
- Speed-up of Iterate nested in Dynamic. When an Iterate appears in a Dynamic loop, and implements a convergence algorithm than depends only on the current or recent time steps, evaluation in this case is now dramatically faster.
- A new parameter, «method» has been added to Dispatch. It provides alternatives for increment-constrained allocations when increments don't meet demand precisely.
- A new function, AddIndex, has been added. This returns an array having one or more additional indexes that you specify, with the array being constant over the new indexes. In normal situations, this is entirely unnecessary and even undesirable -- the Analytica philosophy is that an array only needs an index if its value vary over that index, which clearly is not the case for the result here. You never need to add an index prior to an array operation in Analytica expressions. There are, however, some esoteric cases where you do need to do this, often involving meta-inference.
- A new parameter, «extrapolationMethod», has been added to LinearInterp. With it you can specify that values are extrapolated using the nearest point (as in pre-4.6 releases), by extending the slope of the first or last segment, or by never extrapolating and returning null for values outside the data range. An important use is in piecewise-linear Optimization problems when you know that the solution does not appear in the extrapolated region. This extra info can lead to faster solves and greater numeric stability in the integer LP.
- When Choice(Self,...) is evaluated, where the options are in the domain of the variable, the behavior has been changed so that the options are never evaluated, even if the «eval» parameter is specified to true. This is only relevant to the case where your domain contains handles to variables. This change avoids a domain-inconsistency that results otherwise.
- A new function, OpenURL, has been added. It opens the indicated web page in your browser.
MultiTables
A MultiTable allows you to combine several edit tables (ideally with the same dimensionality) into a single view, and to also display computed columns in the same table. Edits to the edit-table columns change the source edit tables. Computed columns update immediately and cannot be edited. MultiTables and SubTables can be arbitrarily nested -- i.e., a SubTable can be source for a MultiTable, and a MultiTable can be a source for a SubTable.
A new control shows up in edit mode when viewing a MultiTable, which allows you to toggle between the "meta view" (the definitions of each "column") or the "cell view" (the actual data). Use the meta view to configure your multi-table, and use the cell view once it is set up. Keep in mind that in meta view, A
means that A's definition should show, whereas Mid(A)
means that A's computed result should be displayed.
User Interface
Start up
The very first time you launch Analytica, it will inform you that if you are new to Analytica, the Tutorial is the best place to start.
Elimination of buttons
When your variable is defined as call to Sequence or to a distribution function, it now shows the textual definition rather than those annoying buttons that would appear previously. Buttons in the definition field are now reserved for edit tables.
Links to the Wiki
- You can rapidly see a description of a function by selecting its identifier in a Definition and pressing Ctrl+H (or selecting Find (Jump to) selection from the right-click context menu).
- Built-in functions have a link to their Wiki description in blue, as above.
- You can also jump straight to the wiki description for a built in function by selecting its identifier, right-click to see the context menu. and selecting "Wiki help on «name of function»".
- You can add a similar hyperlink for your own User-Defined Functions or Variable: Set the
Att_WikiHelpURL
attribute of the object to a URL. Then the link will appear in its object window, and in the right-mouse context menu when you select its identifier.
Misc
- When you have some text selected when you press Ctrl+F, the select text is inserted into the text field of the Find dialog.
- You can adjust the column side of a table by double-clicking on the right edge of the column header cell.
- A new folder for the build-in functions was introduced, Application Integration. Functions that involve interactions with other applications (other than the Database functions) are now in this folder, including the new COM Integration functions, RunConsoleProcess and the Spreadsheet functions.
- The Shift+Ctrl+E shortcut opens the textual definition. Sometimes useful when Ctrl+E opens an edit table window.
Window Management
- Max open windows is a new option on the Preference Dialog to control how many Analytica windows (of any kind) you can have open at once. If you are at this limit when opening a new window, it automatically closes the least-recently-used window. This much simplifies the previous somewhat confusing method, which often resulted in a vast number of windows being open which slowed down user interaction. This is a personal preference saved for you as a user, not stored with the model. Most users can simply ignore this now, and simply accept the default of 8 windows.
Example Models
Some new example models have been included:
- Enterprise Model: (Business examples). A financial model of a hypothetical company than sells widgets. Forecasts sales and staffing needs into the future. Long used in Lonnie's introduction to Analytica webinar.
- Waterfall chart (Business examples). A very basic financial example, illustrating a type of graph called a Waterfall Chart.
- Vacation plan with PWL tax (Optimization Models): Illustrates the use of a piecewise-linear constraint in a linear program. Here, income tax rates are staged by bracket (as they are in the US tax code).
Easier Manual License Activation
- Normally, when you install or upgrade Analytica and enter a key into the license dialog, it activates automatically. But, if your computer is not connected to the internet (or a firewall prevents it connecting to the activation server at AnalyticaOnline.com), you have to activate Analytica manually. We have simplified manual activation to make it more robust, to reduce the chance of mistakes, and to identify any problems that still occur.
- As before, use automatic activation if you can -- because it's much easier.
To activate manually an individual license in Analytica 4.6,
- Double click the installer and go through installation screens (as before), but with activating.
- Fill in the Manual Activation Form on the Lumina website and click "Submit".
- When you receive the email with activation information, save the attached license file to a known directory.
- Launch Analytica and open the Analytica Licensing Information dialog (Help→Update License...).
- Select »Add license from *.lic file from the License ID dropdown menu and select the license file from the directory into which you just saved it.
- You can now copy (ctrl-C) the Host id and User id from the bottom of this Analytica Licensing Information dialog, for example to paste it into the online Activation form.
Analytica Decision Engine (ADE)
- A new interface has been added, IAdeUICallbacks which allows you to implement callbacks that are called when Analytica functions requiring user input are evaluated. For Example: MsgBox(), ShowProgressBar(), ShowPdfFile(), OpenURL() More...
- A new property has been added, CATable::GraphWithStoredPivot. When you set this to true, CATable::GraphToStream and CATable::GraphToFile use the pivots and slicer state stored with the model to produce the same graph that appears in the desktop Analytica window. When this is set to false, then it is up to your code to use CATable::Subscript or CATable::Slice to select out the slice being graphed, and CATable::SetIndexOrder to set the table pivot prior to graphing.
- A new Flags property has been added to CAEngine. It is a bit field. Currently only one bit is used:
- 1 = Allow hiding and unhiding of definitions. This is set to off by default, so that definitions that were hidden from Analytica Enterprise remains hidden.
Backward Compatibility with Analytica 4.5
We always strive to make each release of Analytica backward compatible, so that models created with an earlier Analytica release will still work fine with the new release. But there is a remote chance that a change will impact an existing model. For example, if your model took advantage of a "bug" that is fixed in the new release. The situations that could possibly affect backward compatibility are quite rare, but we list them for completeness:
Structured Optimization Library
If your model embeds the Structured Optimization Library (such as Use_opt_decisions() and Set_decisions_to_opt(), you should replace it with the new version of the library in 4.6 to make sure you get correct values. It fixes a bug that results in a gross inefficiency for optimization formulations with extrinsic indexes. The bug interacts with context speedup causing extrinsic indexes to be dropped by the assignment. We also recommend you use the new version even if you continue to use Analytica 4.5.
Evaluation Context Speedup
This speed-up optimization can reduce the number of iterations that could rarely alter some results in these situations:
- Functions that generate random numbers appear within affected expressions. With fewer iterations, the random seed may be altered, so that the exact values appearing in Monte Carlo samples might change compared to Analytica 4.5.
- If a local variable with a scope broader that an iteration point is updated inside the iteration, the result of the computation might change. For example:
Var count := 0; Index I := 1..3 Do ( Var i1[] := I; Var i2[] := i1^2 + I; count:=count + i2; ); count
- In Analytica 4.6 this returns 2 + 6 + 12 = 20, whereas in Analytica 4.5 it would return 60 due to the double iteration. This difference occurs because of the side-effect in which
count
is updated within the body of the second Var, but has a scope outside of this iteration.
- When there is a side-effect of a different nature, which occurs in an expression whose result for certain iteration values is not used. These side-effects might be the display of a MsgBox, writing to a file, interacting with an external application, or implementing a time delay through vacuous iteration.
If your legacy model is impacted by any of these conditions, you may disable this optimization for the whole model or for a particular expression. To disable it your whole model: 1. Press F12 to open the Typescript window. 2. Type: EnableEvalContextUse:0 Disabling globally is appropriate when the random seed is an issue for you; however, by doing so, you don't benefit from the speed-up in model evaluation time that might result from the optimization.
If you isolate a particular expression affected by this issue, you can disable the optimization just in that expression by nesting it inside SetEvaluationFlag:
SetEvaluationFlag("evaluationContext",0, Var count := 0; Index I := 1..3 Do ( Var i1[] := I; Var i2[] := i1^2 + I; count:=count + i2; ); count )
Cascading comparisons
The change to how cascading comparisons are interpreted has the potential to "break" an expression. The situation where this occurs is extremely rare, and very unlikely to appear in your model, but it is nonetheless theoretically possible that an existing model might be impacted, and hence, it is listed here.
Suppose you wanted to test whether x is non-negative and y negative. The intuitive was of doing this would be:
which presents no problem. But an arcane way of testing this same condition might be
In earlier releases this would parse as (x<0) < (y<0)
. This arcane way of expressing this would be impacted by the new cascading comparisons, because it would now be parsed as x<0 and 0 < (y<0)
, which is not the same.
Graph colors
In some Tornado charts, the colors for some of the bars may change when viewed in 4.6 compared to 4.5. Suppose you have an key index with items ['Low','Baseline','High']
, and you set the bar origin to 'Baseline'
. Analytica 4.5 uses the 1st color for 'Low'
and the second color for 'High'
, whereas Analytica 4.6 uses the first color for 'Low'
and the third color for 'High'
. So the color used for 'High'
will be different.
Hiding or unhiding definitions in ADE
This note only impacts users of ADE.
ADE has been changed to issue an error by default if your attempt to change the Att__cloakDefn attribute of an object, whereas in 4.5 this was allowed. Setting this attribute to 1 hides definitions, to 0 unhides definitions. By default, if your code that calls ADE tries to change this attribute (e.g., using CAObject::SetAttribute or via typescript CAEngine::SendCommand, it will fail with an error. This is so that your applications that use models created in Analytica Enterprise that have hid certain definitions continue to hide these definitions from end users as intended. If you are creating code that allows people to build or configure models and want to allow hiding or unhiding, then set the 1 bit of CAEngine::Flags to allow it.
Enable comment auto-refresher