{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "42772387",
   "metadata": {
    "vscode": {
     "languageId": "r"
    }
   },
   "source": [
    "## Dynamics : Glauber-Metropolis comparisons\n",
    "\n",
    "A table as an output.  \n",
    "\n",
    "* Scaling Power-laws Kappa. Temperature and fields. \n",
    "* Diffusion coefficients over temperatures and fields.\n",
    "* Scaling Power-laws distribution of Gamma over temperatures.\n",
    "* Magnetisation Autocorrelations over temperatures. \n",
    "\n",
    "Two-sided Kolmogorov-Simirnov test.\n",
    "\n",
    "D < 0.1\tVery small difference — samples are very similar\n",
    "0.1 ≤ D < 0.2\tSmall to moderate difference — possibly negligible in practice\n",
    "0.2 ≤ D < 0.3\tModerate difference — may be meaningful\n",
    "D ≥ 0.3\tLarge difference — suggests the distributions differ significantly"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "79aaa7c7",
   "metadata": {
    "vscode": {
     "languageId": "r"
    }
   },
   "source": [
    "## Summar of Result\n",
    "\n",
    "\n",
    "We will combine them to a dataframe and write to a latex table. \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "01998f1d",
   "metadata": {
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "\n",
    "get_ks_on_alpha <- function(pLaws, N, type_power_law=\"Time Temperature Range\") {\n",
    "    df <- pLaws[pLaws[\"N\"]==N,]\n",
    "    df_metro  <- df[df['dynamics'] == \"Metropolis\",]\n",
    "    df_glauber <- df[df['dynamics'] == \"Glauber\",]\n",
    "    a1 <- as.numeric(df_metro['alpha_mean']$alpha_mean)\n",
    "    a2 <- as.numeric(df_glauber['alpha_mean']$alpha_mean)\n",
    "    kt <- ks.test(a1, a2)\n",
    "    list(\"type_power_law\"=type_power_law, \"N\"=N, \"D\"=kt$statistic, \"pvalue\"=kt$p.value, \"parameter\"=\"alpha scale\")\n",
    "}\n",
    "\n",
    "get_ks_on_C <- function(pLaws, N, type_power_law=\"Time Temperature Range\") {\n",
    "    df <- pLaws[pLaws[\"N\"]==N,]\n",
    "    df_metro  <- df[df['dynamics'] == \"Metropolis\",]\n",
    "    df_glauber <- df[df['dynamics'] == \"Glauber\",]\n",
    "    a1 <- as.numeric(df_metro['C_mean']$C_mean)\n",
    "    a2 <- as.numeric(df_glauber['C_mean']$C_mean)\n",
    "    kt <- ks.test(a1, a2)\n",
    "    list(\"type_power_law\"=type_power_law, \"N\"=N, \"D\"=kt$statistic, \"pvalue\"=kt$p.value, \"parameter\"=\"C diffusion\")\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf52fbb0",
   "metadata": {
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "## Scaling Power-laws Kappa Temperature Distribution\n",
    "pLaws <- readRDS(\"../datasets/ising1DrateErgodicityPowerlawsDistribution.rds\")\n",
    "df <- as.data.frame(get_ks_on_alpha(N=512, pLaws, type_power_law=\"Distribution Temperature Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_alpha(N=1024, pLaws, type_power_law=\"Distribution Temperature Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_alpha(N=1536, pLaws, type_power_law=\"Distribution Temperature Range\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6663f124",
   "metadata": {
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "## Scaling Power-laws Kappa Field Distribution\n",
    "pLaws <- readRDS(\"../datasets/ising1DrateErgodicityPowerlawsDistributionFields.rds\")\n",
    "df <- rbind.data.frame(df, get_ks_on_alpha(N=512, pLaws, type_power_law=\"Distribution Field Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_alpha(N=1024, pLaws, type_power_law=\"Distribution Field Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_alpha(N=1536, pLaws, type_power_law=\"Distribution Field Range\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a00b867",
   "metadata": {
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "## Scaling Power-laws Kappa Temperature Time\n",
    "pLaws <- readRDS(\"../datasets/ising1DrateErgodicityPowerlawsTime.rds\")\n",
    "df <- rbind.data.frame(df, get_ks_on_alpha(N=512, pLaws, type_power_law=\"Time Temperature Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_alpha(N=1024, pLaws, type_power_law=\"Time Temperature  Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_alpha(N=1536, pLaws, type_power_law=\"Timer Temperature Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_C(N=512, pLaws, type_power_law=\"Time Temperature Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_C(N=1024, pLaws, type_power_law=\"Time Temperature  Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_C(N=1536, pLaws, type_power_law=\"Timer Temperature Range\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f72ce7eb",
   "metadata": {
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "## Scaling Power-laws Kappa Field Time\n",
    "pLaws <- readRDS(\"../datasets/ising1DrateErgodicityPowerlawsTimeFields.rds\")\n",
    "df <- rbind.data.frame(df, get_ks_on_alpha(N=512, pLaws, type_power_law=\"Time Field Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_alpha(N=1024, pLaws, type_power_law=\"Time Field  Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_alpha(N=1536, pLaws, type_power_law=\"Time Field Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_C(N=512, pLaws, type_power_law=\"Time Field Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_C(N=1024, pLaws, type_power_law=\"Time Field  Range\"))\n",
    "df <- rbind.data.frame(df, get_ks_on_C(N=1536, pLaws, type_power_law=\"Time Field Range\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3369a42f",
   "metadata": {
    "vscode": {
     "languageId": "r"
    }
   },
   "outputs": [],
   "source": [
    "library(Hmisc)\n",
    "rownames(df) <- NULL\n",
    "latex(df, file=\"../tables/metropolis_glauber_ks_tests.latex\") "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "4.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
