Skip to content

Commit

Permalink
fitting and plotting code
Browse files Browse the repository at this point in the history
  • Loading branch information
jkott committed Mar 12, 2023
1 parent 6a53771 commit 12f0953
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 0 deletions.
69 changes: 69 additions & 0 deletions cumulant_parameters.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
cd(@__DIR__)

using Interpolations
using DelimitedFiles
using StaticArrays
using LinearAlgebra
using LaTeXStrings
using PlotThemes
using Plots
using Optim

include("data/data_c2_32.jl")

interp_linear1 = LinearInterpolation(t_1, c2_1)
err_linear1 = LinearInterpolation(t_1, c2_1_err)

interp_linear2 = LinearInterpolation(t_2, c2_2)
err_linear2 = LinearInterpolation(t_2, c2_2_err)

interp_linear3 = LinearInterpolation(t_3, c2_3)
err_linear3 = LinearInterpolation(t_3, c2_3_err)


xs = collect(-40:0.1:40)

function minimize(x)
return sum(
.+ abs.(interp_linear1.(xs) .- interp_linear2.(xs*2^x[1])/2^x[2])
.+ abs.(interp_linear1.(xs) .- interp_linear3.(xs*4^x[1])/4^x[2])
)
end

initial_x=[0.7,0.3]
res=optimize(minimize, initial_x)

Optim.summary(res)
param=Optim.minimizer(res)
println(param)

function scatter_style(xl,yl)
scatter!(
ylabel=yl, xlabel=xl,
grid = :off,
box = :on,
foreground_color_legend = nothing,
fontfamily = "serif-roman",
font="CMU Serif",
xtickfontsize = 10,
ytickfontsize = 10,
xguidefontsize = 10,
yguidefontsize = 10,
thickness_scaling=1.5,
legendfontsize=10,
markersize=0.7,
legend=:topleft,
)
end

plotlims = (-50,100)
xplot_1 = collect(plotlims[1]:0.1:plotlims[2])
xplot_2 = collect(plotlims[1]*2^param[1]:0.1:plotlims[2]*2^param[1])
xplot_3 = collect(plotlims[1]*4^param[1]:0.1:plotlims[2]*4^param[1])
yscale(i) = interp_linear1(0) * 2^((i-1)*param[2])

plot(xplot_1, interp_linear1.(xplot_1)/yscale(1), fillalpha=0.1, ribbon=err_linear1.(xplot_1)/yscale(1), label=L"\hat \tau_Q=1")
plot!(xplot_2/2^param[1], interp_linear2.(xplot_2)/yscale(2), fillalpha=0.1, ribbon=err_linear2.(xplot_2)/yscale(2), label=L"\hat\tau_Q=2")
plot!(xplot_3/4^param[1], interp_linear3.(xplot_3)/yscale(3), fillalpha=0.1, ribbon=err_linear3.(xplot_3)/yscale(3), label=L"\hat\tau_Q=4")
scatter_style(L"\bar t/\hat\tau_Q^{p_1}", L"\hat c_2(\bar t,\tau_Q)/\hat \tau_Q^{p_2}")
savefig("plots/cumulant_fit.pdf")
77 changes: 77 additions & 0 deletions cumulant_plot.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
cd(@__DIR__)

using Plots
using ColorSchemes
using Statistics
using LaTeXStrings
using DelimitedFiles
using LsqFit
using Interpolations
using Optim

L = 32
const λ = 4.0e0
const Γ = 1.0e0
const T = 1.0e0
const z = 3.906e0

const Δt = 0.04e0/Γ
const Rate = Float64(sqrt(2.0*Δt*Γ))

# KZ protocol variables
const m²c, m²0, m²e = -2.28587, -2.0e0, -3.0e0
m_a, m_b = begin
τ_R = 2 * 10^-3 * L^z
τ_Q = τ_R

m²c/τ_Q, m²0
end

# In units of time
t_c = (m²c - m_b) / m_a
t_e = (m²e - m_b) / m_a
##

function time_axis(m, i)
t = (m .- m_b) / (m_a / i)
t_ce = t_c * i
t = t / t_ce
t
end

function scatter_style(xl,yl)
scatter(
ylabel=yl, xlabel=xl,
grid = :off,
box = :on,
foreground_color_legend = nothing,
fontfamily = "serif-roman",
font="CMU Serif",
xtickfontsize = 10,
ytickfontsize = 10,
xguidefontsize = 10,
yguidefontsize = 10,
thickness_scaling=1.5,
legendfontsize=10,
markersize=1,
legend=:topleft
)
end

include("data/data_c2_32.jl")

p = palette(:Set1_5)

df = readdlm("data/sum_1.dat", ' ')
m_1 = df[:,2]
df = readdlm("data/sum_2.dat", ' ')
m_2 = df[:,2]
df = readdlm("data/sum_3.dat", ' ')
m_3 = df[:,2]

scatter_style(L"t/t_c", L"c_2(t)")
plot!(time_axis(m_1, 1), c2_1, fillalpha=0.1, ribbon=c2_1_err, label=L"\hat\tau_Q=1")
plot!(time_axis(m_2, 2), c2_2, fillalpha=0.1, ribbon=c2_2_err, label=L"\hat\tau_Q=2")
plot!(time_axis(m_3, 4), c2_3, fillalpha=0.1, ribbon=c2_3_err, label=L"\hat\tau_Q=4")

savefig("plots/c2_t.pdf")
80 changes: 80 additions & 0 deletions dynamic_exp.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
cd(@__DIR__)

using LsqFit
using Plots
using LaTeXStrings

include("data/data_8.jl")
include("data/data_12.jl")
include("data/data_16.jl")
include("data/data_24.jl")

L = [8, 12, 16, 24]
t = [t_8, t_12, t_16, t_24]
C = [C_8, C_12, C_16, C_24]
C_err = [Cerr_8, Cerr_12, Cerr_16, Cerr_24]
τ = zeros(length(L))
τ_err = zeros(length(L))

for i in 1:length(L)
C_err[i] = C_err[i] / C[i][1]
C[i] = C[i] / C[i][1]
end

m(t,p) = exp.(p[1]*t)
p0 = [-0.1]

for i in 1:length(L)
fit = curve_fit(m, t[i], C[i], p0)
τ[i] = -inv(fit.param[1])
τ_err[i] = stderror(fit)[1]
end

fit_fn(t,p) = p[2] .+ p[1] * t

z_fit = curve_fit(fit_fn, log.(L), log.(τ), [4.0, 0.0])
(z, c) = z_fit.param
z_err = stderror(z_fit)[1]

c_err = exp(stderror(z_fit)[2])
println(c*(1-c_err))

scatter(log.(L), log.(τ), legend=:topleft, label="")
plot!(log.(L[[1,end]]), c.+z.*log.(L[[1,end]]),
legend=nothing,
foreground_color_legend=nothing,
grid=:off,
box=:on,
fontfamily = "serif-roman",
xtickfontsize = 10,
ytickfontsize = 10,
xguidefontsize = 10,
yguidefontsize = 10,
thickness_scaling=1.5,
legendfontsize=5,
markersize=1)
xlabel!(L"\ln\, L")
ylabel!(L"\ln\, \tau")
savefig("plots/z_fit_B.pdf")

scatter(xlabel=L"t/L^z",
ylabel=L"G(t,|k|=2\pi/L)/\chi",
foreground_color_legend=nothing,
grid=:off,
box=:on,
fontfamily = "serif-roman",
xtickfontsize = 10,
ytickfontsize = 10,
xguidefontsize = 10,
yguidefontsize = 10,
thickness_scaling=1.5,
legendfontsize=10,
xticks = [0.0, 0.0025, 0.005, 0.0075, 0.01],
xlims = [0, 0.012]
)

for i in eachindex(L)
plot!(t[i]/L[i]^z, C[i], ribbon = C_err[i], label=L"L=%$(L[i])", fillalpha = 0.2)
end

savefig("plots/Ck1.pdf")

0 comments on commit 12f0953

Please sign in to comment.