Numssp.jl

Author brianyjtai1994
Popularity
0 Stars
Updated Last
2 Years Ago
Started In
August 2020

Numssp

Numssp.jl is a numerical package for the daily routines of my solid state physics (SSP) experiments.

1. Optimization and Root Finding

Based on the implementation of the WCSCA solver, the following functionality is provided.

1.1 Function Minimization (Root Finding)

minimize!(fn!::Function, lb::NTuple{ND,T}, ub::NTuple{ND,T}[, NP::Int, NR::Int, imax::Int, dmax::T])

where:

  • fn! is the objective function to be minimized.
  • lb and ub are the lower/upper boundaries to define the feasible region to be minimized.
  • NP is the popuplation size for WCSCA (optional).
  • NR is the number of splitting in two subpopulations (optional).
  • imax is the maximum iteration of WCSCA evolution (optional).
  • dmax is the criterion distance between candidates to start a stagnation treatment (optional).

The objective function fn! should be defined as:

function fn!(params::Vector{T}) where T
    # body ...
end

A simple way to conduct a minimization is:

res = minimize!(fn!, lb, ub)

and use:

  • res.x to access the optiomized parameters.
  • res.f to access the corresponding function value.

1.2 Least-Square and χ² Curve Fitting

A χ² curve fitting is described as:

, when all of σ are 1.0 is a least-squrea curve fitting.

To conduct:

  • χ² curve fitting by passing (xdat, ydat, σdat, lb, ub).
  • least-square curve fitting by passing (xdat, ydat, lb, ub).

where

  • xdat::Vector{T} is the x-raw data
  • ydat::Vector{T} is the y-raw data
  • σdat::Vector{T} is the σ-raw data

Available fitting models are described as below:

Multi-Exponential Decay

res = decay_fit(xdat, ydat[, σdat], lb, ub)

Gaussian Distribution

res = gauss_fit(xdat, ydat[, σdat], lb, ub)

Lorentzian Distribution

res = lorentz_fit(xdat, ydat[, σdat], lb, ub)

2. Unit Conversion

A functionality of unit conversion, by using

@unit_convert x "unit_1"=>"unit_2"

where x can be any <:Real number or AbstractVector{<:Real}. Currently, the following conversion is provided:

  • "thz", "nj": terahertz <=> nanojoul
  • "thz", "meV": terahertz <=> milli-electron volt
  • "nm", "nj": nanometer <=> nanojoul
  • "nm", "eV": nanometer <=> electron volt
  • "cm⁻¹", "nm": reciprocal wavelength <=> nanometer
  • "ps", "μm": picosecond <=> micrometer

3. Some Customized Function for PyPlot

  • For setting of using LaTeX and fontsize:

    using PyPlot
    set_rcParams!(rc, PyPlot.PyDict(PyPlot.matplotlib."rcParams"), fontsize=12)
  • For setting ticklabels of specific direction:

    set_ticklabels!(axis, tick_start, tick_end, tick_step, direction, pad=true)

    where tick_start:tick_step:tick_end can be both Int or Float64, direction should be :x, :y, :z.

    If you have used

    axis[:set_xticks](..., ...)
    axis[:set_yticks](..., ...)
    axis[:set_zticks](..., ...)

    then pad should be passed by false.

  • For saving a pdf format figure:

    save_pdf(file_name, fig)