+ All Categories
Home > Documents > Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can...

Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can...

Date post: 25-Aug-2021
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
65
Collecting & Outputting Data from AnyLogic Nathaniel Osgood March 15, 2011
Transcript
Page 1: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Collecting & Outputting Data from AnyLogic

Nathaniel Osgood

March 15, 2011

Page 2: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Recording of Results

• A frequent modeler need is to record some components of model state over time – State variables (e.g. stocks) – States of agents – Summaries of model state – We informally term this a “trajectory file”

• Trajectory recording is only supported by AnyLogic Professional

• AnyLogic does allow for – Definition of DataSets that record recent values of

parameters – Statistics summarizing model state – Reporting on values of data sets as a graph or table

Page 3: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Techniques for Outputting Data

• Ad-Hoc Exports from variables

• Manual copies from visible datasets

• Export to files

• Writing to console

• Export to databases

• [AnyLogic Professional] Dataset archiving

• Capturing images of graphs

Page 4: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Cross-Method Output Tips

• A convenient mechanism is to periodically output data using events (e.g. every time unit)

• Beyond output, be sure to save information on context of run

– Model version (Use unique id that increment whenever change model)

– Parameter assumptions

– Intention

• Think carefully about whether want to save away intermediate data

Page 5: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Hands on Model Use Ahead

Load Sample Model: SIR Agent Based Calibration

(Via “Sample Models” under “Help” Menu)

Page 6: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Techniques for Collecting & Outputting Data

• Ad-Hoc Exports from variables

• Pre-Prepared methods – Statistics

– Charts

– Manual copies from visible datasets

– Export to files

– Writing to console

– Export to databases

– [AnyLogic Professional] Dataset archiving

– Capturing images of graphs

Page 7: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Add an Experiment

Page 8: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Add an Experiment

Page 9: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Save the Resulting Model (To Avoid Overwriting the Other Model)

Page 10: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Run the Experiment (To Verify Functionality)

Page 11: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Click on Variable “nInfectious”

Page 12: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Graph of Variable

Page 13: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Right-Click to Copy the Numeric Data

Page 14: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Pasting Into Excel

Page 15: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Press Red “Stop” Button to Terminate Execution

Page 16: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Techniques for Collecting & Outputting Data

• Ad-Hoc Exports from variables

• Pre-Prepared methods – Statistics

– Charts

– Manual copies from visible datasets

– Export to files

– Writing to console

– Export to databases

– [AnyLogic Professional] Dataset archiving

– Capturing images of graphs

Page 17: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Statistics & Charts • A population of agents can have associated statistics

that calculate values

• Examples of things that can be computed with using AnyLogic’s statistics – Count of agents in the population for which certain

condition (“predicate”) evaluates to true

– Function of the values of some expression over the population • Maximum value

• Minimum value

• Average value

• Sum (total) over population

– Statistics can be defined as properties of the population

Page 18: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Select “People”, and Choose “Statistics”

Page 19: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Also, Expand “Statechart” Under “Person”

Page 20: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Click “Add Statistics”

Page 21: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Fill in the “Condition” (Predicate) on Person

Page 22: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Continue Typing

Page 23: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Full Expression

Expression: item.statechart.isStateActive(Person.Susceptible)

Page 24: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Example Statistics

The population in which the statistics are to be calculated

What statistics we wish to calculate

Page 25: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Name the Statistic “countSusceptible”

Page 26: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Run the Model, and Click on “people” The Statistic should be Visible

Close the Model after you’re done

Page 27: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Drag a “Time Plot” from the Palette to the “Main” Canvas

Page 28: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Enlarge the Chart

Page 29: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Click “Add Data Item”

Page 30: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Put in “people.” and Press Ctrl-Space

Page 31: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Choose “Count Susceptible”

Page 32: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Now Run the Model

Notice that this only goes back to time 100

Page 33: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Stop the Simulation, and Click on the Plot. Change Time Window & Display Size to 200

Page 34: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

This Captures the Full Time Range

Page 35: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Techniques for Collecting & Outputting Data

• Ad-Hoc Exports from variables

• Pre-Prepared methods – Statistics

– Charts

