8 -GINI系数计算与 如何使用行为空间做实验
 
 
首先,我们加入保底机制。
对于每一个agent,都有一个随机的保底比例 s(每个agent的 s 不都一样,且s初始化之后不会改变)
进行交易时,双方会保留一部分的财富作为保底财富,只拿一部分出来交易。
 
 
 
GINI系数的计算
它是以下图中 S 面积的两倍。
用积分的思想,底乘高
( i/num_ag ents)* (wealth_so_far/total_wealth)
 
 
经过修改后的模型代码:
turtles-own [
money
save_rate ;; 新增了一个保底比例
] to setup clear-all
create-turtles agent_num[
setxy random-xcor random-ycor
set money (total_money / agent_num)
set save_rate random-float ;;对于每一个人来说,这个保底比例不一样 ]
reset-ticks
end to go
ask turtles[
let agsets other turtles-here
if count agsets >= [
transaction (one-of agsets)
]
forward
]
tick
end to transaction [trader]
let deltam
let money1 ([money] of trader)
let epsilon (random-float )
set deltam (epsilon - ) * money + epsilon * money1
if money + deltam >= and money1 - deltam >=
[
set money money + deltam
ask trader[
set money money1 - deltam
] ]
end to go2
ask turtles[
let agsets other turtles-here
if count agsets >= [
transaction2 (one-of agsets)
]
forward
]
tick
end to transaction2 [trader] ;; go2 按钮调用的函数
let deltam
let money0 ( ( - save_rate) * money) ;; 自己拿出来交易的财富
let money1 ( ( - ([save_rate] of trader)) * ( [money] of trader)) ;; 另外一个人拿出来交易的财富
let epsilon (random-float ) ;; 随机分割财富的系数
set deltam (epsilon - ) * money0 + epsilon * money1
if money + deltam >= and ([money] of trader) - deltam >=
[
set money money + deltam
ask trader[
set money money - deltam
] ]
end to to-update-plot
 let lst [money] of turtles
 set-histogram-num-bars
 if not empty? lst [
set-plot-x-range max lst
histogram lst
] end to save-file
file-open "ag.txt"
let wealths""
ask turtles[
set wealths (word wealths money "\r\n")
]
file-print wealths
file-close
end to lorenz-plot
clear-plot
set-current-plot-pen "equal"
plot
plot set-current-plot-pen "dominant"
plot-pen-down
plotxy
plotxy
plotxy
plot-pen-up set-current-plot-pen "lorenz"
set-plot-pen-interval / agent_num
plot let sorted-wealths sort [money] of turtles
let total-weath sum sorted-wealths
let weath-sum-so-far
let index
let gini-s ;;
repeat agent_num [
set weath-sum-so-far (weath-sum-so-far + item index sorted-wealths)
plot (weath-sum-so-far / total-weath)
set index (index + ) set gini-s gini-s + ((index / agent_num) - (weath-sum-so-far / total-weath)) / agent_num
;; ]
set-current-plot "吉尼系数"
 plot gini-s *
end to-report compute-gini ;;行为空间调用的重复函数
let sorted-wealths sort [money] of turtles
let total-weath sum sorted-wealths
let weath-sum-so-far
let index
let gini-s
repeat agent_num [
set weath-sum-so-far (weath-sum-so-far + item index sorted-wealths)
plot (weath-sum-so-far / total-weath)
set index (index + ) set gini-s gini-s + ((index / agent_num) - (weath-sum-so-far / total-weath)) / agent_num ]
set-current-plot "吉尼系数"
 report gini-s *
end
 
 
 
行为空间
用处:
  • 为了找出哪组参数控制下的 某个参数最高,我们需要重复实验,但是手动太麻烦了,我们可以用netlogo 自带的 “行为空间” 工具
新建一个行为空间
 
  • 实验名称
  • 组合起来不同的参数。
有两种方法:
1. 列出参数的取值;
示例: [ "para" 1, 3 ,8 ,9 ]
2. 指定参数的 初值、增量、终值(需要额外的中括号)。
示例: ["agent_num" [10 10 100]]
  • 对于每一组参数的实验,需要 重复多次
  • 调用报告函数 ,这个函数负责绘制每一组参数下的 gini 系数
  • 设置每一次实验的 终止时间步数
 
  • 实时更新 视图
  • 实时更新 绘图 和 监视器
  • 最大并行运算数
  • 然后会让你选择需要存放 csv 数据表格的目录
  • 取消 这两项实时更新的话,数据会跑的比之前快很多
 
 
行为空间的函数:
to-report compute-gini ;; 这个函数是需要输出的
let sorted-wealths sort [money] of turtles
let total-weath sum sorted-wealths
let weath-sum-so-far
let index
let gini-s
repeat agent_num [
set weath-sum-so-far (weath-sum-so-far + item index sorted-wealths)
plot (weath-sum-so-far / total-weath)
set index (index + ) set gini-s gini-s + ((index / agent_num) - (weath-sum-so-far / total-weath)) / agent_num ]
set-current-plot "吉尼系数"
 report gini-s *
end
 
 

最新文章

  1. HTML5 离线缓存管理库
  2. 【记忆化搜索】bzoj1652 [Usaco2006 Feb]Treats for the Cows
  3. Java 基础知识 练习
  4. DIOCP之DEMO学习顺序及达到要求
  5. SQL 汉字转换成拼音首字母 首字母查
  6. 转:strcmp函数实现及分析
  7. bug_ _ java.lang.IllegalArgumentException: pointerIndex out of range 问题的两种解决办法
  8. phpstorm自动对齐数组=>,自动加空格
  9. ARM&Linux 下驱动开发第二节
  10. ERP 及相关名词的含义
  11. Java中的不可变类
  12. eclipse打开时提示:failed to create the java virtual machine
  13. ButterKnife 牛油刀使用
  14. SQL SERVER 查询表的行数
  15. [ 严重 ] my网SQL注入
  16. leetcode3:无重复字符的最长子串
  17. tensorflow GPU版本安装及配置
  18. iOS transform解决连续多次旋转缩放,实现图片旋转缩放效果
  19. Python3基础 set 删除list中的重复项
  20. Codeforces Round #323 (Div. 2) C. GCD Table map

热门文章

  1. win10 免安装版本的MySQL的下载安装和配置
  2. robot framework 接口post请求需要加headers
  3. SpringMVC:详述拦截器
  4. selenium webdriver 模拟鼠标悬浮
  5. 八大排序算法C++代码实现
  6. webpack中devtool的配置方案[开发模式]---[线上模式]
  7. 题解 JSOI2010 找零钱的洁癖
  8. Centos7 之 MariaDB(Mysql) root密码忘记的解决办法
  9. 无线冲方案 MCU vs SoC
  10. STP 指定端口 根端口 区别和理解