在 NetLogo 中实现时间延迟

Implementing a time lag in NetLogo

我正在尝试为 NetLogo 程序中的性能指标实现时间滞后。这就是我目前正在尝试编写的代码,但我不知道如何在以下公式中实现 (t-1) 因子:

performance(t) = θ × performance(t−1) + (1 − θ) π(t), 0 < θ < 1

现在我是这样离开的:

ask turtles [
set performance theta * performance + (1 - theta) * profit
]

但是我的模型没有给出合法的结果(据我所知,因为这个公式没有考虑时间滞后)。

完整代码:

globals [
  N ; Number of firms
  price         ; Market price
  totOutput    ; Total production of firms
  meanProd  ; Average productivity of firms
  maxProd      ; Maximal productivity of firms
  minProd      ; Minimal productivity of firms
  meanProf-innov ; Average profit of innovators
  meanProf-imit  ; Average profit of pure imitators

  HK     ; Concentration index over capital
  HQ     ; Concentration index over output

  ; Other parameters
  rIn  ; Innovative R&D calibration parameter
  rIm  ; Imitative R&D calibration parameter
  aIn  ; Innovative R&D calibration parameter
  aIm  ; Imitative R&D calibration parameter
  avgRIn ; NEW -> Represents the Average Rate of R&D Investments by Innovators
  avgRIm ; NEW -> Represents the Average Rate of R&D Investments by Imitators
  avgCapitalProfit
  CapitalProfit
  Ae
  Ue
  Entrynumber
  sumCapSq
  totCapital
]

breed [Innovators Innovator]
breed [Imitators Imitator]

Innovators-own [
  output  ; output of the firm
  prod    ; productivity of the firm
  capital ; capital stock of the firm
  profit  ; gross profit of the firm
  rInF    ; Each innovator's innovative R&D parameter will be the common rIn
  rImF    ; Each innovator's imitative R&D parameter will the common rIm
  RDIn    ; Innovative R&D investment of the firm
  RDIM    ; Imitative R&D investment of the firm
  RInCapital ; NEW -> See below (Formula for new rates) , it is equal to rImF * capital for each innovator
  RImCapital ; NEW -> See below (Formula for new rates) , it is equal to rImF * capital for each imitator
  prodInnovate ; Productivity discovered thanks to the innovation
  prodImitate ; Productivity discovered thanks to the imitation
  performance   ; NEW -> Performance Indicator
]

Imitators-own [
  output  ; output of the firm
  prod    ; productivity of the firm
  capital ; capital stock of the firm
  profit  ; net profit of the firm
  rImF    ; Each imitator's imitative R&D parameter will be the common rIm
  rInF    ; Each imitator's innovative R&D parameter will be zero
  RDIn    ; Innovative R&D investment of the imitator will be 0
  RDIM    ; Imitative R&D investment of the firm
  RInCapital ; NEW -> See below (Formula for new rates) , it is equal to rImF * capital for each innovator
  RImCapital ; NEW -> See below (Formula for new rates) , it is equal to rImF * capital for each imitator
  prodInnovate ; Productivity discovered thanks to the innovation
  prodImitate ; Productivity discovered thanks to the imitation
  performance   ; NEW -> Performance indicator
]

to setup
  clear-all
  create-Innovators nbInnov
  create-Imitators nbImit
  set N nbInnov + nbImit

  ; Initial capital stock of the firms in order to have zero desired net investment (investment just compensates the depreciation in the initial Cournot equilibrium) 
  let K0 ( (Dem * A0 * ( N * Eta - 1))/(N * Eta * c) ^ (1 / Eta )) / (N * A0)


  ; Innovation and imitation parameters
  set aIn 0.125
  set aIm 1.25
  ; Innovation and imitation parameters deducted from probabilities

  ; NEW Investment R&D Rates

  set rIn probInnov / ( K0 * aIn)
  set rIm probImitate / ( K0 * aIm)


  ; Setting these parameters at the firm level for each type of firm

   ask Innovators [
   set prod A0
   set capital K0
   set rInF random-float 0.004 + 0.005    ; NEW -> Gives a number following a Uniform distribution between 0.005 and 0.009
   set rImF random-float 0.0004 + 0.0003  ; NEW -> Gives a number following a Uniform distribution between 0.0003 and 0.0007
  ]

  ask Imitators [
   set prod A0
   set capital K0    
   set rInF 0
   set rImF random-float 0.0004 + 0.0003 ; NEW -> Gives a number following a Uniform distribution between 0.0003 and 0.0007 
  ]

  ask Turtles [
    set performance 0
  ]

  reset-ticks

end

to go

  if ticks > nbPeriods [stop]

    ask turtles [ ; NEW
    if capital < Kmin [ die ] ; NEW
    if performance < performance-min [ die ] ; NEW
  ] ; NEW

  ; NEW
  ; Eventually, hereafter is the problem of decision that decides wheter a company should enter the industry or not

 ask turtles [ ; NEW
    if (price * Ae - c > entry-barrier + ue) [ ; NEW
      hatch entryNumber [ ; NEW 
        set performance 0.1 ; NEW 
        set capital random-normal (sumCapSq / totCapital) 5 ; NEW 
        set RDIm random-normal (RImCapital / totCapital) 0.01 ; NEW 
        set RDIn random-normal (RInCapital / totCapital) 0.01 ; NEW 
    ]
  ]
  ]

  ; Fixing the output of each firm
  ask turtles [   
   set output prod * capital
  ]

  ;Computing the total output and the intraperiod price
  set totOutput sum [output] of turtles
  set price invDemand totOutput

  ;Productivity indicators of the current period
  set maxProd max [prod] of turtles
  set meanProd mean [prod] of turtles
  set minProd min [prod] of turtles

  ;Concentration indicators of the current period
  set totCapital sum [capital] of turtles


  set HK (totCapital) ^ 2 / sum [capital ^ 2] of turtles
  set HQ (totOutput) ^ 2 / sum [output ^ 2] of turtles 

  ; Moving towards the next period (new productivity and capital stock)
  ask turtles [

      ; Compute net profits
      set profit (price * prod - c) * capital - RDIn - RDIm  

      ; NEW Formulas used to calculate new rates 
      set capitalProfit sum  [capital * profit] of turtles ;NEW
      set avgCapitalProfit capitalProfit / totCapital ;NEW 
      set RInCapital sum [(rInF * capital)] of turtles ;NEW
      set RImCapital sum [(rImF * capital)] of turtles ;NEW
      set avgRIn (RInCapital) / (totCapital) ;NEW
      set avgRIm (RImCapital) / (totCapital) ;NEW

      ; Compute R&D investments

      ]

ask turtles [
  set RDIn rInF * aIn * capital
  set RDIm rImF * aIm * capital


      ; Below are the original commands of the original model, kept this way should an error arise
      ; OLD set RDIn (rInF * aIn * capital) 
      ; OLD set RDIm (rImF * aIm * capital)

      ; Compute productivities discovered thanks to innovation and imitation
set prodInnovate innovation
set prodImitate imitation

      ; Set the new productivity of the firm
set prod max (list prod prodInnovate prodImitate)

      ; Compute the new capital stock of the firm
set capital investK
]


  ;profit indicators
set meanProf-innov mean [profit] of Innovators
set meanProf-imit mean [profit] of Imitators

 ; NEW 
 ; Below we code the performance indicator

  ask turtles [
     set profit (price * prod - c) * capital - RDIn - RDIm 
    set performance theta * performance + (1 - theta) * profit
  ]


tick

  ; NEW
  ; The group of commands below represents the entry process of decision

  set entryNumber round (entry-trials-rate * N) ; NEW
  let prodCapital sum [prod * capital] of turtles ; NEW
  let avgA prodCapital / totCapital ; NEW
  set Ae random-normal avgA STD ; NEW
  set ue random-normal 0 0.1 ; NEW 
  set sumCapSq sum [capital ^ 2] of turtles ; NEW
  ; NEW 
  ; Below are is the command representing the exit process of decision

  ; NEW R&D RATES
      ; Hereafter we compute the new rates following the satisficing rule à la Simon
     ask turtles [ 
      if performance < avgCapitalProfit [
        set rInF (1 - beta) * rInF + beta * avgRIn + random-normal 0 sigma-n 
        set rImF (1 - beta) * rImF + beta * avgRIm + random-normal 0 sigma-m

      ]
     ]






end ;INVESTK

; Imitation procedure
to-report imitation

  ; Draw a number between 0 and 1
  let draw random-float 1.
  ; Compare it with the rescaled value of the R&D
  ifelse draw <= RDIm [report maxProd][report 0.]
end

; Innovation procedure
to-report innovation
  ; Draw a number between 0 and 1
  let draw random-float 1.
  ; Compare it with the rescaled value of the R&D
  ifelse draw <= RDIn [report random-normal prod STD][report 0.]

end

;Investment procedure
to-report investK
  ; Compute the current market share of the firm
  let marketShare output / totOutput
  ; Compute the current margin of the firm
  let margin c / (prod * price)
  ; The target price
  let target-price (margin * ETA) / (ETA - marketShare)
  ; Compute the desired investment of the firm
  let desInvest (DEPREC + 1 - ( target-price / price) )
  ; Compute maximal possible investment (No external financing)
  let maxInvest  (DEPREC + profit)
  ; Possible investment 
  let posInvest min (list desInvest maxInvest)
  ; Compute the effective investment rate of the firm (it cannot be negative)
  let investmentRate max (list  posInvest 0.)
  report  ((1 - DEPREC) + investmentRate) * capital 
end

; The constant-elasticity inverse demand function
 to-report invDemand [totQuant]

       report Dem / (totQuant ^ Eta)
 end

您的代码已经执行了 (t-1)。您可以通过执行以下操作来查看:

ask turtles
[ print performance
  set performance theta * performance + (1 - theta) * profit
  print performance
]

我们可能需要更多代码和错误示例