– Manual copies from visible datasets

– Export to files

– Writing to console

– Export to databases

– [AnyLogic Professional] Dataset archiving

– Capturing images of graphs

Page 36: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Datasets

• Datasets store recent values of some quantities from the model

• Datasets can be exported easily using custom code

– This can simply call the dataset’s to string method

Page 37: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Output: Datasets

Page 38: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Run the Experiment & Click on “Infectious DS”

Page 39: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Click on “InfectiousDS” to See Data in Dataset

Page 40: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Right Click and Select “Copy”

Page 41: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Call Up Excel and Paste into It

Page 42: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Dataset Properties

Page 43: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Chart Use of Datasets

Page 44: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Ad-hoc Export

Page 45: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Begins as a Small Chart

Page 46: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Copying Data

Page 47: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Data Exported from Ad-Hoc Chart

Page 48: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Techniques for Outputting Data

• Ad-Hoc Exports from variables

• Manual copies from visible datasets

• Capturing images of graphs

• Export to files

• Writing to console

• [AnyLogic Professional] Dataset archiving

• Export to databases

Page 49: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Manual Output from Datasets

Page 50: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Right Clicking Gives Context Menu

Page 51: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Copied Data Can be Pasted into Excel

Page 52: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Declaratively Specifying Datasets

Page 53: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Supported Dataset Types

• Simple

– holds values only -- no timestamps

• Timed

– holds values and timestamps

• Phase

– holds pairs of values but no timesamps

• Histogram

– can define bins for data set

– data set will record # falling in each bin

Page 54: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Techniques for Outputting Data

• Ad-Hoc Exports from variables

• Manual copies from visible datasets

• Capturing images of graphs

• Export to files

• Writing to console

• [AnyLogic Professional] Dataset archiving

• Export to databases

Page 55: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Output to Console

• Pros – Easy to program

• ActiveObject.traceln(Stringstr) outputs string to console

• System.out.println(Stringstr)

– Readily visible

– Copy & Paste to another document

• Cons – May be mixed with other output (easy to miss other

output)

– Limited length

– Depends on memory to copy

Page 56: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Techniques for Outputting Data

• Ad-Hoc Exports from variables

• Manual copies from visible datasets

• Capturing images of graphs

• Export to files

• Writing to console

• [AnyLogic Professional] Dataset archiving

• Export to databases

Page 57: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Data Output to File

• Pros

– Simple to perform

– Relatively easy to import into e.g. Excel, R, etc.

– Files can be readily archived

• Cons

– Awkward to draw combine from multiple files

– Denormalization: Requires either

• Duplication of scenario-wide information (e.g. parameter values) on each row

• Separate header section & later section

Page 58: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Example code to Export Dataset to File

FileOutputStream fos = new FileOutputStream(“Filename”);

PrintStream p = new PrintStream(fos);

p.println(datasetName.toString()); // outputs tab delimited values

Page 59: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Techniques for Outputting Data

• Ad-Hoc Exports from variables

• Manual copies from visible datasets

• Capturing images of graphs

• Export to files

• Writing to console

• [AnyLogic Professional] Dataset archiving

• Export to databases

Page 60: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Output to Databases: Tradeoffs • Pros

– More flexible than string output to file

– Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.)

– Can easily clean up

– For larger databases

• Transactional (either writes entirely or not at all)

• Can query from remote machines

• Cons

– More programming

– Need to set up a database

Page 61: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Output to Databases: Steps

• One Time:

– Install database on computer

– Add reference to database libraries

• Each time during simulation

– Open database connection at start of model

– Optionally, “insert” model version & parameter information into the database

– Periodically during simulation

• “insert” values into databases

– At end of model execution, close database connection

Page 62: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Database Dependencies (MySQL database)

Page 63: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Example Simple Database Class

Page 64: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Setup for Database Class

Page 65: Collecting & Outputting Data from AnyLogic...–More flexible than string output to file –Can query from diverse tools (e.g. excel, R, SPSS, SAS, etc.) –Can easily clean up –For

Example Database Output Code A database query language (SQL) statement

Requesting that the database class execute the SQL statement

Checking to make sure that the insert worked properly


Recommended