Market model
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
(a general understanding of what the model is trying to show or explain)
HOW IT WORKS
(what rules the agents use to create the overall behavior of the model)
HOW TO USE IT
(how to use the model, including a description of each of the items in the Interface tab)
THINGS TO NOTICE
(suggested things for the user to notice while running the model)
THINGS TO TRY
(suggested things for the user to try to do (move sliders, switches, etc.) with the model)
EXTENDING THE MODEL
(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)
NETLOGO FEATURES
(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)
RELATED MODELS
(models in the NetLogo Models Library and elsewhere which are of related interest)
CREDITS AND REFERENCES
(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)
Comments and Questions
globals [ first_opinion
second_opinion
first_palette
second_palette
number-of-turtles
energy
max_credibility
div_credibility
bubble_active
bubble_age
]
turtles-own[credibility
notoriety
opinion
followed_people
followers
]
to setup
clear-all
reset-ticks
setup-plots
set number-of-turtles square_size * square_size
let columns floor (sqrt number-of-turtles)
let rows ceiling (number-of-turtles / columns)
let x-spacing max-pxcor / (columns)
let y-spacing max-pycor / (rows)
set-default-shape turtles "person business"
set first_opinion 1
set second_opinion -1
set first_palette 10
set second_palette 80
set max_credibility 1
set div_credibility 0.2
let n 0
let n_col 1
let n_row 0
let numero 0
while [n < number-of-turtles] [
if n_col > columns [
set n_col 1
set n_row n_row + 1
]
create-turtles 1 [
setxy (n_col * x-spacing - x-spacing / 2) (n_row * y-spacing + y-spacing / 2)
set notoriety choose-probability analyst_probability
set opinion set_opinion initial_buyers_percentage
set credibility random-normal mean_of_credibility div_credibility
set color set_color credibility opinion
set followed_people []
set followers []
]
set n n + 1
set n_col n_col + 1
]
update-followed
update_size
init_energy
init_bubble_variables
end
to go
update-plot
tick
update_opinion
manage_bubble
end
to opinion_setup
ask turtles [
set opinion set_opinion initial_buyers_percentage
set color set_color credibility opinion
]
end
to-report choose-probability [p1]
let min_influencer 0.3
let max_influencer 0.5
let min_norm 0.01
let max_norm 0.05
let r random-float 1.00
if r < p1 [
report min_influencer + random-float (max_influencer - min_influencer)
]
report min_norm + random-float (max_norm - min_norm)
end
to-report set_opinion [p1]
let r random-float 1.00
if r < p1 [
report second_opinion
]
report first_opinion
end
to-report set_color [cred opin]
let palette 0
if opin = first_opinion [
set palette first_palette
]
if opin = second_opinion [
set palette second_palette
]
if cred > 0.8 * max_credibility [
report 2.5 + palette
]
if cred <= 0.8 * max_credibility and cred > 0.6 * max_credibility [
report 4 + palette
]
if cred <= 0.6 * max_credibility and cred > 0.4 * max_credibility [
report 5.5 + palette
]
if cred <= 0.4 * max_credibility and cred > 0.2 * max_credibility [
report 7 + palette
]
if cred <= 0.2 * max_credibility [
report 8.5 + palette
]
end
to-report return_follower [prob]
let r random-float 1.00
if r < prob [
report 1
]
report 0
end
to update-followed
let new_follower 0
ask turtles [
let out_turtle_notoriety notoriety
let id who
let follower_list []
ask other turtles [
let inner_id who
set new_follower return_follower out_turtle_notoriety
if new_follower = 1 [
set followed_people lput [id] of myself followed_people
set follower_list lput inner_id follower_list
]
]
set followers follower_list
]
end
to update_size
ask turtles [
let n_followers (length followers / number-of-turtles)
set size n_followers * 3 + 0.7
;show length followers
]
end
to update-plot
set-current-plot "Sum of Spins Over Time"
set-current-plot-pen "Sum of Spins"
let sum-spins sum [opinion] of turtles
set sum-spins sum-spins / number-of-turtles
plotxy ticks sum-spins
end
to init_energy
let new_opinion 0
set energy 0
let spin_interaction 0
let external_mag 0
ask turtles[
set new_opinion 0
set external_mag external_mag + opinion
let n_neighbors length followed_people
if n_neighbors != 0 [
foreach followed_people [id ->
ask turtle id [
set new_opinion new_opinion + credibility * opinion / n_neighbors
]
]
;set new_opinion new_opinion + coherence * opinion
set spin_interaction spin_interaction + opinion * new_opinion
]
]
;set energy -1 * J * (spin_interaction + h * external_mag)
set energy -1 * market_influence_strength * (spin_interaction + external_news * external_mag)
end
to-report get_delta_H [turtle_id]
let delta_h 0
let neighbors_influence 0
ask turtle turtle_id [
set neighbors_influence 0
let n_neighbors length followed_people
if n_neighbors != 0 [
foreach followed_people [id ->
ask turtle id [
set neighbors_influence neighbors_influence + credibility * opinion
]
]
;set delta_h 2 * opinion * ( J * neighbors_influence / n_neighbors + h + coherence * opinion)
set delta_h 2 * opinion * ( market_influence_strength * neighbors_influence / n_neighbors + external_news + coherence * opinion)
]
]
report delta_h
end
to update_opinion
let i random number-of-turtles
let delta_h get_delta_H i
let change set_opinion exp(- delta_h * market_sensitivity)
if delta_h != 0 [
if delta_h < 0 or change < 0 [
ask turtle i[
set opinion -1 * opinion
set color set_color credibility opinion
]
init_energy
]
]
end
to run_simulation
set initial_buyers_percentage 1
mag_beta_plot
mag_h_plot
end
to mag_beta_plot
let temperatures (range 0 7 0.1)
let coherences (list 0.5 0.6 0.7 1)
let labels (list "C1" "C2" "C3" "C4")
let results []
let m 0
let i 0
foreach coherences [ coher ->
set coherence coher
set results []
foreach temperatures [temperature ->
set m 0
set market_sensitivity temperature
opinion_setup
repeat n_rep[
go
;set m m + mean [opinion] of turtles
]
set m mean [opinion] of turtles
set results lput (list temperature m) results
]
set-current-plot "Magnetization vs Market Sensitivity"
set-current-plot-pen (item i labels)
foreach results [ point ->
let temp first point
let mag last point
plotxy temp mag
]
set i i + 1
]
end
to mag_h_plot
let h_values (range -0.5 0.5 0.05)
let coherences (list 0.5 0.6 0.7 1)
let labels (list "C1" "C2" "C3" "C4")
let results []
let m 0
let i 0
set market_sensitivity 2.5
foreach coherences [ coher ->
set coherence coher
set results []
foreach h_values [h_value ->
set m 0
set external_news h_value
opinion_setup
repeat n_rep [
go
;set m m + mean [opinion] of turtles
]
;set m m / n_rep
set m mean [opinion] of turtles
set results lput (list h_value m) results
]
set-current-plot "Magnetization vs External News"
set-current-plot-pen (item i labels)
foreach results [ point ->
let temp first point
let mag last point
plotxy temp mag
]
set i i + 1
]
end
to good_news
set external_news max list -3 (external_news - 0.5)
end
to bad_news
set external_news min list 3 (external_news + 0.5)
end
to init_bubble_variables
set bubble_active false
set bubble_age 0
end
to manage_bubble
if bubble_active [
set bubble_age bubble_age + 1
if bubble_age < 1000 [
set external_news max list -3 (external_news - 0.05)
]
if bubble_age = 1000 [
set external_news 3
set market_sensitivity 0.5
]
;; Fase 3: Fine bolla
if bubble_age > 1300 [
set bubble_active false
set bubble_age 0
]
]
end
to start_bubble
set bubble_active true
set bubble_age 0
end
There is only one version of this model, created 6 months ago by Plator Rama.
Attached files
| File | Type | Description | Last updated | |
|---|---|---|---|---|
| Market model.png | preview | Preview for 'Market model' | 6 months ago, by Plator Rama | Download |
This model does not have any ancestors.
This model does not have any descendants.
Download this model