Git Product home page Git Product logo

fast_dft_simulation's Introduction

Fast DFT Simulation

This source code implements decision field theory (DFT) as reported in Roe, Busemeyer, and Townsend (2001).

DFT.R is the library of functions used in the model. The code is written in version 2.13.0 of the R programming language.

The library calls optimised C code for speed, and you will need to compile this code before you can use the library. DFT.c is a single-thread version of the model and DFT_parallel.c is a multi-threaded version that will use all of the CPU power available.

Compiling the C libraries

The makefile will compile DFT.c and DFT_parallel.c to give DFT.so and DFT_parallel.so. You will need the GNU Scientific Library installed. I used version 1.14 of the GNU Scientific Library. I compiled the code using gcc version 4.4.5 from the GNU Compiler Collection.

If you are using Debian or a derivative, installing the packages r-base, libgsl0-dev, gcc, and make should give everything you need. Otherwise, install the corresponding packages for your distribution. If you are using Windows, check out Cygwin, which includes the GNU Compiler Collection and GNU Scientific Library.

Put DFT.c, DFT_parallel.c, and makefile in the same direct and run the command "make". This will create DFT.so and DFT_parallel.so, which are the shared libraries used by the R code and should be in the same directory at DFT.R.

Big Three

big_three_example.R shows how to use the DFT() function from the R library to simulate the similarity, attraction, and compromise effects. See big_three_example.Rout for output.

Kahneman and Tverksky (1979) Choices

Kahneman_Tversky_1979_example.R fits DFT to the choices between prospects (gambles) listed in Kahneman and Tversky (1979). Kahneman_Tversky_1979_data.R contains the choices. The function DFT.choices() simulates a series of risky choices. DFT is applied to risky prospects using a states-of-the-world representation. For example, a choice between (A) a 25% chance of 6,000 otherwise nothing and (B) a 25% chance of 4,000 otherwise a 25% chance of 2,000 otherwise nothing is represented by

$M
     [,1] [,2] [,3] [,4] [,5] [,6]
[1,] 6000    0 6000    0 6000    0
[2,] 4000 4000 2000 2000    0    0

$W
[1] 0.0625 0.1875 0.0625 0.1875 0.1250 0.3750

Each column of M represents the outcomes in different states of the world (e.g., win A and win B, lose A and win B, ...), and each element of W gives the probability of that state. The function make.states() creates an option attribute matrix M and a attribute weighting vector W from a risky choice, and is used by DFT.choices().

A second issue is how to make the inhibition matrix S from the choice attributes. The DFT.choices() function gives two choices. Either you supply a pre-defined S matrix to apply to all choices, or you supply the parameters for an algorithm that makes a matrix for each choice based on the distance between the gambles in outcome state space, with each dimension weighted by the probability of that state. The Kahneman_Tversky_1979_example.R code contains examples of each approach.

Running the Scripts

You can run the R scripts by starting the R program and copying and pasting in the commands one-by-one or in chunks from the scripts big_three_example.R or Kahneman_Tversky_1979_example.R.

Whole .R scripts can be run from the command line in batch mode with "R CMD BATCH filename.R". The .Rout files show the result of running the .R files.

Please send bugs or comments to [email protected].

fast_dft_simulation's People

Contributors

neil-stewart avatar

Stargazers

mqg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.