diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..8be96a5c --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,24 @@ +{ + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/devcontainers/features/common-utils:2": { + "configureZshAsDefaultShell": true, + "nonFreePackages": true + } + }, + "customizations": { + "vscode": { + "extensions": [ + "github.vscode-github-actions", + "ms-toolsai.jupyter", + "tamasfe.even-better-toml", + "julialang.language-julia" + ], + "settings": { + "julia.executablePath": "~/.juliaup/bin/julia" + } + } + }, + "onCreateCommand": "bash .devcontainer/onCreate.sh" +} \ No newline at end of file diff --git a/.devcontainer/julia_startup.jl b/.devcontainer/julia_startup.jl new file mode 100644 index 00000000..06be6e3b --- /dev/null +++ b/.devcontainer/julia_startup.jl @@ -0,0 +1,2 @@ +ENV["JULIA_PKG_USE_CLI_GIT"] = true +ENV["JULIA_PKG_SERVER_REGISTRY_PREFERENCE"] = "eager" diff --git a/.devcontainer/onCreate.jl b/.devcontainer/onCreate.jl new file mode 100644 index 00000000..cec50a31 --- /dev/null +++ b/.devcontainer/onCreate.jl @@ -0,0 +1,11 @@ +import Pkg + +Pkg.Registry.add(Pkg.RegistrySpec(url="https://github.com/cossio/CossioJuliaRegistry.git")) +Pkg.Registry.add("General") + +Pkg.add([ + "CairoMakie", + "Makie", + "MyRegistrator", + "Revise", +]) diff --git a/.devcontainer/onCreate.sh b/.devcontainer/onCreate.sh new file mode 100644 index 00000000..15dbd1b0 --- /dev/null +++ b/.devcontainer/onCreate.sh @@ -0,0 +1,18 @@ +# install Julia and make sure it's in the PATH of the current shell +curl -fsSL https://install.julialang.org | sh -s -- --yes + +# Julia startup file +mkdir -p ~/.julia/config +cp .devcontainer/julia_startup.jl ~/.julia/config/startup.jl + +# Github CLI autocomplete (https://www.ajfriesen.com/github-cli-auto-completion-with-oh-my-zsh/) +mkdir -p ~/.oh-my-zsh/completions +/usr/bin/gh completion -s zsh > ~/.oh-my-zsh/completions/_gh +echo "autoload -U compinit" >> ~/.zshrc +echo "compinit -i" >> ~/.zshrc + +# Directory to store Rfam data (set in LocalPreferences.toml) +mkdir -p ~/data/Rfam + +# Install Julia packages, registries, ... +/home/vscode/.juliaup/bin/julia .devcontainer/onCreate.jl \ No newline at end of file diff --git a/Project.toml b/Project.toml index 35808ab7..8180658e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "RestrictedBoltzmannMachines" uuid = "12e6b396-7db5-4506-8cb6-664a4fe1e50e" authors = ["Jorge Fernandez-de-Cossio-Diaz "] -version = "3.3.1-DEV" +version = "3.4.0" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" diff --git a/src/RestrictedBoltzmannMachines.jl b/src/RestrictedBoltzmannMachines.jl index b151866a..2e6e989c 100644 --- a/src/RestrictedBoltzmannMachines.jl +++ b/src/RestrictedBoltzmannMachines.jl @@ -32,6 +32,7 @@ include("rbm.jl") include("rbms/hopfield.jl") include("rbms/binary.jl") +include("rbms/spin.jl") include("rbms/gaussian.jl") include("pseudolikelihood.jl") diff --git a/src/rbms/spin.jl b/src/rbms/spin.jl new file mode 100644 index 00000000..fea8917c --- /dev/null +++ b/src/rbms/spin.jl @@ -0,0 +1,15 @@ +function SpinRBM(a::AbstractArray, b::AbstractArray, w::AbstractArray) + @assert size(w) == (size(a)..., size(b)...) + visible = Spin(; θ = a) + hidden = Spin(; θ = b) + return RBM(visible, hidden, w) +end + +function SpinRBM(::Type{T}, N::Union{Int,Dims}, M::Union{Int,Dims}) where {T} + a = zeros(T, N...) + b = zeros(T, M...) + w = zeros(T, N..., M...) + return SpinRBM(a, b, w) +end + +SpinRBM(N::Union{Int,Dims}, M::Union{Int,Dims}) = SpinRBM(Float64, N, M)