//Written by Collins Mark.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Precognition_tester
{
class Program
{
static void Main(string[] args)
{
int NumLoops = 10000; // <== number of experiments
int SampleSize = 50; // <== number of participants in each experiment.
// This represents the paper's mean DR% threshold. Used for
// comparison of simulated mean DR% values. Should be 2.27
// for SampleSize of 100, and 4.21% for SampleSize of 50,
// to compare directly with paper's results.
double DRcomparisonThreshold = 4.21;
double memoryMean = 18.4; // <== averge number of words recalled.
double memoryStDev = 5; // <== standard deviation of number of words
// recalled (I had to guess at this one)
int ItemsPerCat = 12;
int i;
Random uniRand = new Random();
// Load the category lists.
List<string> foodList = new List<string>();
foodList.Add("HotDogs");
foodList.Add("Hamburgers");
foodList.Add("Waffles");
foodList.Add("IceCream");
foodList.Add("Coffee");
foodList.Add("Pizza");
foodList.Add("Guinness");
foodList.Add("SausageEggAndCheeseBiscuit");
foodList.Add("Toast");
foodList.Add("Salad");
foodList.Add("Taco");
foodList.Add("Steak");
List<string> animalList = new List<string>();
animalList.Add("Cat");
animalList.Add("Dog");
animalList.Add("Snake");
animalList.Add("Whale");
animalList.Add("Bee");
animalList.Add("Spider");
animalList.Add("Elephant");
animalList.Add("Mongoose");
animalList.Add("Wambat");
animalList.Add("Bonobo");
animalList.Add("Hamster");
animalList.Add("Human");
List<string> occupationsList = new List<string>();
occupationsList.Add("Engineer");
occupationsList.Add("Plumber");
occupationsList.Add("TalkShowHost");
occupationsList.Add("Doctor");
occupationsList.Add("Janitor");
occupationsList.Add("Prostitute");
occupationsList.Add("Cook");
occupationsList.Add("Theif");
occupationsList.Add("Pilot");
occupationsList.Add("Maid");
occupationsList.Add("Nanny");
occupationsList.Add("Bartender");
List<string> clothesList = new List<string>();
clothesList.Add("Shirt");
clothesList.Add("Shoes");
clothesList.Add("Jacket");
clothesList.Add("Undershorts");
clothesList.Add("Socks");
clothesList.Add("Jeans");
clothesList.Add("Wristwatch");
clothesList.Add("Cap");
clothesList.Add("Sunglasses");
clothesList.Add("Overalls");
clothesList.Add("LegWarmers");
clothesList.Add("Bra");
// Add elements to superset without clustering
List<string> superset = new List<string>();
for (i = 0; i < ItemsPerCat; i++)
{
superset.Add(foodList[i]);
superset.Add(animalList[i]);
superset.Add(occupationsList[i]);
superset.Add(clothesList[i]);
}
mainLoop(
NumLoops,
SampleSize,
DRcomparisonThreshold,
ItemsPerCat,
memoryMean,
memoryStDev,
superset,
foodList,
animalList,
occupationsList,
clothesList,
uniRand);
}
// This is the big, main loop.
static void mainLoop(
int NumLoops,
int SampleSize,
double DRcomparisonThreshold,
int ItemsPerCat,
double memoryMean,
double memoryStDev,
List<string> superset,
List<string> foodList,
List<string> animalList,
List<string> occupationsList,
List<string> clothesList,
Random uniRand)
{
// Report something to the screen,
Console.WriteLine("Simulating {0} experiments of {1} participants each", NumLoops, SampleSize);
Console.WriteLine("...Calculating...");
// Create list of meanDR of separate experiments.
List<double> meanDRlist = new List<double>();
// Initialze DR comparison counter.
int NumDRaboveThresh = 0; // Number of DR% above comparison thesh.
// Loop through main big loop
for (int mainCntr = 0; mainCntr < NumLoops; mainCntr++)
{
// create Array of participant's DR's for a given experiment.
List<double> DRarray = new List<double>();
//Loop through each participant in one experiment.
for (int participant = 0; participant < SampleSize; participant++)
{
// Reset parameters.
int P = 0; // number of practice words recalled.
int C = 0; // number of control words recalled.
double DR = 0; // weighted differential recall (DR) score.
// Create recalled set.
List<string> recalledSet = new List<string>();
createRecalledSet(
recalledSet,
superset,
memoryMean,
memoryStDev,
uniRand);
// Create random practice set.
List<string> practiceSet = new List<string>();
createPracticeSet(
practiceSet,
foodList,
animalList,
occupationsList,
clothesList,
ItemsPerCat,
uniRand);
// Compare recalled count to practice set.
foreach (string strTemp in recalledSet)
{
if (practiceSet.Contains(strTemp))
P++;
else
C++;
}
// Compute weighted differential recall (DR) score
DR = 100.0 * (P - C) * (P + C) / 576.0;
// Record DR in list.
DRarray.Add(DR);
// Report output.
//Console.WriteLine("DR%: {0}", DR);
}
// record mean DR.
double meanDR = DRarray.Average();
meanDRlist.Add(meanDR);
// Update comparison counter
if (meanDR >= DRcomparisonThreshold) NumDRaboveThresh++;
// Report Average DR.
//Console.WriteLine("Experiment {0}, Sample size: {1}, mean DR: {2}", mainCntr, SampleSize, meanDR);
}
// Finished looping.
// Calculate mean of meanDR
double finalMean = meanDRlist.Average();
// Calculate standard deviation of meanDR
double finalStDev = 0;
foreach (double dTemp in meanDRlist)
{
finalStDev += (dTemp - finalMean) * (dTemp - finalMean);
}
finalStDev = finalStDev / NumLoops;
finalStDev = Math.Sqrt(finalStDev);
// Report final results.
Console.WriteLine(" ");
Console.WriteLine("Participants per experiment: {0}", SampleSize);
Console.WriteLine("Number of separate experiments: {0}", NumLoops);
Console.WriteLine("mean of the mean DR% from all experiments: {0}",
finalMean);
Console.WriteLine("Standard deviation of the mean DR%: {0}", finalStDev);
Console.WriteLine("");
Console.WriteLine("Comparison theshold (from study): {0}", DRcomparisonThreshold);
Console.WriteLine("Total number of meanDR above comparison threshold: {0}", NumDRaboveThresh);
Console.WriteLine("% of meanDR above comparison threshold: {0}%", 100.0*((double)NumDRaboveThresh)/((double)NumLoops));
Console.ReadLine();
}
static double Gaussrand(double unirand1, double unirand2)
{
return (Math.Sqrt(-2 * Math.Log(unirand1)) * Math.Cos(2 * Math.PI * unirand2));
}
static void createRecalledSet(List<string> recalledSet, List<string> superSet, double mean, double stdev, Random unirand)
{
// Determine how many words were recalled. (random)
double unirand1 = unirand.NextDouble();
double unirand2 = unirand.NextDouble();
while (unirand1 == 0.0) unirand1 = unirand.NextDouble();
while (unirand2 == 0.0) unirand2 = unirand.NextDouble();
double gaussrand = Gaussrand(unirand1, unirand2);
gaussrand *= stdev;
gaussrand += mean;
int recalledCount = (int)gaussrand;
if (recalledCount > superSet.Count) recalledCount = superSet.Count;
// Create temporary superset and copy elements over.
List<string> tempSuperSet = new List<string>();
foreach (string strTemp in superSet)
{
tempSuperSet.Add(strTemp);
}
// Randomize temporary superset.
shuffleList(tempSuperSet, unirand);
// Copy over first recalledCount items to recalledSet.
for (int i = 0; i < recalledCount; i++)
{
recalledSet.Add(tempSuperSet[i]);
}
}
static void createPracticeSet(
List<string> practiceList,
List<string> foodList,
List<string> animalList,
List<string> occupationsList,
List<string> clothesList,
int itemsPerCat,
Random uniRand)
{
List<string> tempFoodList = new List<string>();
List<string> tempAnimalList = new List<string>();
List<string> tempOccupationsList = new List<string>();
List<string> tempClothesList = new List<string>();
// load temporary lists.
foreach (string strTemp in foodList)
tempFoodList.Add(strTemp);
foreach (string strTemp in animalList)
tempAnimalList.Add(strTemp);
foreach (string strTemp in occupationsList)
tempOccupationsList.Add(strTemp);
foreach (string strTemp in clothesList)
tempClothesList.Add(strTemp);
// Shuffle temporary lists
shuffleList(tempFoodList, uniRand);
shuffleList(tempAnimalList, uniRand);
shuffleList(tempOccupationsList, uniRand);
shuffleList(tempClothesList, uniRand);
// Load practice list
for (int i = 0; i < itemsPerCat / 2; i++)
{
practiceList.Add(tempFoodList[i]);
practiceList.Add(tempAnimalList[i]);
practiceList.Add(tempOccupationsList[i]);
practiceList.Add(tempClothesList[i]);
}
// Shuffle practice list
shuffleList(practiceList, uniRand);
}
// method to shuffle lists.
static void shuffleList(List<string> list, Random unirand)
{
List<string> shuffledList = new List<string>();
while (list.Count() > 0)
{
int indexTemp = unirand.Next(list.Count());
shuffledList.Add(list[indexTemp]);
list.RemoveAt(indexTemp);
}
foreach (string strTemp in shuffledList) list.Add(strTemp);
}
}
}