Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
MultilevelChainSampler
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Luca Lenz
MultilevelChainSampler
Commits
8712b0d2
Commit
8712b0d2
authored
1 year ago
by
Luca Lenz
Browse files
Options
Downloads
Patches
Plain Diff
added erdos renyi ensemble
parent
1d5abea8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/MultilevelChainSampler.jl
+8
-3
8 additions, 3 deletions
src/MultilevelChainSampler.jl
src/proposals/networks.jl
+35
-0
35 additions, 0 deletions
src/proposals/networks.jl
test/run_tests.jl
+3
-2
3 additions, 2 deletions
test/run_tests.jl
test/test_proposals.jl
+31
-0
31 additions, 0 deletions
test/test_proposals.jl
with
77 additions
and
5 deletions
src/MultilevelChainSampler.jl
+
8
−
3
View file @
8712b0d2
...
...
@@ -7,17 +7,22 @@ using Distributions
using
Random
,
StatsBase
using
Primes
,
HaltonSequences
using
Graphs
import
Base
:
rand
,
length
,
size
import
Distributions
:
logpdf
import
StatsBase
:
sample
export
logdensity
export
LogDensity
,
SampledLogDensity
export
MultilevelLogDensity
,
MultilevelSampledLogDensity
export
logdensity
export
propose
,
logpratio
export
MetropolisHastings
,
ChristenFox
export
propose
export
RandomWalk
,
CyclicWalk
export
ErdosRenyi
export
sample
export
MetropolisHastings
,
ChristenFox
export
DefaultChains
include
(
"models/all.jl"
)
...
...
This diff is collapsed.
Click to expand it.
src/proposals/networks.jl
+
35
−
0
View file @
8712b0d2
abstract type
NetworkEnsemble
<:
AbstractProposal
end
struct
ErdosRenyi
<:
NetworkEnsemble
n
::
Int64
p
::
Float64
s
::
Int64
end
ErdosRenyi
(
n
::
Int64
)
=
ErdosRenyi
(
n
,
log
(
n
)
/
n
*
(
1
+
exp
(
-
rand
())))
ErdosRenyi
(
n
::
Int64
,
p
::
AbstractFloat
)
=
ErdosRenyi
(
n
,
p
,
ceil
(
Int
,
log
(
n
)))
ErdosRenyi
(
n
::
Int64
,
m
::
Int64
,
s
::
Int64
=
ceil
(
Int
,
log
(
n
)))
=
ErdosRenyi
(
n
,
m
/
(
n
*
(
n
-
1
)
/
2
),
s
)
Base
.
rand
(
rng
::
AbstractRNG
,
e
::
ErdosRenyi
)
=
erdos_renyi
(
e
.
n
,
e
.
p
;
rng
)
function
propose
(
rng
::
AbstractRNG
,
e
::
ErdosRenyi
,
G
::
Graph
)
G
=
copy
(
G
)
for
t
=
1
:
e
.
s
# Choose a pair
u
=
rand
(
rng
,
1
:
nv
(
G
))
v
=
rand
(
rng
,
1
:
nv
(
G
)
-
1
)
if
(
v
>=
u
)
v
+=
1
end
# Resample edge
if
has_edge
(
G
,
u
,
v
)
if
rand
(
rng
)
<
1
-
e
.
p
rem_edge!
(
G
,
u
,
v
)
end
else
if
rand
(
rng
)
<
e
.
p
add_edge!
(
G
,
u
,
v
)
end
end
end
return
G
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/run_tests.jl
+
3
−
2
View file @
8712b0d2
...
...
@@ -4,10 +4,10 @@ using AbstractMCMC: MCMCSerial #, MCMCThreads, MCMCDistributed
using
CairoMakie
using
Revise
using
Pkg
;
Pkg
.
activate
(
"."
)
#
using Pkg; Pkg.activate(".")
using
MultilevelChainSampler
#=
function analyse(chains)
t = TruncatedNormal(0, 1, -1, 1)
...
...
@@ -59,3 +59,4 @@ begin # Sample Based Energy Function
analyse(chains)
end
=#
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/test_proposals.jl
0 → 100644
+
31
−
0
View file @
8712b0d2
using
Random
,
StatsBase
,
Distributions
using
Graphs
using
AbstractMCMC
:
MCMCSerial
#, MCMCThreads, MCMCDistributed
using
CairoMakie
using
Test
using
Revise
using
MultilevelChainSampler
rng
=
Random
.
default_rng
()
function
chain
(
g
)
x
=
[
rand
(
g
)
]
for
i
=
1
:
1000
y
=
MultilevelChainSampler
.
propose
(
rng
,
g
,
x
[
end
])
push!
(
x
,
y
)
end
return
x
end
w
=
CyclicWalk
(
-
1
,
1
,
.
5
)
x
=
chain
(
w
)
@test
abs
(
mean
(
x
)
)
<
0.1
@test
abs
(
std
(
x
)
-
.
5
)
<
0.1
er
=
ErdosRenyi
(
1000
)
x
=
chain
(
er
)
c
=
is_connected
.
(
x
)
@test
mean
(
c
)
>
.
5
k
=
mean
.
(
degree
.
(
x
))
@test
abs
(
mean
(
k
)
-
er
.
n
*
er
.
p
)
<
1
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment