Skip to content

Instantly share code, notes, and snippets.

@wamoyo
Created July 30, 2020 18:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wamoyo/ad1ce8f4bd76bea8bd632e7bac73822c to your computer and use it in GitHub Desktop.
Save wamoyo/ad1ce8f4bd76bea8bd632e7bac73822c to your computer and use it in GitHub Desktop.
!(function () {
"use strict"
window.addEventListener('load', function (event) {
// What is it we're modeling?
// The end goal is to model economic phenomena. And to 'combine' those models to model higher
// level economic phenomena.
// Modeling a single economic actor and how they make decisions.
// Are people rational or is there something else going on? (Inductive reasoning).
// Perfect information? What happens when you don't have it?
// Model a basic economic interaction (whether to purchase something) with perfect rationality.
// Then model it with inductive reasoning.
// "Should you go to the bar tonight?"
// Bar is fun (+) if between (inclusive) 35 and 65 people show up.
// Bar sucks (-) if less than 35 or more than 65 show up.
var barAttendanceHistory = [40] //, 65, 35, 70, 89, 100, 99, 17, 50]
var algos = [historicalMean, lastWeek, go, nogo]
var people = []
/*
* PERSON MAKER
* @param {string} model - the final html to send
* @returns {boolean} true/false - go / no go
*/
function personMaker () {
return {
method: { status: 'active', scores: [], rating: '', algo: algos[Math.floor(Math.random() * algos.length)] },
}
}
for (var i = 0; i < 100; i += 1) {
people.push(personMaker())
}
// How many of each do we have
var nogos = people.filter( person => person.method.algo.toString().split(' ')[1] === 'nogo')
var gos = people.filter( person => person.method.algo.toString().split(' ')[1] === 'go')
var lastWeekers = people.filter( person => person.method.algo.toString().split(' ')[1] === 'lastWeek')
var historicalMeaners = people.filter( person => person.method.algo.toString().split(' ')[1] === 'historicalMean')
console.log({nogos, gos, lastWeekers, historicalMeaners})
// make 100 people
// One iteration.
function iterate (people, barAttendanceHistory) {
var trues = 0
var falses = 0
people.forEach(function (person) {
person.method.algo(barAttendanceHistory) ? trues += 1 : falses += 1
})
barAttendanceHistory.push(trues)
}
for (var j = 0; j < 200; j += 1) {
iterate(people, barAttendanceHistory)
}
console.log(barAttendanceHistory)
// run their repective algorithm(s).
// see who goes.
// generate another bar history entry.
//console.log(charlie(barAttendanceHistory))
// ALGOS (Should I go to the bar?) Go by...
// mean all history
function historicalMean (history) {
var sum = history.reduce((total, current) => total + current)
var mean = sum / history.length
return mean >= 35 && mean <= 65 && true
}
// mean of last 3 weeks
// just last week
function lastWeek (history) {
var previousWeek = history[history.length - 1]
return previousWeek >= 35 && previousWeek <= 65 && true
}
// median of last 3 weeks
// median of last 5 weeks
// the trend for all of history
// the trend for the last 5 weeks
// reverse the mean of all of history (some people are just contrarians)
// reverse the mean of last 7 weeks (some people are just contrarians)
// reverse the most recent week (some people are just contrarians)
// if less than 35 last week, definitly go this time
// if more than 65 last week, definitly go this time
// just go
function go (history) {
return true
}
// don't go
function nogo (history) {
return false
}
// the first 3 weeks mean (traditionalist)
// do what your friends are doing (for later)
// do what people like you are doing (for later)
})
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment