text:
module SymEGRSSMatrices

import LinearAlgebra: cholesky,inv!, tr, mul!, Adjoint, det, logdet, dot,
                      Factorization, tril, triu, ldiv!,
                      LowerTriangular, UpperTriangular, Diagonal
import Base: \, inv, size, eltype, Matrix, getindex, getproperty

export SymEGRSSMatrix, SymEGRSSCholesky,
       SymEGRQSMatrix, SymEGRQSCholesky,
       trinv, cholesky, det, logdet

# Matrices
include("SymEGRSSMatrix.jl")
include("SymEGRSSCholesky.jl")

include("SymEGRQSMatrix.jl")
include("SymEGRQSCholesky.jl")

# Extra functions
include("spline_kernel.jl")

end # module

max_stars_repo_name: mipals/SymEGRSSMatrices


text:
"""
nullpert.jl

Null Perturbation
"""

immutable NullPerturbation <: Perturbation
  ncomp::Int # number of components
end

#
# Thermodynamic functions
#
kinetic(null::NullPerturbation, ref::ReferenceSystem)::Float64 = 0
internal(null::NullPerturbation, ref::ReferenceSystem)::Float64 = 0
entropy(null::NullPerturbation, ref::ReferenceSystem, T::Float64)::Float64 = 0
helmholtz(null::NullPerturbation, ref::ReferenceSystem)::Float64 = 0

function pairpotential(null::NullPerturbation)::Array{Function,2}
  N::Int = null.ncomp
  ret = Array{Function,2}(N,N)

  for i in 1:N, j in 1:N
    i > j && continue
    u(r)::Float64 = 0
    ret[i,j] = ret[j,i] = u
  end

  return ret
end

ext: jl


text:
export Sech

"""
`Sech([domainType=Float64::Type,] dim_in::Tuple)`

Creates an hyperbolic secant non-linear operator with input dimensions `dim_in`:
```math
\\text{sech} ( \\mathbf{x} ).
```

"""
struct Sech{T,N} <: NonLinearOperator
	dim::NTuple{N,Int}
end

function Sech(DomainType::Type, DomainDim::NTuple{N,Int}) where {N}
	Sech{DomainType,N}(DomainDim)
end

Sech(DomainDim::NTuple{N,Int}) where {N} = Sech{Float64,N}(DomainDim)
Sech(DomainDim::Vararg{Int}) = Sech{Float64,length(DomainDim)}(DomainDim)

function mul!(y::AbstractArray{T,N}, L::Sech{T,N}, x::AbstractArray{T,N}) where {T,N}
	y .= sech.(x)
end

function mul!(y::AbstractArray,
              J::AdjointOperator{Jacobian{A,TT}},
              b::AbstractArray) where {T,N, A<: Sech{T,N}, TT <: AbstractArray{T,N}}
    L = J.A
    y .= -conj.( tanh.(L.x) .* sech.(L.x) ).*b
end

fun_name(L::Sech) = "sech"

size(L::Sech) = (L.dim, L.dim)

domainType(L::Sech{T,N}) where {T,N} = T
codomainType(L::Sech{T,N}) where {T,N} = T


text:
# Poverty_gap.jl

###### poverty_gap #####
"""
    poverty_gap(v, z)

Compute the Poverty Gap of a vector `v` at a specified poverty threshold `z`.

# Examples
```julia
julia> using Inequality
julia> poverty_gap([8, 5, 1, 3, 5, 6, 7, 6, 3], 4)
0.1388888888888889
```
"""
poverty_gap(v::AbstractVector{<:Real}, z::Real)::Float64 = sum((z .- v[v .< z])/z)/length(v)

###### weighted poverty_gap #####
"""
    poverty_gap(v, w, z)

Compute the Poverty Gap of a vector `v` at a specified poverty threshold `z`,
using weights given by a weight vector `w`.

Weights must not be negative, missing or NaN. The weights and data vectors must have the same length.

# Examples
```julia
julia> using Inequality
julia> poverty_gap([8, 5, 1, 3, 5, 6, 7, 6, 3], [0.1,0.5,0.3,0.8,0.1,0.5,0.3,0.8,0.2], 4)
0.13194444444444445
```
"""
function poverty_gap(v::AbstractVector{<:Real}, w::AbstractVector{<:Real}, z::Real)::Float64
    checks_weights(v, w)

    return sum((z .- v[v .< z])/z .* w[v .< z])/sum(w)
end

function poverty_gap(v::AbstractVector{<:Real}, w::AbstractWeights, z::Real)::Float64
    checks_weights(v, w)

    return sum((z .- v[v .< z])/z .* w[v .< z])/w.sum
end

wpoverty_gap(v::AbstractVector{<:Real}, w::AbstractVector{<:Real}, z::Real)::Float64 = poverty_gap(v, w, z)

wpoverty_gap(v::AbstractVector{<:Real}, w::AbstractWeights, z::Real)::Float64 = poverty_gap(v, w, z)


text:
# Gather statistics for the KS problem and store to file
module KSGather

include("kuramoto-sivashinsky.jl")
using .kuramoto_sivashinsky

# define integrand functions needed for time averages
function ident(val)
    return val
end
function square(val)
    return val*val
end

# This is not the same as the function in `verify_spatial_accuracy.jl` !!!
# The order below is different
function Print3DArray(file, arr::AbstractArray{Float64,3})
    for k = 1:size(arr,3)
        for j = 1:size(arr,2)
            for i = 1:size(arr,1)
                print(file, arr[i,j,k], " ")
            end
            println(file)
        end
    end
end

"""
    gatherStatsKS()

Runs the KS problem with different discretization orders, mesh sizes and
integration periods, and writes results to file.
"""
function gatherStatsKS()

    # set some parameters
    tp = Float64             # floating point type to use
    Lx = convert(tp, 128)    # domain size
    spin = convert(tp, 1000) # spin-up period
    num_samples = 10         # number of ensemble samples to use

    # set the discretization parameters
    dt = 0.01
    base_time = 40.0
    base_steps = convert(Int, base_time/dt)
    time_fac = 10
    order = [2, 4, 6]
    num_nodes = Array{Int}(128:32:256) .- 1
    num_spin = convert(Int, spin/dt)

    println("Information")
    println("\tdt = ",dt)
    println("\tbase_time = ",base_time)
    println("\tbase_steps = ",base_steps)
    println("\ttime_fac  = ",time_fac)
    println()

    # loop over the orders of accuracy
    for p = 1:size(order,1)
        println("Gathering statistics for order ",order[p])
        # each order gets its own file

        dx = zeros(Float64, (num_samples*time_fac^2, size(num_nodes,1), 3) )
        u_avg = zeros(size(dx))
        u2_avg = zeros(size(dx))
        cputime = zeros(size(dx))
        time = base_time*time_fac^2
        num_steps = base_steps*time_fac^2

        for n = 1:size(num_nodes,1)
            println("\tUsing number of nodes = ",num_nodes[n])
            # set initial condition and set-up the KSData structure
            dx[:,n,:] .= Lx/(num_nodes[n]+1)
            ks = kuramoto_sivashinsky.buildKSData(order[p], num_nodes[n], tp)

            for s = 1:num_samples
                println("\tRunning long-time sample ",s)
                # run spin up simulation
                u = 2*rand(num_nodes[n]) .- 1
                sol = kuramoto_sivashinsky.solveUsingMidpoint(ks, spin, num_spin, u)
                u = sol[2:end-1,end]
                sol = nothing

                # solve for the statistics using longest simulation time
                # print("\t") # this is so the elapsed time is indented
                cpu_long = @elapsed begin
                    sol = kuramoto_sivashinsky.
                    solveUsingMidpoint(ks, time, num_steps, u)
                end
                if any(isnan, sol)
                    error("KS failed to solve due to instability.")
                end

                # We partition the long-time simulation into smaller periods for
                # statistics gathering.  For example, if the long-time is 4000
                # units then we have 1 sample for 4000, 10 samples for 400
                # units, and 100 samples for 40 units.
                # The statistics for the medium and long periods are duplicated
                # to simplify the file I/O (NumPy loadtxt is easier), so this
                # needs to be accounted for by dividing by the same number of
                # total samples, which is num_samples*time_fac^2
                u_avg_long = kuramoto_sivashinsky.
                    calcSolutionAverage(order[p], sol, ident)
                u2_avg_long = kuramoto_sivashinsky.
                    calcSolutionAverage(order[p], sol, square)
                ptr = (s-1)*time_fac^2 + 1
                for s1 = 1:time_fac
                    ibeg = base_steps*(s1-1)*time_fac + 1
                    iend = base_steps*s1*time_fac + 1
                    u_avg_med = kuramoto_sivashinsky.
                        calcSolutionAverage(order[p], view(sol,:,ibeg:iend),
                                            ident)
                    u2_avg_med = kuramoto_sivashinsky.
                        calcSolutionAverage(order[p], view(sol,:,ibeg:iend),
                                            square)
                    for s2 = 1:time_fac
                        # get statistics for the shortest period
                        ibeg = base_steps*((s1-1)*time_fac + s2 - 1) + 1
                        iend = base_steps*((s1-1)*time_fac + s2) + 1
                        u_avg[ptr,n,1] = kuramoto_sivashinsky.
                        calcSolutionAverage(order[p], view(sol,:,ibeg:iend),
                                            ident)
                        u2_avg[ptr,n,1] = kuramoto_sivashinsky.
                        calcSolutionAverage(order[p], view(sol,:,ibeg:iend),
                                            square)
                        cputime[ptr,n,1] = cpu_long/(time_fac^2)
                        # get statistics for the medium period
                        u_avg[ptr,n,2] = u_avg_med
                        u2_avg[ptr,n,2] = u2_avg_med
                        cputime[ptr,n,2] = cpu_long/time_fac
                        # get statistics for the longest period
                        u_avg[ptr,n,3] = u_avg_long
                        u2_avg[ptr,n,3] = u2_avg_long
                        cputime[ptr,n,3] = cpu_long

                        ptr += 1
                    end
                end
            end
        end

        # write the data
        data = open("raw_statistics_ks_order$(order[p]).dat", "w")
        Print3DArray(data, dx)
        Print3DArray(data, u_avg)
        Print3DArray(data, u2_avg)
        Print3DArray(data, cputime)
        close(data)
    end
end

end # module KSGather

max_stars_repo_name: jehicken/high-order-and-chaos

max_issues_repo_name: jehicken/high-order-and-chaos

max_forks_repo_name: jehicken/high-order-and-chaos


text:
#
# Datasets
#

# Use an Enum here when it doesn't make us allocate
const LC_COMPACT_STORAGE = 0x00
const LC_CONTIGUOUS_STORAGE = 0x01
const LC_CHUNKED_STORAGE = 0x02

function load_dataset(f::JLDFile, offset::RelOffset)
    if haskey(f.jloffset, offset)
        # Stored as WeakRefs and may no longer exist
        val = f.jloffset[offset].value
        val !== nothing && return val
    end

    io = f.io
    seek(io, fileoffset(f, offset))
    cio = begin_checksum_read(io)
    sz = read_obj_start(cio)
    pmax = position(cio) + sz

    # Messages
    dataspace = ReadDataspace()
    attrs = EMPTY_READ_ATTRIBUTES
    datatype_class::UInt8 = 0
    datatype_offset::Int64 = 0
    data_offset::Int64 = 0
    data_length::Int = -1
    chunked_storage::Bool = false
    filter_id::UInt16 = 0
    while position(cio) <= pmax-4
        msg = read(cio, HeaderMessage)
        endpos = position(cio) + msg.size
        if msg.msg_type == HM_DATASPACE
            dataspace = read_dataspace_message(cio)
        elseif msg.msg_type == HM_DATATYPE
            datatype_class, datatype_offset = read_datatype_message(cio, f, (msg.flags & 2) == 2)
        elseif msg.msg_type == HM_FILL_VALUE
            (read(cio, UInt8) == 3 && read(cio, UInt8) == 0x09) || throw(UnsupportedFeatureException())
        elseif msg.msg_type == HM_DATA_LAYOUT
            read(cio, UInt8) == 4 || throw(UnsupportedVersionException())
            storage_type = read(cio, UInt8)
            if storage_type == LC_COMPACT_STORAGE
                data_length = read(cio, UInt16)
                data_offset = position(cio)
            elseif storage_type == LC_CONTIGUOUS_STORAGE
                data_offset = fileoffset(f, read(cio, RelOffset))
                data_length = read(cio, Length)
            elseif storage_type == LC_CHUNKED_STORAGE
                # TODO: validate this
                flags = read(cio, UInt8)
                dimensionality = read(cio, UInt8)
                dimensionality_size = read(cio, UInt8)
                skip(cio, Int(dimensionality)*Int(dimensionality_size))

                chunk_indexing_type = read(cio, UInt8)
                chunk_indexing_type == 1 || throw(UnsupportedFeatureException())
                data_length = read(cio, Length)
                read(cio, UInt32)
                data_offset = fileoffset(f, read(cio, RelOffset))
                chunked_storage = true
            else
                throw(UnsupportedFeatureException())
            end
        elseif msg.msg_type == HM_FILTER_PIPELINE
            version = read(cio, UInt8)
            version == 2 || throw(UnsupportedVersionException())
            nfilters = read(cio, UInt8)
            nfilters == 1 || throw(UnsupportedFeatureException())
            filter_id = read(cio, UInt16)
            filter_id == 1 || throw(UnsupportedFeatureException())
        elseif msg.msg_type == HM_ATTRIBUTE
            if attrs === EMPTY_READ_ATTRIBUTES
                attrs = ReadAttribute[read_attribute(cio, f)]
            else
                push!(attrs, read_attribute(cio, f))
            end
        elseif (msg.flags & 2^3) != 0
            throw(UnsupportedFeatureException())
        end
        seek(cio, endpos)
    end
    seek(cio, pmax)

    filter_id != 0 && !chunked_storage && throw(InvalidDataException())

    # Checksum
    end_checksum(cio) == read(io, UInt32) || throw(InvalidDataException())

    # TODO verify that data length matches
    val = read_data(f, dataspace, datatype_class, datatype_offset, data_offset, data_length,
                    filter_id, offset, attrs)
    val
end

"""
    read_attr_data(f::JLDFile, attr::ReadAttribute)

Read data from an attribute.
"""
read_attr_data(f::JLDFile, attr::ReadAttribute) =
    read_data(f, attr.dataspace, attr.datatype_class, attr.datatype_offset,
              attr.data_offset)

"""
    read_attr_data(f::JLDFile, attr::ReadAttribute, expected_datatype::H5Datatype,
                   rr::ReadRepresentation)

Read data from an attribute, assuming a specific HDF5 datatype and ReadRepresentation. If
the HDF5 datatype does not match, throws an `UnsupportedFeatureException`. This allows
better type stability while simultaneously validating the data.
"""
function read_attr_data(f::JLDFile, attr::ReadAttribute, expected_datatype::H5Datatype,
                        rr::ReadRepresentation)
    io = f.io
    if attr.datatype_class == class(expected_datatype)
        seek(io, attr.datatype_offset)
        dt = read(io, typeof(expected_datatype))
        if dt == expected_datatype
            seek(f.io, attr.data_offset)
            BOXED_READ_DATASPACE[] = (attr.dataspace, NULL_REFERENCE, -1, 0)
            return read_data(f, rr)
        end
    end
    throw(UnsupportedFeatureException())
end

"""
    read_data(f::JLDFile, dataspace::ReadDataspace, datatype_class::UInt8,
              datatype_offset::Int64, data_offset::Int64[, filter_id::UInt16,
              header_offset::RelOffset, attributes::Vector{ReadAttribute}])

Read data from a file. If `datatype_class` is typemax(UInt8), the datatype is assumed to be
committed, and `datatype_offset` points to the offset of the committed datatype's header.
Otherwise, datatype_offset points to the offset of the datatype attribute.
"""
function read_data(f::JLDFile, dataspace::ReadDataspace,
                   datatype_class::UInt8, datatype_offset::Int64,
                   data_offset::Int64, data_length::Int=-1, filter_id::UInt16=UInt16(0),
                   header_offset::RelOffset=NULL_REFERENCE,
                   attributes::Union{Vector{ReadAttribute},Nothing}=nothing)
    # See if there is a julia type attribute
    io = f.io
    if datatype_class == typemax(UInt8) # Committed datatype
        rr = jltype(f, f.datatype_locations[h5offset(f, datatype_offset)])
        seek(io, data_offset)
        BOXED_READ_DATASPACE[] = (dataspace, header_offset, data_length, filter_id)
        read_data(f, rr, attributes)
    else
        seek(io, datatype_offset)
        @read_datatype io datatype_class dt begin
            rr = jltype(f, dt)
            seek(io, data_offset)
            BOXED_READ_DATASPACE[] = (dataspace, header_offset, data_length, filter_id)
            read_data(f, rr, attributes)
        end
    end
end

# We can avoid a box by putting the dataspace here instead of passing
# it to read_data.  That reduces the allocation footprint, but doesn't
# really seem to help with performance.
const BOXED_READ_DATASPACE = Ref{Tuple{ReadDataspace,RelOffset,Int,UInt16}}()

# Most types can only be scalars or arrays
function read_data(f::JLDFile, rr, attributes::Union{Vector{ReadAttribute},Nothing}=nothing)
    dataspace, header_offset, data_length, filter_id = BOXED_READ_DATASPACE[]
    if dataspace.dataspace_type == DS_SCALAR
        filter_id != 0 && throw(UnsupportedFeatureException())
        read_scalar(f, rr, header_offset)
    elseif dataspace.dataspace_type == DS_SIMPLE
        read_array(f, dataspace, rr, data_length, filter_id, header_offset, attributes)
    else
        throw(UnsupportedFeatureException())
    end
end

# Reference arrays can only be arrays or null dataspace (for Union{} case)
function read_data(f::JLDFile, rr::ReadRepresentation{Any,RelOffset},
                   attributes::Vector{ReadAttribute})
    dataspace, header_offset, data_length, filter_id = BOXED_READ_DATASPACE[]
    filter_id != 0 && throw(UnsupportedFeatureException())
    if dataspace.dataspace_type == DS_SIMPLE
        # Since this is an array of references, there should be an attribute
        # informing us of the type
        io = f.io
        startpos = position(io)
        for x in attributes
            if x.name == :julia_type
                T = read_attr_data(f, x)
                if isa(T, UnknownType)
                    str = typestring(T)
                    @warn("type $(str) does not exist in workspace; interpreting Array{$str} as Array{Any}")
                    T = Any
                end
                seek(io, startpos)
                return read_array(f, dataspace, ReadRepresentation{T,RelOffset}(),
                                  -1, UInt16(0), header_offset, attributes)
            end
        end
    elseif dataspace.dataspace_type == DS_NULL
        return read_empty(ReadRepresentation{Union{},nothing}(), f,
                          attributes[find_dimensions_attr(attributes)],
                          header_offset)
    end
    throw(UnsupportedFeatureException())
end

# Types with no payload can only be null dataspace
function read_data(f::JLDFile,
                   rr::Union{ReadRepresentation{T,nothing} where T,
                             ReadRepresentation{T,CustomSerialization{S,nothing}} where {S,T}},
                   attributes::Vector{ReadAttribute})
    dataspace, header_offset, data_length, filter_id = BOXED_READ_DATASPACE[]
    filter_id != 0 && throw(UnsupportedFeatureException())
    dataspace.dataspace_type == DS_NULL || throw(UnsupportedFeatureException())

    dimensions_attr_index = find_dimensions_attr(attributes)
    if dimensions_attr_index == 0
        jlconvert(rr, f, Ptr{Cvoid}(0), header_offset)
    else
        # dimensions attribute => array of empty type
        read_empty(rr, f, attributes[dimensions_attr_index], header_offset)
    end
end

function find_dimensions_attr(attributes::Vector{ReadAttribute})
    dimensions_attr_index = 0
    julia_type_attr_index = 0
    for i = 1:length(attributes)
        x = attributes[i]
        if x.name == :dimensions
            dimensions_attr_index = i
        end
    end
    dimensions_attr_index
end

function read_empty(rr::ReadRepresentation{T}, f::JLDFile,
                 dimensions_attr::ReadAttribute, header_offset::RelOffset) where T
    dimensions_attr.datatype_class == DT_FIXED_POINT || throw(UnsupportedFeatureException())

    io = f.io
    seek(io, dimensions_attr.dataspace.dimensions_offset)
    ndims = Int(read(io, Length))

    seek(io, dimensions_attr.datatype_offset)
    read(io, FixedPointDatatype) == h5fieldtype(f, Int64, Int64, Val{true}) || throw(UnsupportedFeatureException())

    seek(io, dimensions_attr.data_offset)
    v = construct_array(io, T, ndims)
    if isconcretetype(T)
        for i = 1:length(v)
            @inbounds v[i] = jlconvert(rr, f, Ptr{Cvoid}(0), header_offset)
        end
    end
    header_offset !== NULL_REFERENCE && (f.jloffset[header_offset] = WeakRef(v))
    v
end

get_ndims_offset(f::JLDFile, dataspace::ReadDataspace, attributes::Nothing) =
    (dataspace.dimensionality, dataspace.dimensions_offset)

function get_ndims_offset(f::JLDFile, dataspace::ReadDataspace, attributes::Vector{ReadAttribute})
    ndims = dataspace.dimensionality
    offset = dataspace.dimensions_offset
    if !isempty(attributes)
        for x in attributes
            if x.name == :dimensions
                (x.dataspace.dataspace_type == DS_SIMPLE &&
                 x.dataspace.dimensionality == 1) || throw(InvalidDataException())
                seek(f.io, x.dataspace.dimensions_offset)
                ndims = UInt8(read(f.io, Length))
                offset = x.data_offset
            end
        end
    end
    (ndims, offset)
end

"""
    construct_array{T}(io::IO, ::Type{T}, ndims::Int)

Construct array by reading `ndims` dimensions from `io`. Assumes `io` has already been
seeked to the correct position.
"""
function construct_array(io::IO, ::Type{T}, ndims::Int)::Array{T} where {T}
    if ndims == 1
        n = read(io, Int64)
        Vector{T}(undef, n)
    elseif ndims == 2
        d2 = read(io, Int64)
        d1 = read(io, Int64)
        Matrix{T}(undef, d1, d2)
    elseif ndims == 3
        d3 = read(io, Int64)
        d2 = read(io, Int64)
        d1 = read(io, Int64)
        Array{T,3}(undef, d1, d2, d3)
    else
        ds = reverse!(read!(io, Vector{Int64}(undef, ndims)))
        Array{T}(undef, tuple(ds...))
    end
end

function read_array(f::JLDFile, dataspace::ReadDataspace,
                    rr::ReadRepresentation{T,RR}, data_length::Int,
                    filter_id::UInt16, header_offset::RelOffset,
                    attributes::Union{Vector{ReadAttribute},Nothing}) where {T,RR}
    io = f.io
    data_offset = position(io)
    ndims, offset = get_ndims_offset(f, dataspace, attributes)
    seek(io, offset)
    v = construct_array(io, T, Int(ndims))
    header_offset !== NULL_REFERENCE && (f.jloffset[header_offset] = WeakRef(v))
    n = length(v)
    seek(io, data_offset)
    if filter_id == 1
        read_compressed_array!(v, f, rr, data_length)
    else
        read_array!(v, f, rr)
    end
    v
end

function payload_size_without_storage_message(dataspace::WriteDataspace, datatype::H5Datatype)
    sz = 6 + 4 + sizeof(dataspace) + 4 + sizeof(datatype) + length(dataspace.attributes)*sizeof(HeaderMessage)
    for attr in dataspace.attributes
        sz += sizeof(attr)
    end
    sz
end

function deflate_data(f::JLDFile, data::Array{T}, odr::S, wsession::JLDWriteSession) where {T,S}
    buf = Vector{UInt8}(undef, odr_sizeof(odr) * length(data))
    cp = Ptr{Cvoid}(pointer(buf))
    @simd for i = 1:length(data)
        @inbounds h5convert!(cp, odr, f, data[i], wsession)
        cp += odr_sizeof(odr)
    end
    transcode(ZlibCompressor, buf)
end

function write_dataset(f::JLDFile, dataspace::WriteDataspace, datatype::H5Datatype, odr::S, data::Array{T}, wsession::JLDWriteSession) where {T,S}
    io = f.io
    datasz = odr_sizeof(odr) * numel(dataspace)
    layout_class = datasz < 8192 ? LC_COMPACT_STORAGE :
                   f.compress ? LC_CHUNKED_STORAGE : LC_CONTIGUOUS_STORAGE
    psz = payload_size_without_storage_message(dataspace, datatype)
    if datasz < 8192
        layout_class = LC_COMPACT_STORAGE
        psz += sizeof(CompactStorageMessage) + datasz
    elseif f.compress && isconcretetype(T) && isbitstype(T)
        layout_class = LC_CHUNKED_STORAGE
        psz += chunked_storage_message_size(ndims(data)) + length(DEFLATE_PIPELINE_MESSAGE)
    else
        layout_class = LC_CONTIGUOUS_STORAGE
        psz += sizeof(ContiguousStorageMessage)
    end
    fullsz = sizeof(ObjectStart) + size_size(psz) + psz + 4

    header_offset = f.end_of_data
    seek(io, header_offset)
    f.end_of_data = header_offset + fullsz

    if !isa(wsession, JLDWriteSession{Union{}})
        wsession.h5offset[objectid(data)] = h5offset(f, header_offset)
        push!(wsession.objects, data)
    end

    cio = begin_checksum_write(io, fullsz - 4)
    write_object_header_and_dataspace_message(cio, f, psz, dataspace)
    write_datatype_message(cio, datatype)

    # Data storage layout
    if layout_class == LC_COMPACT_STORAGE
        write(cio, CompactStorageMessage(datasz))
        if datasz != 0
            write_data(cio, f, data, odr, datamode(odr), wsession)
        end
        write(io, end_checksum(cio))
    elseif layout_class == LC_CHUNKED_STORAGE
        write(cio, DEFLATE_PIPELINE_MESSAGE)
        deflated = deflate_data(f, data, odr, wsession)
        write_chunked_storage_message(cio, odr_sizeof(odr), size(data), length(deflated), h5offset(f, f.end_of_data))
        write(io, end_checksum(cio))

        f.end_of_data += length(deflated)
        write(io, deflated)
    else
        write(cio, ContiguousStorageMessage(datasz, h5offset(f, f.end_of_data)))
        write(io, end_checksum(cio))

        f.end_of_data += datasz
        write_data(io, f, data, odr, datamode(odr), wsession)
    end

    h5offset(f, header_offset)
end

function write_dataset(f::JLDFile, dataspace::WriteDataspace, datatype::H5Datatype, odr::S, data, wsession::JLDWriteSession) where S
    io = f.io
    datasz = odr_sizeof(odr) * numel(dataspace)
    psz = payload_size_without_storage_message(dataspace, datatype) + sizeof(CompactStorageMessage) + datasz
    fullsz = sizeof(ObjectStart) + size_size(psz) + psz + 4

    header_offset = f.end_of_data
    seek(io, header_offset)
    f.end_of_data = header_offset + fullsz

    if ismutabletype(typeof(data)) && !isa(wsession, JLDWriteSession{Union{}})
        wsession.h5offset[objectid(data)] = h5offset(f, header_offset)
        push!(wsession.objects, data)
    end

    cio = begin_checksum_write(io, fullsz - 4)
    write_object_header_and_dataspace_message(cio, f, psz, dataspace)
    write_datatype_message(cio, datatype)
    write(cio, CompactStorageMessage(datasz))
    if datasz != 0
        write_data(cio, f, data, odr, datamode(odr), wsession)
    end
    write(io, end_checksum(cio))

    h5offset(f, header_offset)
end

function write_object_header_and_dataspace_message(cio::IO, f::JLDFile, psz::Int, dataspace::WriteDataspace)
    write(cio, ObjectStart(size_flag(psz)))
    write_size(cio, psz)

    # Fill value
    write(cio, HeaderMessage(HM_FILL_VALUE, 2, 0))
    write(cio, UInt8(3)) # Version
    write(cio, 0x09)     # Flags

    # Dataspace
    write(cio, HeaderMessage(HM_DATASPACE, sizeof(dataspace), 0))
    write(cio, dataspace)

    # Attributes
    for attr in dataspace.attributes
        write(cio, HeaderMessage(HM_ATTRIBUTE, sizeof(attr), 0))
        write_attribute(cio, f, attr, f.datatype_wsession)
    end
end

function write_datatype_message(cio::IO, datatype::H5Datatype)
    write(cio, HeaderMessage(HM_DATATYPE, sizeof(datatype), 1 | (2*isa(datatype, CommittedDatatype))))
    write(cio, datatype)
end

struct CompactStorageMessage
    hm::HeaderMessage
    version::UInt8
    layout_class::UInt8
    data_size::UInt16
end
define_packed(CompactStorageMessage)
@inline CompactStorageMessage(datasz::Int) =
    CompactStorageMessage(
            HeaderMessage(HM_DATA_LAYOUT, sizeof(CompactStorageMessage) - sizeof(HeaderMessage) + datasz, 0),
            4, LC_COMPACT_STORAGE, datasz
    )

struct ContiguousStorageMessage
    hm::HeaderMessage
    version::UInt8
    layout_class::UInt8
    address::RelOffset
    data_size::Length
end
define_packed(ContiguousStorageMessage)
@inline ContiguousStorageMessage(datasz::Int, offset::RelOffset) =
    ContiguousStorageMessage(
        HeaderMessage(HM_DATA_LAYOUT, sizeof(ContiguousStorageMessage) - sizeof(HeaderMessage), 0),
        4, LC_CONTIGUOUS_STORAGE, offset, datasz
    )

@inline chunked_storage_message_size(ndims::Int) =
    sizeof(HeaderMessage) + 5 + (ndims+1)*sizeof(Length) + 1 + sizeof(Length) + 4 + sizeof(RelOffset)
function write_chunked_storage_message(io::IO, elsize::Int, dims::NTuple{N,Int}, filtered_size::Int, offset::RelOffset) where N
    write(io, HeaderMessage(HM_DATA_LAYOUT, chunked_storage_message_size(N) - sizeof(HeaderMessage), 0))
    write(io, UInt8(4))                     # Version
    write(io, UInt8(LC_CHUNKED_STORAGE))    # Layout Class
    write(io, UInt8(2))                     # Flags (= SINGLE_INDEX_WITH_FILTER)
    write(io, UInt8(N+1))                   # Dimensionality
    write(io, UInt8(sizeof(Length)))        # Dimensionality Size
    for i = N:-1:1
        write(io, Length(dims[i]))          # Dimensions 1...N
    end
    write(io, Length(elsize))               # Element size (last dimension)
    write(io, UInt8(1))                     # Chunk Indexing Type (= Single Chunk)
    write(io, Length(filtered_size))        # Size of filtered chunk
    write(io, UInt32(0))                    # Filters for chunk
    write(io, offset)                       # Address
end

const DEFLATE_PIPELINE_MESSAGE = let
    io = IOBuffer()
    write(io, HeaderMessage(HM_FILTER_PIPELINE, 12, 0))
    write(io, UInt8(2))                 # Version
    write(io, UInt8(1))                 # Number of Filters
    write(io, UInt16(1))                # Filter Identification Value (= deflate)
    write(io, UInt16(0))                # Flags
    write(io, UInt16(1))                # Number of Client Data Values
    write(io, UInt32(5))                # Client Data (Compression Level)
    take!(io)
end

@Base.pure ismutabletype(x::DataType) = x.mutable

@inline function write_dataset(f::JLDFile, x, wsession::JLDWriteSession)
    odr = objodr(x)
    write_dataset(f, WriteDataspace(f, x, odr), h5type(f, x), odr, x, wsession)
end

@inline function write_ref_mutable(f::JLDFile, x, wsession::JLDWriteSession)
    offset = get(wsession.h5offset, objectid(x), RelOffset(0))
    offset != RelOffset(0) ? offset : write_dataset(f, x, wsession)::RelOffset
end

@inline write_ref_mutable(f::JLDFile, x, wsession::JLDWriteSession{Union{}}) =
    write_dataset(f, x, wsession)

function write_ref(f::JLDFile, x, wsession::JLDWriteSession)
    if ismutabletype(typeof(x))
        write_ref_mutable(f, x, wsession)::RelOffset
    else
        write_dataset(f, x, wsession)::RelOffset
    end
end
write_ref(f::JLDFile, x::RelOffset, wsession::JLDWriteSession) = x


text:
"""
An abstract package to be implemented by packages/people who create widgets/*dingetjes* for Pluto. If you are just happy using Pluto to make cool stuff, you probably don't want to use this package directly.

Take a look at [`PlutoAbstractDingetjes.Bonds`](@ref).
"""
module AbstractPlutoDingetjes

export Bonds, is_inside_pluto, is_supported_by_display

include_dependency("../Project.toml")

import Pkg
project_relative_path(xs...) = normpath(joinpath(dirname(dirname(pathof(@__MODULE__))), xs...))
p = Pkg.TOML.parsefile(project_relative_path("Project.toml"))

const MY_VERSION = VersionNumber(p["version"])

const _loaded_ref = Ref(false)
function __init__()
    _loaded_ref[] = true
end

"""
```julia
is_supported_by_display(io::IO, f::Union{Function,Module})::Bool
```

Check whether the current runtime/display (Pluto) supports a given feature from `AbstractPlutoDingetjes` (i.e. is the Pluto version new enough). This function should be used inside a `Base.show` method. The first argument should be the `io` provided to the `Base.show` method, and the second argument is the feature to check.

You can use this information to:
- Error the show method of your widget if the runtime/display does not support the required features, or
- Render a simpler version of your widget that does not depend on the advanced Pluto features.

# Example
```julia
import AbstractPlutoDingetjes: is_supported_by_display, Bonds

struct MyCoolDingetje
    values::Vector
end

function Base.show(io::IO, m::MIME"text/html", d::MyCoolDingetje)
    if !(is_supported_by_display(io, Bonds.initial_value) && is_supported_by_display(io, Bonds.transform_value))
        error("This widget does not work in the current version of Pluto.")
    end

    write(io, html"...")
end

```

See also: [`is_inside_pluto`](@ref).
"""
is_supported_by_display(io::IO, x::Any) = if !_loaded_ref[]
    error("`is_supported_by_display` can only be called inside a function, **after** your package has been imported. You can not call the function at top-level.")
else
    features = get(io, :pluto_supported_integration_features, [])
    x ∈ features
end

"""
```julia
is_inside_pluto()::Bool
```

Are we running inside a Pluto notebook?
"""
is_inside_pluto()::Bool = if !_loaded_ref[]
    error("`is_inside_pluto` can only be called inside a function, **after** your package has been imported. You can not call the function at top-level.")
else
    isdefined(Main, :PlutoRunner)
end
"""
```julia
is_inside_pluto(io::IO)::Bool
```

Are we rendering inside a Pluto notebook?

This function should be used inside a `Base.show` method, and the first argument should be the `io` provided to the `Base.show` method.
"""
is_inside_pluto(io::IO)::Bool = if !_loaded_ref[]
    error("`is_inside_pluto` can only be called inside a function, **after** your package has been imported. You can not call the function at top-level.")
else
    get(io, :is_pluto, false)
end

module Bonds
import ..AbstractPlutoDingetjes

export initial_value, transform_value, possible_values, validate_value
export NotGiven, InfinitePossibilities

"""
The initial value of a bond. In a notebook containing `@bind x my_widget`, this will be used in two cases:
1. The value of `x` will be set to `x = PlutoAbstractDingetjes.initial_value(my_widget)` during the `@bind` call. This initial value will be used in cells that use `x`, until the widget is rendered in the browser and the first value is received.
2. When running a notebook file without Pluto, e.g. `shell> julia my_notebook.jl`, this value will be used for `x`.

When not overloaded for your widget, it defaults to returning `missing`.

# Example
```julia
struct MySlider
    range::AbstractRange{<:Real}
end

Base.show(io::IO, m::MIME"text/html", s::MySlider) = show(io, m, HTML("<input type=range min=\$(first(s.values)) step=\$(step(s.values)) max=\$(last(s.values))>"))

PlutoAbstractDingetjes.Bonds.initial_value(s::MySlider) = first(s.range)

# Add the following for the same functionality on Pluto versions TODO and below. Will be ignored in future Pluto versions. See the compat info below.
Base.get(s::MySlider) = first(s.range)

```

!!! info "Note about `transform_value`"
    If you are also using [`transform_value`](@ref) for your widget, then the value returned by `initial_value` should be the value **after** transformation.

!!! compat "Pluto TODO"
    This feature only works in Pluto version TODO: NOT RELEASED YET or above.

    Older versions of Pluto used a `Base.get` overload for this (to avoid the need for the `AbstractPlutoDingetjes` package, but we changed our minds 💕). To support all versions of Pluto, use both methods of declaring the initial value.

    Use [`AbstractPlutoDingetjes.is_supported_by_display`](@ref) if you want to check support inside your widget.

"""
initial_value(bond::Any) = missing

"""
Transform a value received from the browser before assigning it to the bound julia variable. In a notebook containing `@bind x my_widget`, Pluto will run `x = PlutoAbstractDingetjes.Bonds.transform_value(my_widget, \$value_from_javascript)`. Without this hook, widgets in JavaScript can only return simple types (numbers, dictionaries, vectors) into bound variables.

When not overloaded for your widget, it defaults to returning the value unchanged, i.e. `x = \$value_from_javascript`.

# Example
```julia
struct MyVectorSlider
    values::Vector{<:Any} # note! a vector of arbitrary objects, not just numbers
end

Base.show(io::IO, m::MIME"text/html", s::MyVectorSlider) = show(io, m, HTML("<input type=range min=1 max=\$(length(s.values))>"))

PlutoAbstractDingetjes.Bonds.transform_value(s::MySlider, value_from_javascript::Int) = s.values[value_from_javascript]
```

!!! compat "Pluto TODO"
    This feature only works in Pluto version TODO: NOT RELEASED YET or above. Values are not transformed in older versions.

    Use [`AbstractPlutoDingetjes.is_supported_by_display`](@ref) if you want to check support inside your widget.

"""
transform_value(bond::Any, value_from_javascript::Any) = value_from_javascript

"`NotGiven()` is the default return value of `possible_values(::Any)`."
struct NotGiven end
"Return `InfinitePossibilities()` from your overload of [`possible_values`](@ref) to signify that your bond has no finite set of possible values."
struct InfinitePossibilities end

"""
The possible values of a bond. This is used when generating precomputed PlutoSliderServer states, see [https://github.com/JuliaPluto/PlutoSliderServer.jl/pull/29](https://github.com/JuliaPluto/PlutoSliderServer.jl/pull/29). Not relevant outside of this use (for now...).

The returned value should be an iterable object that you can call `length` on (like a `Vector` or a `Generator` without filter) or return [`InfinitePossibilities()`](@ref) if this set is inifinite.

# Examples
```julia
struct MySlider
    range::AbstractRange{<:Real}
end

Base.show(io::IO, m::MIME"text/html", s::MySlider) = show(io, m, HTML("<input type=range min=\$(first(s.values)) step=\$(step(s.values)) max=\$(last(s.values))>"))

PlutoAbstractDingetjes.Bonds.possible_values(s::MySlider) = s.range
```

```julia
struct MyTextBox end

Base.show(io::IO, m::MIME"text/html", s::MyTextBox) = show(io, m, HTML("<input type=text>"))

PlutoAbstractDingetjes.Bonds.possible_values(s::MySlider) = PlutoAbstractDingetjes.Bonds.InfinitePossibilities()
```

!!! info "Note about `transform_value`"
    If you are also using [`transform_value`](@ref) for your widget, then the values returned by `possible_values` should be the values **before** transformation.

!!! compat "Pluto TODO"
    This feature only works in Pluto version TODO: NOT RELEASED YET or above.

"""
possible_values(bond::Any) = NotGiven()

"""
Validate a value received from the browser before "doing the pluto thing". In a notebook containing `@bind x my_widget`, Pluto will run `PlutoAbstractDingetjes.Bonds.validate_value(my_widget, \$value_from_javascript)`. If the result is `false`, then the value from JavaScript is considered "invalid" or "insecure", and no further code will be executed.

This is a protection measure when using your widget on a public PlutoSliderServer, where people could write fake requests that set bonds to arbitrary values.

The returned value should be a `Boolean`.

# Example
```julia
struct MySlider
    range::AbstractRange{<:Real}
end

Base.show(io::IO, m::MIME"text/html", s::MySlider) = show(io, m, HTML("<input type=range min=\$(first(s.values)) step=\$(step(s.values)) max=\$(last(s.values))>"))

PlutoAbstractDingetjes.Bonds.validate_value(s::MySlider, x::Any) = x isa Real && first(s.range) <= x <= last(s.range)
```

!!! info "Note about `transform_value`"
    If you are also using [`transform_value`](@ref) for your widget, then the value validated by `validate_value` will be the value **before** transformation.

!!! warning
    Be sure to add a dispatch for `validate_value(s::MyWidget, x::Any)`, not just for `validate_value(s::MyWidget, x::ExpectedType)`, since this would return the fallback value `true` when `x` is not of the expected type.

!!! compat "Pluto TODO"
    This feature only works in Pluto version TODO: NOT RELEASED YET or above.

"""
validate_value(bond::Any, input::Any) = true

end

end


text:
"""

Create an MAPHDist of dimensions pxq where q is the length of `probs`, `means`, and `scvs` and p is specified.

This tries to do a best "moment fit" for the probability of absorbitions, means, and scvs

"""
function MAPHDist(p::Int, probs::Vector{Float64}, means::Vector{Float64}, scvs::Vector{Float64})
    @show "Constructor based on moments"

    q = length(probs)
    length(means) != q && error("Dimension mismatch")
    length(scvs) != q && error("Dimension mismatch")

    πhat_order = sortperm(probs)
    sorted_scvs = scvs[πhat_order]
    sorted_means = means[πhat_order]

    num_phases = [sorted_scvs[i] ≥ 1 ? 2 : ceil(1/sorted_scvs[i]) for i in 1:q]

    required_phases = sum(num_phases)
    K=0
    K = findfirst((x)->x ≤ p, [sum(num_phases[k:end]) for k=1:q])
    K ∉ (1:q) && error("Not enough phases to start")

    @show num_phases, K

    dist = []
    for k = 1:q
        if sorted_scvs[k]≥1
            push!(dist,hyper_exp_init(sorted_means[k],sorted_scvs[k]))
        end
        if sorted_scvs[k]<1
            push!(dist,hypo_exp_init(sorted_means[k],sorted_scvs[k]))
        end
    end

    α = zeros(p)'
    T = ones(p,p).*eps()
    T0 = ones(p,q).*eps()

    reverse_order = sortperm(πhat_order)

    reversed_dist = dist[reverse_order]

    if p ≥ required_phases
        α_temp, T_temp, T0_temp = merge_dist(probs,reversed_dist)
        m,n = model_size(MAPHDist(α_temp, T_temp, T0_temp))
        α[1:m] = α_temp
        T[1:m,1:m] = T_temp
        T0[1:m,1:n] = T0_temp
    else
        idx_drop = πhat_order[1:K-1]
        probs = probs[eachindex(probs) .∉ Ref(idx_drop)]
        reversed_dist = reversed_dist[eachindex(reversed_dist) .∉ Ref(idx_drop)]
        α_temp, T_temp, T0_temp = merge_dist(probs,reversed_dist)
        m,n = model_size(MAPHDist(α_temp, T_temp, T0_temp))
        α[1:m] =α_temp
        T[1:m,1:m] = T_temp
        T0[1:m,1:n]=T0_temp
    end

    ### fix T,T0 to be stochastic Matrix due to numerical error in the computation above

    excess = sum(T, dims = 2) + sum(T0, dims = 2)

    T = T + Diagonal(vec(excess))

    display(T)
    display(T0)

    maph = MAPHDist(α,T,T0)

    return maph

end

function q_matrix(d::MAPHDist)::Matrix{Float64}
    p, q = model_size(d)
    return [zeros(q,p) zeros(q,q) ; d.T0 d.T]
end

function p_matrix(d::MAPHDist)::Matrix{Float64}
    p, q = model_size(d)
    PT = I-inv(Diagonal(d.T))*d.T
    PT0 = -inv(Diagonal(d.T))*d.T0
    return [I zeros(q,p); PT0 PT]
end

function rand(d::MAPHDist; full_trace = false)
    p, q = model_size(d)
    transient_states = (q+1):(q+p)
    all_states = 1:(q+p)
    Pjump = p_matrix(d)
    Λ = vcat(zeros(q), -diag(d.T))

    if full_trace
        states = Int[]
        sojourn_times = Float64[]
    end

    state = sample(transient_states,weights(d.α)) #initial state
    t = 0.0
    while state ∈ transient_states
        sojourn_time = rand(Exponential(1/Λ[state]))
        if full_trace
            push!(states,state)
            push!(sojourn_times,sojourn_time)
        end
        t += sojourn_time
        state = sample(all_states,weights(Pjump[state,:]))
    end

    if full_trace
        push!(states,state)
        return (sojourn_times, states)
    else
        return (y = t, a = state)
    end
end


text:
using JuMP, EAGO

                     m = Model()

                     EAGO.register_eago_operators!(m)

                     @variable(m, -1 <= x[i=1:4] <= 1)

                     @variable(m, -41.21023060076703 <= q <= 39.01192102445897)

                     add_NL_constraint(m, :(1/(1 + exp(-(-0.296746779395487 + 0.5509866377924739*1/(1 + exp(-(-0.36537726371933 + -0.13236748618316563*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.8938439926067105*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.2026514795524368*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.4969096390589627*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))))))))) + -0.850208463612319*1/(1 + exp(-(-0.13805861779585626 + 0.8324190447258686*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.45691763611374503*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.0018061937798208305*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.06838129719944464*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))))))))) + 0.14361846152386626*1/(1 + exp(-(0.892089992500452 + -0.9262441239021939*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.1220711338530176*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.013243228467184842*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.22830737094249542*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))))))))) + 0.12455164844812394*1/(1 + exp(-(-0.09971606472325156 + 0.22050596868305217*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.9537528744420904*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.13795746696872868*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.0643190431003462*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))))))))) + 1/(1 + exp(-(-0.7906046812278151 + -0.2168623555923963*1/(1 + exp(-(-0.36537726371933 + -0.13236748618316563*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.8938439926067105*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.2026514795524368*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.4969096390589627*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))))))))) + 0.3937942437507238*1/(1 + exp(-(-0.13805861779585626 + 0.8324190447258686*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.45691763611374503*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.0018061937798208305*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.06838129719944464*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))))))))) + 0.013414887338259796*1/(1 + exp(-(0.892089992500452 + -0.9262441239021939*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.1220711338530176*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.013243228467184842*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.22830737094249542*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))))))))) + -0.20160941359718088*1/(1 + exp(-(-0.09971606472325156 + 0.22050596868305217*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.9537528744420904*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.13795746696872868*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.0643190431003462*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))))))))) + 1/(1 + exp(-(0.21825887860627402 + 0.23342217391611308*1/(1 + exp(-(-0.36537726371933 + -0.13236748618316563*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.8938439926067105*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.2026514795524368*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.4969096390589627*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))))))))) + 0.7638006108327029*1/(1 + exp(-(-0.13805861779585626 + 0.8324190447258686*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.45691763611374503*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.0018061937798208305*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.06838129719944464*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))))))))) + 0.4051674738413942*1/(1 + exp(-(0.892089992500452 + -0.9262441239021939*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.1220711338530176*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.013243228467184842*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.22830737094249542*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))))))))) + 0.17219310126869347*1/(1 + exp(-(-0.09971606472325156 + 0.22050596868305217*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.9537528744420904*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.13795746696872868*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.0643190431003462*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))))))))) + 1/(1 + exp(-(0.8210746038366681 + -0.06951431198870361*1/(1 + exp(-(-0.36537726371933 + -0.13236748618316563*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.8938439926067105*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.2026514795524368*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.4969096390589627*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))))))))) + 0.9856384884704164*1/(1 + exp(-(-0.13805861779585626 + 0.8324190447258686*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.45691763611374503*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.0018061937798208305*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.06838129719944464*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))))))))) + -0.2856111885860577*1/(1 + exp(-(0.892089992500452 + -0.9262441239021939*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.1220711338530176*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.013243228467184842*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.22830737094249542*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4])))))))))) + 0.04937870878523665*1/(1 + exp(-(-0.09971606472325156 + 0.22050596868305217*1/(1 + exp(-(0.24726246482452874 + -0.2513871312104543*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.4677853214537917*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + -0.10088601735084568*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.6507022966434817*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.9537528744420904*1/(1 + exp(-(0.30866893537934104 + -0.11067617174498023*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.7749548972944802*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.44318801341623093*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + 0.23547099627350976*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + -0.13795746696872868*1/(1 + exp(-(-0.39572563026399044 + -0.2902839675147266*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + 0.2975675315855191*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.808554335286296*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.2217074058396178*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))) + 0.0643190431003462*1/(1 + exp(-(0.8092602903578396 + -0.8861475410157751*1/(1 + exp(-(-0.7954573007956682 + 0.11924049292543248*$(x[1]) + 0.1731334424011517*$(x[2]) + -0.6758597754938092*$(x[3]) + 0.13301420625435734*$(x[4])))) + -0.38211269748902854*1/(1 + exp(-(-0.7274702539948783 + 0.17282628886946716*$(x[1]) + 0.018302754525115095*$(x[2]) + 0.800298561254523*$(x[3]) + -0.4821070372998202*$(x[4])))) + 0.47211467596801615*1/(1 + exp(-(-0.4299065646425082 + -0.1572016654178685*$(x[1]) + 0.08953552697871814*$(x[2]) + 0.5995804212147959*$(x[3]) + -0.3420773339437706*$(x[4])))) + -0.8428121402295612*1/(1 + exp(-(0.440020919910439 + 0.27581141739825465*$(x[1]) + 0.9904718804451909*$(x[2]) + -0.9775405312317109*$(x[3]) + 0.5010243235294203*$(x[4]))))))))))))) - $q <= 0.0))

                     @objective(m, Min, q)

                     return m

max_stars_repo_name: PSORLab/RSActivationFunctions

max_issues_repo_name: PSORLab/RSActivationFunctions

max_forks_repo_name: PSORLab/RSActivationFunctions


text:
include("mms.jl")

let

    year_seconds = 31556952

    # Domain length
    Lw = 40
    # Basin width
    W = 24#/40
    # Basin Depth
    D = 6#/40
    # simulation timespan

    # mesh refinement

    ns = 2 .^ (4:9)

    # order of operators
    p = [2, 4, 6]

    # Basin Params
    B_p = (μ_out = 24.0,
           ρ_out = 3.0,
           μ_in = 18.0,
           ρ_in = 2.6,
           c = (W/2)/D,
           r̄ = (W/2)^2,
           r_w = 40,
           on = 1)

    # Rate-and-State Friction Params`
    RS = (σn = 50.0,
          a = .015,
          b0 = .02,
          Dc = 1.0,
          f0 = .6,
          V0 = 1e-6,
          τ_inf = 31.73,
          Vp = 1e-9)

    #=
     MMS = (wl = Lw/2,
           amp = .5,
           ϵ = 4.00)
    =#
    # MMS params

    MMS = (Lw = Lw,
           t̄ = 35*year_seconds,
           t_w = 10,
           t_f = 70*year_seconds,
           τ∞ = 31.73,
           Vp = 1e-9,
           H = 8,#/40,
           Vmin = 1e-12,
           δ_e = 1e-9*(35*year_seconds) -
               (1e-12*(35*year_seconds)),
           ϵ = 2.0)

    refine(p, ns, Lw, D, B_p, RS, (-1, 0, 0, 1), MMS)

end


text:
# Executble for printing colors!

using Pkg
Pkg.activate(normpath(@__DIR__))

using ProjectMoana

function main(ARGS)
    if length(ARGS)==3 && 0 <= parse(Float32, ARGS[1]) <= 1 && 0 <= parse(Float32, ARGS[2]) <= 1 && 0 <= parse(Float32, ARGS[3]) <= 1
        a = (parse(Float32, ARGS[1]), parse(Float32, ARGS[2]), parse(Float32, ARGS[3]))
        b = round.(Int, a .* 255)
        printcol(b)
    else
        println("Pass me a RGB color \ne.g. 1.0 0.4 0.6")
    end
end

main(ARGS)