ScalingCollapse

Documentation for ScalingCollapse.

ScalingCollapse.DataType
Data(L::Int, xs::Vector{Float64}, ys::Vector{Float64}, es::Vector{Float64})

A Data object stores the data for a single system size. Sorted by the x values.

Fields

  • L::Int: system size
  • xs::Vector{Float64}: x values
  • ys::Vector{Float64}: y values
  • es::Vector{Float64}: y error values
source
ScalingCollapse.HoudayerType
Houdayer()

Quality function that uses the Houdayer & Hartmann method to calculate the quality of a scaling. It is less stable than the spline methods and the Linear method and therefore not recommended.

How does it work?

TO BE DOCUMENTED

source
ScalingCollapse.LinearType
Linear()

Quality function that interpolates all scaled data points to a single master curve. For every data point, we take the closest data points, to the left and to the right to interpolate a linear function. The quality is then calculated as the sum of the squared differences between the data points and the interpolated values.

source
ScalingCollapse.MultipleSplinesType
MultipleSplines(; N_steps::Int=100, weight_density::Bool=true)

Quality function that uses a spline interpolation to calculate the quality of a scaling.

How does it work?

TO BE DOCUMENTED

Keyword arguments

  • N_steps::Int=100: Number of points used in the interval to calculate the quality.
  • weight_density::Bool=true: If true, the quality is weighted by the density of data points in the interval.
source
ScalingCollapse.ScalingFunctionType
ScalingFunction(preset::Symbol; kwargs...)
ScalingFunction(f::Function; kwargs...)

A ScalingFunction is used in a ScalingProblem to rescale the data. It is defined by a function f and a set of parameters p_names. The function f is called with the data d and the parameters p1, p2, ... and returns a new Data object.

Arguments

  • preset::Symbol: a preset for the ScalingFunction. See Presets below.

  • f::Function: the function f to be used in the ScalingFunction. Pass this argument to create a custom ScalingFunction. f should take a Data object and a set of parameters p1, p2, ... and return a new Data object: f(d::Data, p1, p2, ...) -> Data.

    Note that you might want to set the function f as a keyword argument to use the "fixing parameters" feature (see below).

Presets

The preset argument can be used to create a ScalingFunction with a preset function f and a preset set of parameter names p_names. The following presets are available:

  • :x rescale the x values of the data according to x -> (x - p1)/p1 * L^(1/p2)
  • :xy rescale the x and y values of the data according to x -> (x - p1)/p1 * L^(1/p2) and y -> y * L^(p3/p2)
  • :xny rescale the x and y values of the data according to x -> (x - p1)/p1 * L^(1/p2) and y -> y * L^(-p3/p2)

Keyword arguments

  • p_names::Vector{String}: the parameter names p_names to be used in the ScalingFunction. This kwarg can be used to overwrite the preset parameter names p_names (p1, p2, ...).

  • f::Function: the function f to be used in the ScalingFunction. This kwarg can be used to overwrite the preset function f. If you pass f as a kwarg, instead of an argument, you can use the "fixing parameters" feature (see below). In that case the number of paramters of your function f should match the preset, i.e. if your function f takes 2 parameters, you should use the preset :x and if your function f takes 3 parameters, you should use the preset :xy.

  • x_scale::String: the scaling function for the x values. This is just used to display the scaling function in plots and julias show function.

  • y_scale::String: the scaling function for the y values. This is just used to display the scaling function in plots and julias show function.

  • p::Float64: fix a parameter to a value. If you know the analytical value of a scaling parameter you might want to fix it to this value. This can speed up the optimization and give better results. Note, that p is either "p1", "p2", ... or the name you specified in p_names.

    Note that this feature is only available if you use one of the presets. You can still modify the scaling function by setting f as a kwarg.

Examples

Presets

# rescale the x axis only
ScalingFunction(:x; p_names=["T_c", "nu"])

# lets fix nu to 1.0
ScalingFunction(:x; p_names=["T_c", "nu"], nu=1.0)

# rescale the x and y axis
ScalingFunction(:xy; p_names=["T_c", "nu", "beta"])

# rescale the x and y axis with negative exponent on y
ScalingFunction(:xny; p_names=["T_c", "nu", "gamma"])

Custom scaling function

# define the function that scales the data
function myfunction(d::ScalingCollapse.Data, p1, p2)

    #  initialize arrays for scaled data
    xs = zeros(length(d.xs))
    ys = zeros(length(d.ys))
    es = zeros(length(d.es))

    # scale data according to p1 and p2
    for (i, x, y, e) in zip(eachindex(d.xs), d.xs, d.ys, d.es)
        xs[i] = (x - p1) / p1 * log(d.L)
        ys[i] = y * d.L^(p2)
        es[i] = e * d.L^(p2)
    end

    # create new Data object with scaled data
    return ScalingCollapse.Data(d.L, xs, ys, es)
end

ScalingFunction(myfunction; p_names=["myp1", "myp2"])

# lets say we want to fix the parameter "myp1" to 1.0
# we use the preset :x (because it also has 2 parameters) and overwrite the function f
ScalingFunction(:x; f=myfunction, p_names=["myp1", "myp2"], myp1=1.0)
source
ScalingCollapse.ScalingProblemType
ScalingProblem(args...; kwargs...)

Create a scaling problem which solves on initialization.

Arguments

  • xs: x values of the data
  • ys: y values of the data
  • es: y error values of the data (optional)
  • Ls: system sizes of the data

For more information on the arguments, see methods(ScalingCollapse.unzip_data).

