# N-Dimensional Space NetLogo Model

### Produced for the book series "Artificial Intelligence";

### Author: W. J. Teahan; Publisher: Ventus Publishing Aps, Denmark.

powered by NetLogo

view/download model file: N-Dimensional-Space.nlogo

## WHAT IS IT?

This model plots a simple set of 5-dimensional data (about 17 New Zealand All Blacks rugby players) using Cartesian co-ordinates as well as parallel co-ordinates.

## THE INTERFACE

The three buttons at the bottom left are defined as follows:

- setup : clears both plots;

- setup-left-plots : plots the data using Cartesian co-ordinates in the left hand plots;

- setup-right-plot : plots the data using parallel co-ordinates in the right hand plot.

The three sliders in the middle bottom are defined as follows:

- parallel-startx : where the leftmost vertical axis is drawn for the right hand plot;

- parallel-width : the width between vertical axes for the right hand plot;

- max-y : the maximum height from y = 0 of each vertical axis (highest y co-ordinate

is (+ max-y) and lowest y co-ordinate is (- max-y).

The five switches to the right are defined as follows when set to On:

- plot-locks : this will result in data relating to the locks being plotted;

- plot-props : this will result in data relating to the props being plotted;

- plot-wingers : this will result in data relating to the wingers being plotted;

- plot-half-backs : this will result in data relating to the half-backs being plotted.

## HOW IT WORKS

The left plots use the standard NetLogo plotting features to plot the data using the Cartesian co-ordinate system. With 5-dimensional data, a problem occurs when trying to depict the data on a 2-dimensional plot. We can add a third dimension by plotting several lines on the same graph, but that leaves the problem of how to plot the other two dimensions. One solution is to have two graphs, and plot a subset of the dimensions. In the model, the two dimension subsets are: (Weight, Year-of-debut, Position), to show trends in the weights of NZ All Blacks; and (Height, Year-of-debut, Position), to show trends in the heights of NZ All Blacks.

The right plot plots the 5-dimensional data using parallel co-ordinates. It uses patch agents to plot the parallel axes, and labelled points on the axes using the turtle breed axis-points. Each polyline that represents a 5-dimensional point is plotted by having each all-blacks turtle agent move from left to right drawing lines between the parallel axes.

## HOW TO USE IT

You can use these plots to spot trends or patterns in the data (such as locks and props being generally heavier and taller than wingers and half-backs, except for Jonah Lomu).

## WHAT IS ITS PURPOSE?

Its purpose is to show the problem with visualising n-dimensional data, and the difference between plotting using the Cartesian co-ordinate system and the parallel co-ordinate system.

## THINGS TO TRY

See what happens in the right plot when you change the value of the sliders. In some cases, the entire plot will no longer fit in the environment. In this case, you will need to alter the Settings of the environment to suit.

Try turning off the plotting of the locks, props, wingers or half-backs.

## EXTENDING THE MODEL

Try adding the capability where the user has more control over what gets plotted. For example: allow the user to decide on which 3-dimensional subset of the data is plotted in the left plots; or allow the user to decide on the order the axes are plotted in the right plot.

## RELATED MODELS

See the Missionaries and Cannibals model to see parallel co-ordinates used to plot search space states.

## CREDITS AND REFERENCES

To refer to this model in publications, please use:

Teahan, W. J. (2010). N-Dimensional Space NetLogo model.

Artificial Intelligence. Ventus Publishing Aps.

## PROCEDURES

; N-Dimensional Space model ; ; Plots a simple set of N-Dimensional data using Cartesian Co-ordinates ; as well as Parallel Co-ordinates ; Copyright 2010 William John Teahan. All Rights Reserved. breed [all-blacks all-black] all-blacks-own [name nval pos pval weight height debut] breed [axis-points axis-point] breed [axes axis] axes-own [axis-x axis-max-y axis-max-value axis-min-value axis-name] to setup ca ;; clear everything ; set up the axes on the right plot set-default-shape axis-points "line" ask patches [set pcolor white] create-axes 1 [set size 0 set axis-x parallel-startx set axis-max-y max-y set axis-max-value 16 set axis-min-value 0 set axis-name "Name"] ; axis turtle agent 0 create-axes 1 [set size 0 set axis-x parallel-startx + parallel-width set axis-max-y max-y set axis-max-value 3 set axis-min-value 0 set axis-name "Position"] ; axis turtle agent 1 create-axes 1 [set size 0 set axis-x parallel-startx + 2 * parallel-width set axis-max-y max-y set axis-max-value 140 set axis-min-value 60 set axis-name "Weight"] ; axis turtle agent 2 create-axes 1 [set size 0 set axis-x parallel-startx + 3 * parallel-width set axis-max-y max-y set axis-max-value 210 set axis-min-value 160 set axis-name "Height"] ; axis turtle agent 3 create-axes 1 [set size 0 set axis-x parallel-startx + 4 * parallel-width set axis-max-y max-y set axis-max-value 2010 set axis-min-value 1960 set axis-name "Debut"] ; axis turtle agent 4 initialise-all-blacks end to setup-parallel-axis [axis-agent] ; draws the dimension's axis let amax [axis-max-value] of turtle axis-agent let amin [axis-min-value] of turtle axis-agent let axisx [axis-x] of turtle axis-agent let amaxy [axis-max-y] of turtle axis-agent let aname [axis-name] of turtle axis-agent if (pxcor = axisx and pycor >= (- amaxy) and pycor <= amaxy) [set pcolor black] ;; draws the axis if (pxcor = axisx + 8 and pycor = (- amaxy - 8)) [set plabel aname set plabel-color black] ;; draws its label end to setup-parallel-axis-point [axis-agent pt-range pt-pos pt-label pt-color] ; draws a point on the axis let axisx [axis-x] of turtle axis-agent let amaxy [axis-max-y] of turtle axis-agent create-axis-points 1 [set color black set size 6 set heading 90 let interval (2 * amaxy) / pt-range set xcor axisx set ycor (- amaxy) + pt-pos * interval set label pt-label set label-color pt-color] end to setup-parallel-axis-points [axis-turtle pts-color pts-range pts] ; draws the axis points foreach pts [setup-parallel-axis-point axis-turtle pts-range (item 0 ?) (item 1 ?) pts-color] end to plot-parallel-points ; plots all the points (as paths) using the parallel axes ask all-blacks [ pen-up set size 0 ; don't show the turtle set pen-size 1 ; check to see if we need to plot the path first let val 0 let plot-ok true ifelse pos = "Lock" [set color (sky - nval + 12) if not plot-locks [set plot-ok false]] [ifelse pos = "Prop" [set color (green - nval + 8) if not plot-props [set plot-ok false]] [ifelse pos = "Winger" [set color (brown - nval + 4) if not plot-wingers [set plot-ok false]] [set color (magenta - nval - 1) if not plot-half-backs [set plot-ok false]]]] if plot-ok [; plot the path foreach [0 1 2 3 4] ; for each axis ; axis turtle agents 0 and 1 are nominal attributes - need to convert to a number (i.e. nval and pval) [ifelse ? = 0 [set val nval] [ifelse ? = 1 [set val pval] [ifelse ? = 2 [set val weight] [ifelse ? = 3 [set val height] [set val debut]]]] let amaxy [axis-max-y] of turtle ? let aminval [axis-min-value] of turtle ? let amaxval [axis-max-value] of turtle ? let xpos [axis-x] of turtle ? let ypos (- amaxy) + 2 * amaxy * (val - aminval) / (amaxval - aminval) setxy xpos ypos pen-down ] ] ] end to setup-right-plot ask patches [ set pcolor white ;; make background full of white patches foreach [0 1 2 3 4] [setup-parallel-axis ?] ] ; set up the axis marks setup-parallel-axis-points 0 blue 16 (list (list 16 "Chris Jack ") (list 15 "Mark Cooksley ") (list 14 "Ian Jones ") (list 13 "Andy Haden ") (list 12 "Jamie Macintosh ") (list 11 "Neemiah Tialata ") (list 10 "Kees Meeuws ") (list 9 "Richard Loe ") (list 8 "Joe Rokocoko ") (list 7 "Doug Howlett ") (list 6 "Jonah Lomu ") (list 5 "John Kirwan ") (list 4 "Grant Batty ") (list 3 "Piri Weepu ") (list 2 "Justin Marshall ") (list 1 "David Kirk ") (list 0 "Sid Going ")) setup-parallel-axis-points 1 blue 3 (list (list 3 "Locks ") (list 2 "Props ") (list 1 "Wingers ") (list 0 "Half-backs ")) setup-parallel-axis-points 2 blue 8 (list (list 8 "140 ") (list 7 "130 ") (list 6 "120 ") (list 5 "110 ") (list 4 "100 ") (list 3 "90 ") (list 2 "80 ") (list 1 "70 ") (list 0 "60 ")) setup-parallel-axis-points 3 blue 5 (list (list 5 "210 ") (list 4 "200 ") (list 3 "190 ") (list 2 "180 ") (list 1 "170 ") (list 0 "160 ")) setup-parallel-axis-points 4 blue 5 (list (list 5 "2010 ") (list 4 "2000 ") (list 3 "1990 ") (list 2 "1980 ") (list 1 "1970 ") (list 0 "1960 ")) ; then set up the line plots plot-parallel-points end to setup-left-plots setup set-current-plot "Weight of NZ All Blacks" if plot-locks [set-current-plot-pen "Locks" foreach [18 19 20 21] [plotxy [debut] of all-black ? [weight] of all-black ? ]] if plot-props [set-current-plot-pen "Props" foreach [14 15 16 17] [plotxy [debut] of all-black ? [weight] of all-black ? ]] if plot-wingers [set-current-plot-pen "Wingers" foreach [9 10 11 12 13] [plotxy [debut] of all-black ? [weight] of all-black ? ]] if plot-half-backs [set-current-plot-pen "Half-backs" foreach [5 6 7 8] [plotxy [debut] of all-black ? [weight] of all-black ? ]] set-current-plot "Height of NZ All Blacks" if plot-locks [ set-current-plot-pen "Locks" foreach [18 19 20 21] [plotxy [debut] of all-black ? [height] of all-black ? ]] if plot-props [set-current-plot-pen "Props" foreach [14 15 16 17] [plotxy [debut] of all-black ? [height] of all-black ? ]] if plot-wingers [set-current-plot-pen "Wingers" foreach [9 10 11 12 13] [plotxy [debut] of all-black ? [height] of all-black ? ]] if plot-half-backs [set-current-plot-pen "Half-backs" foreach [5 6 7 8] [plotxy [debut] of all-black ? [height] of all-black ? ]] end to initialise-all-blacks create-all-blacks 1 [set size 0 set pos "Half-back" set pval 0 set name " Sid Going" set nval 0 set weight 81 set height 170 set debut 1967] create-all-blacks 1 [set size 0 set pos "Half-back" set pval 0 set name " David Kirk" set nval 1 set weight 73 set height 173 set debut 1983] create-all-blacks 1 [set size 0 set pos "Half-back" set pval 0 set name " Justin Marshall" set nval 2 set weight 95 set height 179 set debut 1995] create-all-blacks 1 [set size 0 set pos "Half-back" set pval 0 set name " Piri Weepu" set nval 3 set weight 94 set height 178 set debut 2004] create-all-blacks 1 [set size 0 set pos "Winger" set pval 1 set name " Grant Batty" set nval 4 set weight 70 set height 165 set debut 1972] create-all-blacks 1 [set size 0 set pos "Winger" set pval 1 set name " John Kirwan" set nval 5 set weight 97 set height 191 set debut 1984] create-all-blacks 1 [set size 0 set pos "Winger" set pval 1 set name " Jonah Lomu" set nval 6 set weight 119 set height 196 set debut 1994] create-all-blacks 1 [set size 0 set pos "Winger" set pval 1 set name " Doug Howlett" set nval 7 set weight 93 set height 185 set debut 2000] create-all-blacks 1 [set size 0 set pos "Winger" set pval 1 set name " Joe Rokocoko" set nval 8 set weight 98 set height 189 set debut 2003] create-all-blacks 1 [set size 0 set pos "Prop" set pval 2 set name " Richard Loe" set nval 9 set weight 116 set height 188 set debut 1986] create-all-blacks 1 [set size 0 set pos "Prop" set pval 2 set name " Kees Meeuws" set nval 10 set weight 121 set height 183 set debut 1998] create-all-blacks 1 [set size 0 set pos "Prop" set pval 2 set name " Neemiah Tialata" set nval 11 set weight 127 set height 187 set debut 2005] create-all-blacks 1 [set size 0 set pos "Prop" set pval 2 set name " Jamie Mackintosh" set nval 12 set weight 130 set height 193 set debut 2008] create-all-blacks 1 [set size 0 set pos "Lock" set pval 3 set name " Andy Haden" set nval 13 set weight 112 set height 199 set debut 1977] create-all-blacks 1 [set size 0 set pos "Lock" set pval 3 set name " Ian Jones" set nval 14 set weight 104 set height 198 set debut 1990] create-all-blacks 1 [set size 0 set pos "Lock" set pval 3 set name " Mark Cooksley" set nval 15 set weight 125 set height 205 set debut 1992] create-all-blacks 1 [set size 0 set pos "Lock" set pval 3 set name " Chris Jack" set nval 16 set weight 115 set height 202 set debut 2001] end ; ; Copyright 2010 by William John Teahan. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from William John Teahan. ; Contact William John Teahan for appropriate licenses for redistribution for ; profit. ; ; To refer to this model in publications, please use: ; ; Teahan, W. J. (2010). N Dimensional Space NetLogo model. ; Artificial Intelligence. Ventus Publishing Aps ;