Skip to content

Commit

Permalink
Made code faster
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoFlorio authored and stecrotti committed Apr 16, 2024
1 parent 45f14f1 commit 393ca39
Show file tree
Hide file tree
Showing 6 changed files with 12,437 additions and 12,435 deletions.
24,856 changes: 12,428 additions & 12,428 deletions notebooks/sis_heterogeneous_compare_homogeneous.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/MatrixProductBP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module MatrixProductBP

using InvertedIndices: Not
using ProgressMeter: Progress, ProgressUnknown, next!
using TensorCast: @reduce, @cast, TensorCast
using TensorCast: @reduce, @cast, TensorCast
using LoopVectorization
using Tullio: @tullio
using IndexedGraphs: IndexedGraphs, AbstractIndexedDiGraph, IndexedGraph, IndexedBiDiGraph,
nv, ne, edges, vertices, inedges, outedges, src, dst, idx, neighbors, IndexedEdge,
issymmetric
using UnPack: @unpack
using Random: shuffle!, AbstractRNG, GLOBAL_RNG
using SparseArrays: rowvals, nonzeros, nzrange
using SparseArrays: rowvals, nonzeros, nzrange, sparse
using Distributions: Distributions, sample, sample!
using Measurements: Measurement, ±
using Statistics: mean, std
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Models.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using MatrixProductBP
import IndexedGraphs: IndexedGraph, IndexedBiDiGraph, AbstractIndexedDiGraph, ne, nv,
outedges, idx, src, dst, inedges, neighbors, edges, vertices, IndexedEdge
import UnPack: @unpack
import SparseArrays: nonzeros, nzrange, rowvals, Symmetric, SparseMatrixCSC
import SparseArrays: nonzeros, nzrange, rowvals, Symmetric, SparseMatrixCSC, sparse
import TensorCast: @reduce, @cast, TensorCast
import ProgressMeter: Progress, next!, ProgressUnknown
import LogExpFunctions: xlogx, xlogy
Expand Down
6 changes: 3 additions & 3 deletions src/Models/epidemics/sis_heterogeneous.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct SIS_heterogeneous{T, N, F<:Real}
g :: IndexedGraph
λ :: SparseMatrixCSC{F,Int64}
λ :: Vector{F}
ρ :: Vector{F}
ϕ :: Vector{Vector{Vector{F}}} # site observations
ψ :: Vector{Vector{Matrix{F}}} # edge observations
Expand All @@ -17,7 +17,7 @@ struct SIS_heterogeneous{T, N, F<:Real}
@assert all(length(ϕᵢ) == T + 1 for ϕᵢ in ϕ)
@assert length(ψ) == 2*ne(g)
@assert all(length(ψᵢⱼ) == T + 1 for ψᵢⱼ in ψ)
new{T,N,F}(g, λ, ρ, ϕ, ψ)
new{T,N,F}(g, nonzeros(λ), ρ, ϕ, ψ)
end
end

Expand All @@ -37,5 +37,5 @@ function SIS_heterogeneous(λ::SparseMatrixCSC{F,Int64}, ρ::Vector{F}, T::Int;
end

function sis_heterogeneous_factors(sis::SIS_heterogeneous{T,N,F}) where {T,N,F}
[fill(SIS_heterogeneousFactor([sis.λ[j,i] for j in sis.λ.rowval[nzrange(sis.λ,i)]], sis.ρ[i]), T + 1) for i in vertices(sis.g)]
[fill(SIS_heterogeneousFactor(sis.λ[nzrange(sis.g.A,i)], sis.ρ[i]), T + 1) for i in vertices(sis.g)]
end
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
IndexedGraphs = "8a731c18-cfb7-4915-927e-cc26b56b67cd"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
TensorTrains = "89893e69-996d-40b1-ba32-8ff5f34c0dd5"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Test, MatrixProductBP
using MatrixProductBP.Models
using Graphs, IndexedGraphs, Random, Distributions
using Graphs, IndexedGraphs, Random, Distributions, SparseArrays
using TensorTrains
using Aqua

Expand All @@ -19,6 +19,7 @@ include("pair_observations.jl")
include("periodic.jl")
include("sampling.jl")
include("sirs_small_tree.jl")
include("sis_heterogeneous_compare_homogeneous.jl")
include("sis_infinite_graph.jl")
include("sis_small_tree.jl")

Expand Down

0 comments on commit 393ca39

Please sign in to comment.