Keyword Arguments

  • sf::ScalingFunction=ScalingFunction(preset; kwargs...): scaling function
  • p_space::Vector{StepRangeLen}=[0.1:0.1:3.0 for _ in sf.p_names]: parameter search space
  • dx::Vector{Float64}=[-Inf, Inf]: optimization interval
  • quality::QualityFunction=Linear(): quality function
  • quality_scan::QualityFunction=MultipleSplines(scan_mode=true): quality function for the parameter space scan (it is highly recommended to use the default function here)
  • verbose::Bool=false: print information during optimization
  • starting_ps::Vector{Float64}: If starting_ps are given, there will be no initial parameter space scan. Instead, the optimization will start at the given points. This is much faster, but might not find the global minimum.
  • error::Bool=true: If error=true, the error analysis will be performed to give estimates of the uncertainties of the optimal parameters.

Fields

  • data::Vector{Data}: data to be scaled
  • sf::ScalingFunction: scaling function
  • p_space::Vector{StepRangeLen}: search parameter space
  • dx::Vector{Float64}: optimization interval
  • optimal_ps::Vector{Float64}: optimal parameters
  • optimal_ps_error::Vector{Float64}: uncertainties of the optimal parameters
  • minimum::Float64: minimum of the objective function
  • solved::Bool: true if optimization was called
  • verbose::Bool: print information during optimization
  • error::Bool: perform error analysis
  • quality_scan::QualityFunction: quality function for the parameter space scan
  • quality::QualityFunction: quality function
  • skip_scan::Bool: true if starting_ps are given by the user
  • starting_ps::Vector{Float64}: starting points for the optimization
  • errors_defined::Bool: true if errors are given by the user

Examples

using ScalingCollapse

rescale the x axis only

# (e.g. for ys == binder cumulant of Ising model)
ScalingProblem(xs, ys, Ls;
    sc=ScalingFunction(:x; p_names=["T_c", "nu"]),
    p_space=[0.1:0.1:3.0, 0.1:0.1:3.0],
    dx=[-1.0, 1.0],
)

# or the same but with errors
ScalingProblem(xs, ys, es, Ls;
    sc=ScalingFunction(:x; p_names=["T_c", "nu"]),
    p_space=[0.1:0.1:3.0, 0.1:0.1:3.0],
    dx=[-1.0, 1.0],
)

rescale the x and y axis

# (e.g. for ys == magnetization of Ising model)
ScalingProblem(xs, ys, Ls;
    sc=ScalingFunction(:xy; p_names=["T_c", "nu", "beta"]),
    dx=[-1.0, 1.0],
)

rescale the x and y axis, but y axis with negative exponent

# (e.g. for ys == susceptibility of Ising model)
ScalingProblem(xs, ys, Ls;
    sc=ScalingFunction(:xny; p_names=["T_c", "nu", "gamma"]),
    dx=[-1.0, 1.0],
)
source
ScalingCollapse.SingleSplineType
SingleSpline()

Quality function that interpolates all scaled data points to a single spline. The quality is then calculated as the sum of the squared differences between the data points and the interpolated values. The spline is fitted using the KissSmoothing.jl package. The number of knots can be specified using the N_knots keyword argument. If N_knots is not specified, the number of knots is set to total_number_of_data_points / 10.

source
ScalingCollapse.residualsMethod
residuals(sp; kwargs...)

Calculate the residuals of the ScalingProblem around the optimal parameters or for a given parameter space.

Arguments

  • sp::ScalingProblem: The ScalingProblem to calculate the residuals for.

Keyword Arguments

  • p_space::Vector{Vector{Float64}}: The parameter space to calculate the residuals for. If not provided, the parameter space is calculated from the optimal parameters, their errors and the number of steps.
  • N_steps::Int=50: The number of steps to use for the default parameter space.
  • dims::Vector{Int}=[1, ...]: The dimensions to calculate the residuals for. If not specified, all dimensions are used.

Returns

  • p_space::Vector{StepRangeLen}: The parameter space used for the calculation.
  • residuals::Array{Float64}: The residuals for the given parameter space.

Example

# lets say our xs, ys and Ls are data for the susceptibility of the Ising model
using ScalingCollapse
sp = ScalingProblem(xs, ys, Ls;
    sc=ScalingFunction(:xny; p_names=["T_c", "nu", "gamma"]),
    dx=[-1.0, 2.0],
)

# now we can calculate the residual landscape around the optimal parameters as follows:
p_space, residuals = residuals(sp)
# in the above case length(p_space) == 3 and size(residuals) == (50, 50, 50)

# we can specify the dimensions we are interested in as follows:
p_space, residuals = residuals(sp; dims=[1, 2])
# now length(p_space) == 2 and size(residuals) == (50, 50)
# we fixed the third parameter (in this case gamma) to its optimal value and calculated
# a 2D cut through the 3D residual landscape
source
ScalingCollapse.scaled_dataMethod
scaled_data(sp::ScalingProblem)
scaled_data(sp::ScalingProblem, ps)

Return the scaled data of the ScalingProblem sp.

Arguments

  • sp::ScalingProblem: scaling problem
  • ps::Vector{Float64}=sp.optimal_ps: parameters to scale the data with (manually)

Returns

  • xs::Vector{Vector{Float64}}: scaled x values
  • ys::Vector{Vector{Float64}}: scaled y values
  • es::Vector{Vector{Float64}}: scaled y error values
  • Ls::Vector{Float64}: scaled system sizes
source