Code Monkey home page Code Monkey logo

Comments (1)

pooyaravari avatar pooyaravari commented on August 15, 2024

So it works fine, and here is the code:

using DifferentialEquations ,BenchmarkTools,  StochasticDiffEq, DiffEqJump, Plots
struct AffectIndex{F1, F2}
  affect_index!::F1
  index::F2
end
function (p::AffectIndex)(integrator)
    return p.affect_index!(integrator, p.index)
end

####
struct RateIndex{F1, F2}
  rate_index::F1
  index::F2
end
function (q::RateIndex)(u, p, t)
    return q.rate_index(u, p, t, q.index)
end
function μ_SDE(du,u,p,t)
  du .= p.μ
end

function σ_SDE(du,u,p,t)
  du .= p.σ
end

function affect!(integrator)
    κ = 0.5
    N = length(integrator.u)
    sort_u = sort(integrator.u)
    F = range(0.0, 1, length = N) 
    draw_quantile = rand(2)  # draw quantile on (0,1)
    u_n = sort_u[findlast(q -> q <= draw_quantile[1], F.^κ)]
    u_n_2 = sort_u[findlast(q -> q <= draw_quantile[2], F.^κ)]
    integrator.u[integrator.u .== u_n] = 
                max(integrator.u[integrator.u .== u_n], integrator.u[integrator.u .== u_n_2])
end

p == 0.01, σ = 0.1, N = 5) # if all constant
T = 10.0  # maximum time length
x_iv = rand(p.N)  # just draws from the inital condition

prob = SDEProblem(μ_SDE, σ_SDE, x_iv ,(0.0, T), p)
rate(u,p,t) = 0.2*p.N
jump = ConstantRateJump(rate,affect!)
jump_prob = JumpProblem(prob,DirectFW(),jump)
sol = solve(jump_prob, SRIW1());
plot(sol)

Screen Shot 2019-08-07 at 1 17 28 PM

from knowledgediffusionsimulations.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.