Commits

howthebodyworks  committed 07dbb87

unused agent logic

  • Participants
  • Parent commits 949a776

Comments (0)

Files changed (2)

File src/firm_arithmetic.py

-#!/usr/bin/env python
-# encoding: utf-8
-"""
-firm_arithmetic.py
-
-Created by dan mackinlay on 2011-11-18.
-Copyright (c) 2011 __MyCompanyName__. All rights reserved.
-
-The evaluator function protocol is that we pass in lists of objects to
-operate on, followed by a dictionary of experiment parameters which is called
-"params". For convenience i make this "params" guy into a Bunch.
-"""
-
-from __future__ import division
-from collections import namedtuple
-from random import randrange, random, sample
-from lib.dynamic import get_callable
-from vector_arithmetic import mean
-
-
-################################################################
-# Culture Evaluators
-def _culture_matrix(firm):
-    return [agent.culture for agent in firm.agents]
-    
-def _culture_cols(firm):
-    m = _culture_matrix(firm)
-    a = len(firm.agents)
-    
-    if not firm.agents:
-        return []
-        
-    return [
-      [m[row_i][col_i] for row_i in xrange(a)] 
-      for col_i in xrange(len(m[0]))
-    ]
-    
-def _culture_vector(firm):
-    """return a float vector of column means across agents"""
-    l = [
-      mean(col)
-      for col in _culture_cols(firm)
-    ]
-    return l
-
-def culture_mean(firm, params=None):
-    if not firm.agents:
-        return 0
-    return sum(_culture_vector(firm))/len(firm.agents)
-
-
-################################################################
-# Knowledge Evaluators
-def knowledge_sum(firm, params=None):
-    return sum([agent.knowledge for agent in firm.agents])
-
-
-################################################################
-# Productivity (Culture-Knowledge interaction) Evaluators
-def power_productivity(knowledge_factor, culture_factor, params=None):
-    return (knowledge_factor ** params.knowledge_exponent) * \
-      (culture_factor ** params.culture_exponent)
-
-
-################################################################
-# Return-on-competitiveness Evaluators
-def linear_market(competitivenesses, params=None):
-    """The size of the slice of pie you get is equal to your proportional
-    skill."""
-    total_competitiveness = sum(competitivenesses)
-    #avoid divide-by-0
-    if total_competitiveness<=0.0:
-        return [0] * len(competitivenesses)
-    return [comp/total_competitiveness for comp in competitivenesses]
-
-def quantal_response_fairy_dust(competitivenesses, params=None):
-    raise NotImplementedError

File src/stars.py

-#!/usr/bin/env python
-# encoding: utf-8
-"""
-stars.py
-
-The classes that hold the minimal state necessary for this model.
-
-Was gonna make it all named tuples, but empty members are nice.
-
-factory params protocol is as per the firm_arhitmetic module
-
-Created by dan mackinlay on 2011-09-11.
-"""
-from __future__ import division
-from collections import namedtuple
-from random import randrange, random, sample
-from vector_arithmetic import rand_bool_vector
-
-Agent = namedtuple('Agent', ['culture', 'knowledge'])
-
-class Firm(object):
-    # __slots__ = ['funds', 'agent_dict']
-    def __init__(self, funds, agents=None, params=None):
-        self.funds = funds
-        self.agent_dict = {}
-        for agent in (agents or []):
-            self.add_agent(agent)
-    
-    def add_agent(self, agent):
-        # agent dict content, for now, is nothing at all)
-        self.agent_dict[agent] = []
-    
-    def rel_agent(self, agent):
-        del(self.agent_dict[agent])
-        
-    def get_agents(self):
-        return self.agent_dict.keys()
-        
-    agents = property(get_agents)
-    
-
-def random_agents(params=None):
-    return tuple([
-       Agent(
-         culture = rand_bool_vector(
-             params.culture_length,
-             params.culture_density),
-         knowledge = random()
-       ) for i in xrange(params.num_agents)])
-
-def random_firms(params=None):
-     return tuple([
-       Firm(
-         funds = 0
-       ) for i in xrange(params.num_firms)
-     ])