Engineering for the real world

Adding Monte-Carlo analysis to iWork Numbers

Monte-Carlo analysis is not a new method of analysis. Scientists, engineers and project managers have been using it for years in many different fields to solve problems with multiple varying inputs. As a tool it has proved to be incredibly adaptable and reliable as a problem solving method. It is simple to understand, works with models of virtually any type and gives a good understanding of a problem. So the question is why is it not used more?

The first problem seems to be that it is not well understood. I think that few engineers actually have a chance to learn about methods if they don't have access to the tools to actually use them. Monte-Carlo analysis can only really be used with a computer model capable of running a Monte-Carlo simulation. It can be done manually, and for complex models sometimes it is necessary to just perform a few runs and manually compare the difference (ref. 1). This is not much different to performing a finite element analysis manually though, it can be done but there is little benefit for all the work that goes in. There are far better ways to solve the problem if manual methods are going to be adopted.

Tools are available to the engineer to undertake Monte-Carlo style risk analysis. The problem is that they are not accessible and they come with an enterprise price. Combining the the cost per seat of the software, the training cost and the learning cost, the price of getting up and running with these tools prevents engineers just having a go. It becomes a serious proposition to look at using Monte-Carlo analysis on a project and yet so often some fairly small decision could be well informed using the method. The tools should encourage the playful, explorative search for a solution as well as being capable of performing accurately, tightly defined, high quality analysis necessary when solving a significant problem.

Monte-Carlo analysis is also prone to a credibility problem. The outputs an always statistical. If you ask your programmer when the project will be complete it is much easier to deal with the answer '4 weeks time' rather than 'there is a 67% chance that the project will be complete in 4 weeks time'. Whilst the statistical answer is more informative, it can also hide many problems. If the project over-runs beyond the 4 week deadline it is easy to say there was a problem with the deterministic answer of '4 weeks time'. You can't readily say whether the statistical answer is right or not though.

For a project manager this would be a serious issue, because without some form of validation of the method being used, you can not have any confidence about using the methodology. Validation of a method only really comes with its regular use; repeated use gives both direct evidence of its performance as well as the personal, empirical understanding of how effective a method is.

To help with these problems I have started to develop a tool that will put Monte-Carlo analysis, as well as other similar tools, into the hands of any engineer. When Apple updated iWork earlier this year, Numbers finally got an Applescript dictionary. This means that automated tools can be created which hook into Numbers. The aim is to create a complete suit of automated tools that allows engineers, scientists and managers to create a model using the freeform approach of Numbers and then analyses the model using simple, intuitive but powerful tools to explore the behaviour of the model.

The project is in an early Beta phase and I would like as many people to try it as possible. People use these tools in many different ways and I need to understand how people will use it to understand how to develop it further, without impacting on the creative use of the tool.

If you are interested then please have a look at the Risk Engine page, download the application and try it out in your models.

Thankyou for your support.

References
1. One is not Enough, 2008, Rocscience Inc., [http://www.rocscience.com/library/rocnews/winter2009/One-Is-Not-Enough.pdf]


Applescript in iWork

Applescript has the potential to significantly improve many work flows. Like all programming or scripting languages it does have a learning curve, but because of the simple structures and plain language the curve is one of the easiest languages to learn. The real power of the language is its ability to interface between different programmes allowing data to be transferred from one application to another. It is also a quick way of creating similar tools to Macros that are used in Microsoft Office.

It comes as a surprise that one of Apples flagship applications, iWork, does not fully support Applescript. Neither Pages nor Numbers have applescript dictionaries associated with them, although Keynote does have a dictionary. This means that Pages and Numbers do not have publicly documented specific Applescript abilities. The good news is that this doesn't mean that Applescript can't be used with this applications.

Using the 'application' System Events you can easily control keystrokes, and occasionally buttons within most applications. To demonstrate how this is done, the following simple script is used to insert a standard reference into the active Pages document. Applescript Studio can then be used to create an interface which allows different references to be inserted all at the click of a button.

set the_text to "Hoek-Brown failure criterion - 2002 edition, 2002, E.Hoek; C. Carranza Torres; B. Corkum, Proc. NARMS-TAC Conference, Toronto, 2002, 1, 267-273, www.rocscience.com/hoek/references/H2002.pdf"
set the clipboard to the_text
tell application "System Events"
tell application "Pages" to activate
tell process "Pages" to keystroke "v" using command down
end tell


I find this script a real timesaver because I don't have to look up references every time I need to insert them into a document. All it takes is a simple click of a button.


Omnigraffle template for geological sequences

Omnigraffle is one of the best tools I've found for creating engineering diagrams. Whilst it is powerful, it is also quick and easy to use and you can copy and paste PDF's straight from Omnigraffle into either Keynote or Pages. This keeps the quality and opacity of the diagrams that have been created.

One of my favourite features of Omnigraffle is the ability to create your own templates. One of the most useful diagrams I work with is a standard borehole logging diagram. The patterns used in this diagram are from British Standard 5930 which means diagrams will be professional quality as well as quick to produce.

Download it here.

Boreholes


Review of iWork Numbers for engineers

I love Apple applications, they just seem to suit the way I work. Last months release of iWork '08 was a big step forward in the suite of applications, especially with the release of Numbers. I see this application as the start of one of the biggest changes that spreadsheet applications have ever had with the use of multiple tables on a single sheet. The effect of this will not be fully realised for a few generations of the software, but I wanted to find out how the current version of Numbers works for engineers.

To do this I recreated a standard spreadsheet I use on a regular basis for designing an unreinforced concrete section under axial load and bending. This spreadsheet allows me to check all of the basic features that I need in a spreadsheet for day to day use. It doesn't include some of the more advanced features that I use, but I know that Numbers is missing scripting and advanced plotting. As version 1.0, I don't expect these features and I know that Numbers will not be able to do everything I need it to do, but hopefully this will improve with time and newer versions.

First of all, here is the spreadsheet I created.

SectionR-BarSpacing

So how did I get on?

Well first of all the separate tables. It took me a few minutes to get used to them, but as soon as I did they are much more intuitive to use. You can concentrate totally on the table you are working on, forgetting about all the others. Once you've done the work setting up the spreadsheets you can then concentrate on how to lay them out. It really helps focus on what you are trying to achieve.

What is ultimately more significant is how the table can be modularised. To test this out I added another table to the spreadsheet which took into account reinforcement in the section. It was really easy, just add the table. What this means is that a library of standard tables can be created and just bolted together. Not only is this quick and easy, but if a standard library of verified tables is created, all you have to worry about when checking a new spreadsheet is how the table have been bolted together and not whether the contents of each and every cell is correct. The whole table concept, from the way they work to the potential ability to create a library of standard tables will make far more transparent and accurate spreadsheets.

The biggest problem I have with numbers is in the graph on my spreadsheet. The amount of control that you have over the type and format of the spreadsheet is an order of magnitude worse than it is with Excel. You can create beautiful looking graphs and charts, but the options are limited. I wanted to create a straight line between the points on my spreadsheet, but could only create a series of points. It is something that I will definitely be looking to Apple to improve in future versions.

My last gripe is a well known one, but there is a lack of support for either plugins or scripting. This is not surprising as most 1.0 applications released by Apple have limited support and things do improve with time. I hope that Applescript can be added for version 2.0, because the possibility of Applescript interfacing between Omnigraffle and Numbers is well worth waiting for. Once this happens the possibilities for quickly automatically generating standard plots and diagrams will mean there is a huge step forward in my productivity.

I think numbers is a big step forward for iWork, and a big step forward for spreadsheets. I will use it, but I have no doubt excel will be my tool of choice, but I look forward to seeing what can be achieved with version 2.0.


Seeding random numbers

Statistical modelling is part of the standard engineers tool set. The desktop computer means running scenarios with multiple inputs an easy task for all engineers. Most of these tools use random numbers to generate varying outputs. The mechanics of generating random numbers is a mathematical art to itself, but there are some key features when using statistical methods that need to be understood for effective modelling.

One of these key features is the seed. Random numbers are generated using algorithms that take an input value and generate a sequence of numbers that are apparently random. The input value is called the seed. Most programmes use the time when the first random number is generated as the seed; this then ensures a different sequence is generated each time a programme is run.

Overriding the use of the time as the seed does however have a number of benefits:

It allows scenarios to be re-run, particularly important where scenarios are used to generate the design in a safety critical situation.

It allows scenarios to be partially re-run. By using the same input parameter the scenario can be started in the same way, but using the seed, the random number sequence can be effectively re-set. This then allows a bifurcation in the model with a different outcome part way through the model.

It gives repeatability to models, a key component of any analysis that is quality audited. If you are having your analysis checked and it doesn't have built in auditing features such as date stamped reports, your checker must be capable of recreating identical results to yours. The only way of doing this in a statistical model such as UDEC is to set the deed of the model prior to the runs so that the checker can recreate exactly the same model.

So with all that in mind, here are a few ways of setting random number seeds in your models:

Excel

With Excel the easiest way to generate random numbers with a seed is to use the Data Analysis tool pack. I usually find that when I'm working with Excel and random numbers I'm having to use visual basic. For me setting the seed programmatically in Excel using Randomize statement.

Apple Numbers 1.0
Bad news here, I don't know how to set the seed in numbers. It doesn't really surprise me given the lack of scripting associated with Numbers. I remain hopeful of many improvements in the next version of Numbers and this is definitely one of them.

Cocoa
In Cocoa just use the srandom() function. There are plenty of examples out there with this in.

Applescript

In Applescript just set the seed when you first generate a random number using set firstRandom to random number from 1 to 100 with seed seedValue. I've been using this with no problems on an Application that I am currently writing in Applescript Studio. One thing to be aware of though is the some item of function. This doesn't seem to respond to seeding so well so other methods of taking a random value from a list using a directly generated random number seem to work better.