├── .Rbuildignore ├── LICENCE.note ├── R ├── isingUtils.R ├── isingLibR.R └── isingLibWrapper.R ├── man ├── genUniform.Rd ├── transferMatrix.Rd ├── sumVec.Rd ├── sumVec_R.Rd ├── genConfig1D.Rd ├── genConfig1D_R.Rd ├── lattice1DenergyNN_R.Rd ├── lattice1DenergyNN.Rd ├── flipConfig1D.Rd ├── flipConfig1D_R.Rd ├── totalEnergy1D.Rd ├── totalEnergy1D_R.Rd ├── flipConfig1Dmany.Rd ├── transitionProbability1D_R.Rd ├── isStep1D.Rd ├── transitionProbability1D.Rd └── isPerform1D.Rd ├── inst ├── CITATION └── examples │ ├── effectiveErgodicity │ ├── README.md │ ├── run.R │ ├── isingErgodicity.R │ └── plotData.R │ └── powerLawErgodicity │ ├── README.md │ ├── data_generate.ipynb │ └── data_analysis.ipynb ├── NAMESPACE ├── NEWS ├── DESCRIPTION ├── README.md ├── src └── isingLib.c ├── vignettes └── isingLenzMC.Rnw └── GPL-3 /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^\.travis\.yml$ 2 | ^\README\.md$ 3 | -------------------------------------------------------------------------------- /LICENCE.note: -------------------------------------------------------------------------------- 1 | This software is distributed under the terms of the GNU General Public 2 | License as published by the Free Software Foundation; either version 3 3 | of the License, or (at your option) any later version. 4 | 5 | A copy of the GNU General Public License version 3 is in file GPL-3 in the 6 | sources of this package, and is also available at 7 | http://www.r-project.org/Licenses/ 8 | -------------------------------------------------------------------------------- /R/isingUtils.R: -------------------------------------------------------------------------------- 1 | # 2 | # Ising Model MC functions 3 | # Utility functions 4 | # (c) 2013 by Dr.Mehmet Suzen 5 | # GPLv3 or higher 6 | # 7 | 8 | # 9 | # Bexter 1982, eq 2.1.9 10 | transferMatrix <- function(ikBt, J, H) { 11 | K <- J*ikBt 12 | h <- H*ikBt 13 | tm <- c(exp(K+h),exp(-K), exp(-K), exp(K-h)) 14 | tm <- matrix(tm, 2, 2) 15 | list(tm=tm, evalues=eigen(tm)$values) 16 | } 17 | -------------------------------------------------------------------------------- /man/genUniform.Rd: -------------------------------------------------------------------------------- 1 | \name{genUniform} 2 | \alias{genUniform} 3 | \title{Get uniformly a spin state} 4 | \usage{ 5 | genUniform(n) 6 | } 7 | \arguments{ 8 | \item{n}{dummy argument} 9 | } 10 | \value{ 11 | Returns randomly 1 or -1 from uniform distribution. 12 | } 13 | \description{ 14 | Generate a single spin state from uniform distribution. 15 | } 16 | \examples{ 17 | genUniform() 18 | } 19 | \author{ 20 | Mehmet Suzen 21 | } 22 | -------------------------------------------------------------------------------- /man/transferMatrix.Rd: -------------------------------------------------------------------------------- 1 | \name{transferMatrix} 2 | \alias{transferMatrix} 3 | \title{Compute theoretical transfer matrix} 4 | \usage{ 5 | transferMatrix(ikBt, J, H) 6 | } 7 | \arguments{ 8 | \item{ikBt}{1/kB*T (Boltzmann factor)} 9 | \item{J}{Interaction strength} 10 | \item{H}{External field} 11 | } 12 | \value{ 13 | Returns transfer matrix and its eigenvalues in a pair list. 14 | } 15 | \description{ 16 | Compute transfer matrix 17 | } 18 | \examples{ 19 | transferMatrix(1.0, 1.0, 0) 20 | } 21 | \author{ 22 | Mehmet Suzen 23 | } 24 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | year <- sub("-.*", "", meta$Date) 2 | note <- sprintf("R package version %s", meta$Version) 3 | 4 | bibentry(bibtype = "Article", 5 | title = "Effective ergodicity in single-spin-flip dynamics", 6 | author = c(person("Mehmet", "Suezen")), 7 | number = 90, 8 | pages = 032141, 9 | journal = "Phys. Rev. E", 10 | year = 2014) 11 | 12 | bibentry(bibtype = "unpublished", 13 | title = "Anomalous diffusion in convergence to effective ergodicity", 14 | author = c(person("Mehmet", "Suezen")), 15 | note = "pre-print", 16 | url = "https://arxiv.org/abs/1606.08693") 17 | -------------------------------------------------------------------------------- /man/sumVec.Rd: -------------------------------------------------------------------------------- 1 | \name{sumVec} 2 | \alias{sumVec} 3 | \title{Sum given vector} 4 | \usage{ 5 | sumVec(x) 6 | } 7 | \arguments{ 8 | \item{x}{1D Spin sites on the lattice} 9 | } 10 | \value{ 11 | Returns the sum, corresponding the long-range part. 12 | } 13 | \description{ 14 | Given a vector of flip sites, 1s or -1s, representing up and down spins 15 | respectively, return the sum. This function calls the C function 'sumVec'. 16 | } 17 | \examples{ 18 | n <- 10 # 10 spin sites 19 | mySites <- genConfig1D(n) # Generate sites 20 | sumVecs <- sumVec(mySites) 21 | } 22 | \author{ 23 | Mehmet Suzen 24 | } 25 | -------------------------------------------------------------------------------- /man/sumVec_R.Rd: -------------------------------------------------------------------------------- 1 | \name{sumVec_R} 2 | \alias{sumVec_R} 3 | \title{Sum given vector} 4 | \usage{ 5 | sumVec_R(x) 6 | } 7 | \arguments{ 8 | \item{x}{1D Spin sites on the lattice} 9 | } 10 | \value{ 11 | Returns the sum, corresponding the long-range part. 12 | } 13 | \description{ 14 | Given a vector of flip sites, 1s or -1s, representing up and down spins 15 | respectively, return the sum. This function calls the C function 'sumVec'. 16 | } 17 | \examples{ 18 | n <- 10 # 10 spin sites 19 | mySites <- genConfig1D_R(n) # Generate sites 20 | sumVecs <- sumVec_R(mySites) 21 | } 22 | \author{ 23 | Mehmet Suzen 24 | } 25 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # import functions 2 | importFrom("stats", "runif") 3 | 4 | # Share Object 5 | useDynLib(isingLenzMC, .registration = TRUE) 6 | 7 | # .C wrapper functions 8 | export(genConfig1D) 9 | export(flipConfig1D) 10 | export(flipConfig1Dmany) 11 | export(lattice1DenergyNN) 12 | export(sumVec) 13 | export(totalEnergy1D) 14 | export(transitionProbability1D) 15 | export(isStep1D) 16 | export(isPerform1D) 17 | 18 | # Pure R functions 19 | export(genConfig1D_R) 20 | export(flipConfig1D_R) 21 | export(lattice1DenergyNN_R) 22 | export(sumVec_R) 23 | export(totalEnergy1D_R) 24 | export(transitionProbability1D_R) 25 | 26 | # Utility Functions 27 | export(genUniform) 28 | export(transferMatrix) 29 | -------------------------------------------------------------------------------- /man/genConfig1D.Rd: -------------------------------------------------------------------------------- 1 | \name{genConfig1D} 2 | \alias{genConfig1D} 3 | \title{Generate one dimensional spin sites randomly} 4 | \usage{ 5 | genConfig1D(n) 6 | } 7 | \arguments{ 8 | \item{n}{The number of spin sites on the lattice.} 9 | } 10 | \value{ 11 | Returns vector that contains 1s or -1s. 12 | } 13 | \description{ 14 | The function uses default RNG (Marsienne-Twister) unless changed by the 15 | user, within R, to generate a vector that contains 1 or -1. This reflects 16 | spin sites. This function calls 'genConfig1D' C function. 17 | } 18 | \examples{ 19 | n <- 10 # 10 spin sites 20 | genConfig1D(n) 21 | } 22 | \author{ 23 | Mehmet Suzen 24 | } 25 | -------------------------------------------------------------------------------- /man/genConfig1D_R.Rd: -------------------------------------------------------------------------------- 1 | \name{genConfig1D_R} 2 | \alias{genConfig1D_R} 3 | \title{Generate one dimensional spin sites randomly} 4 | \usage{ 5 | genConfig1D_R(n) 6 | } 7 | \arguments{ 8 | \item{n}{The number of spin sites on the lattice.} 9 | } 10 | \value{ 11 | Returns vector that contains 1s or -1s. 12 | } 13 | \description{ 14 | The function uses default RNG (Marsienne-Twister) unless changed by the 15 | user, within R, to generate a vector that contains 1 or -1. This reflects 16 | spin sites. This function is pure R implementation. 17 | } 18 | \examples{ 19 | n <- 10 # 10 spin sites 20 | genConfig1D_R(n) 21 | } 22 | \author{ 23 | Mehmet Suzen 24 | } 25 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | isinLenzMC 2 | 3 | 0.2.8 4 | * Updates in the description. 5 | * README.md: More links to examples and link to repo, as package source maybe be propagated. 6 | * NEWS file up-to-date. 7 | * Travis file is removed. 8 | * Minor improvements on Vignette `isingLenzMC.Rnw`. 9 | 10 | 0.2.7 11 | * zenedo datasets for the published works. 12 | 13 | 0.2.6 14 | * improved example for powerLawErgodicity, with notebooks and new size 1024. 15 | 16 | 0.2.5 17 | * A new example is added. 18 | under: inst/examples/powerLawErgodicity 19 | To support the work, see manuscript, https://arxiv.org/abs/1606.08693 20 | 21 | 0.2.4 22 | * Minor update 23 | 24 | 0.2.3 25 | * DESCRIPTION file update. 26 | * CITATION file added. 27 | * GPL-3 license file added. 28 | 29 | 0.2.2 30 | * Vignette fixed. PRE reference. 31 | 32 | -------------------------------------------------------------------------------- /man/lattice1DenergyNN_R.Rd: -------------------------------------------------------------------------------- 1 | \name{lattice1DenergyNN_R} 2 | \alias{lattice1DenergyNN_R} 3 | \title{Nearest-Neighbour energy in periodic boundary conditions in 1D} 4 | \usage{ 5 | lattice1DenergyNN_R(x) 6 | } 7 | \arguments{ 8 | \item{x}{1D Spin sites on the lattice} 9 | } 10 | \value{ 11 | Returns the nearest neighbour energy. 12 | } 13 | \description{ 14 | Given a vector of flip sites, 1s or -1s, representing up and down spins 15 | respectively, return nearest neighbour energy, applying periodic boundary 16 | conditions, i.e., cyclic. This function is a pure R implementation. 17 | } 18 | \examples{ 19 | n <- 10 # 10 spin sites 20 | mySites <- genConfig1D_R(n) # Generate sites 21 | nnEnergy <- lattice1DenergyNN(mySites) 22 | } 23 | \author{ 24 | Mehmet Suzen 25 | } 26 | -------------------------------------------------------------------------------- /inst/examples/effectiveErgodicity/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Effective ergodicity on the Ising model 3 | 4 | This is an example application of the package. 5 | Measuring ergodicity rate for the one dimensional 6 | ising Model. 7 | 8 | ## Reproducing the dataset and plots. 9 | 10 | `run.R` : Generate the data. 11 | `isingErgodicity.R` : Helper functions. 12 | `plotData.R` : Plot using the data (double check the directory identifications for data and plots). 13 | 14 | ## License. 15 | 16 | This project and all contributions are licensed under : 17 | * All non-code [![License: CC BY 4.0](https://i.creativecommons.org/l/by/4.0/88x31.png)](https://creativecommons.org/licenses/by/4.0/) 18 | * Code under [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) 19 | 20 | -------------------------------------------------------------------------------- /man/lattice1DenergyNN.Rd: -------------------------------------------------------------------------------- 1 | \name{lattice1DenergyNN} 2 | \alias{lattice1DenergyNN} 3 | \title{Nearest-Neighbour energy in periodic boundary conditions in 1D} 4 | \usage{ 5 | lattice1DenergyNN(x) 6 | } 7 | \arguments{ 8 | \item{x}{1D Spin sites on the lattice} 9 | } 10 | \value{ 11 | Returns the nearest neighbour energy. 12 | } 13 | \description{ 14 | Given a vector of flip sites, 1s or -1s, representing up and down spins 15 | respectively, return nearest neighbour energy, applying periodic boundary 16 | conditions, i.e., cyclic. This function calls the C function 'lattice1DenergyNN'. 17 | } 18 | \examples{ 19 | n <- 10 # 10 spin sites 20 | mySites <- genConfig1D(n) # Generate sites 21 | # now flip 22 | mySitesNew <- lattice1DenergyNN(mySites) 23 | } 24 | \author{ 25 | Mehmet Suzen 26 | } 27 | -------------------------------------------------------------------------------- /man/flipConfig1D.Rd: -------------------------------------------------------------------------------- 1 | \name{flipConfig1D} 2 | \alias{flipConfig1D} 3 | \title{Given Flip a site randomly} 4 | \usage{ 5 | flipConfig1D(x) 6 | } 7 | \arguments{ 8 | \item{x}{1D Spin sites on the lattice} 9 | } 10 | \value{ 11 | Returns vector that contains 1s or -1s. 12 | } 13 | \description{ 14 | Given a vector of flip sites, 1s or -1s, representing up and down spins 15 | respectively, flip any of the site randomly. The function uses default 16 | RNG (Marsienne-Twister) unless changed by the user, within R, to generate 17 | a vector that contains 1s or -1s. This function calls 'flipConfig1D' C function. 18 | } 19 | \examples{ 20 | n <- 10 # 10 spin sites 21 | mySites <- genConfig1D(n) # Generate sites 22 | # now flip 23 | mySitesNew <- flipConfig1D(mySites) 24 | } 25 | \author{ 26 | Mehmet Suzen 27 | } 28 | -------------------------------------------------------------------------------- /man/flipConfig1D_R.Rd: -------------------------------------------------------------------------------- 1 | \name{flipConfig1D_R} 2 | \alias{flipConfig1D_R} 3 | \title{Given Flip a site randomly} 4 | \usage{ 5 | flipConfig1D_R(x) 6 | } 7 | \arguments{ 8 | \item{x}{1D Spin sites on the lattice} 9 | } 10 | \value{ 11 | Returns vector that contains 1s or -1s. 12 | } 13 | \description{ 14 | Given a vector of flip sites, 1s or -1s, representing up and down spins 15 | respectively, flip any of the site randomly. The function uses default 16 | RNG (Marsienne-Twister) unless changed by the user, within R, to generate 17 | a vector that contains 1s or -1s. This function is a pure R implementation 18 | } 19 | \examples{ 20 | n <- 10 # 10 spin sites 21 | mySites <- genConfig1D_R(n) # Generate sites 22 | # now flip 23 | mySitesNew <- flipConfig1D_R(mySites) 24 | } 25 | \author{ 26 | Mehmet Suzen 27 | } 28 | -------------------------------------------------------------------------------- /man/totalEnergy1D.Rd: -------------------------------------------------------------------------------- 1 | \name{totalEnergy1D} 2 | \alias{totalEnergy1D} 3 | \title{Total energy in periodic boundary conditions in 1D} 4 | \usage{ 5 | totalEnergy1D(x, J, H) 6 | } 7 | \arguments{ 8 | \item{x}{1D Spin sites on the lattice.} 9 | \item{J}{The strength of interaction.} 10 | \item{H}{The value of the external field.} 11 | } 12 | \value{ 13 | Returns the total energy. 14 | } 15 | \description{ 16 | Given a vector of flip sites, 1s or -1s, representing up and down spins 17 | respectively, return total energy, applying periodic boundary 18 | conditions, i.e., cyclic. This function calls the C function 'totalEnergy1D'. 19 | } 20 | \examples{ 21 | n <- 10 # 10 spin sites 22 | mySites <- genConfig1D(n) # Generate sites 23 | # only short-range part 24 | myTotalEnergy <- totalEnergy1D(mySites, 1.0, 0.0) 25 | } 26 | \author{ 27 | Mehmet Suzen 28 | } 29 | -------------------------------------------------------------------------------- /man/totalEnergy1D_R.Rd: -------------------------------------------------------------------------------- 1 | \name{totalEnergy1D_R} 2 | \alias{totalEnergy1D_R} 3 | \title{Total energy in periodic boundary conditions in 1D} 4 | \usage{ 5 | totalEnergy1D_R(x, J, H) 6 | } 7 | \arguments{ 8 | \item{x}{1D Spin sites on the lattice.} 9 | \item{J}{The strength of interaction.} 10 | \item{H}{The value of the external field.} 11 | } 12 | \value{ 13 | Return the total energy. 14 | } 15 | \description{ 16 | Given a vector of flip sites, 1s or -1s, representing up and down spins 17 | respectively, return total energy, applying periodic boundary 18 | conditions, i.e., cyclic. This function is pure R implementation. 19 | } 20 | \examples{ 21 | n <- 10 # 10 spin sites 22 | mySites <- genConfig1D_R(n) # Generate sites 23 | # only short-range part 24 | myTotalEnergy <- totalEnergy1D_R(mySites, 1.0, 0.0) 25 | } 26 | \author{ 27 | Mehmet Suzen 28 | } 29 | -------------------------------------------------------------------------------- /man/flipConfig1Dmany.Rd: -------------------------------------------------------------------------------- 1 | \name{flipConfig1Dmany} 2 | \alias{flipConfig1Dmany} 3 | \title{Flip a single site randomly many times} 4 | \usage{ 5 | flipConfig1Dmany(x, upperF) 6 | } 7 | \arguments{ 8 | \item{x}{1D spin sites on the lattice.} 9 | \item{upperF}{The number of times} 10 | } 11 | \value{ 12 | Returns vector that contains 1s or -1s. 13 | } 14 | \description{ 15 | Given a vector of flip sites, 1s or -1s, representing up and down spins 16 | respectively, flip any of the site randomly, repeat it many times. 17 | The function uses default RNG (Marsienne-Twister) unless changed by the user, 18 | within R, to generate a vector that contains 1s or -1s. This function calls 19 | 'flipConfig1Dmany' C function. 20 | } 21 | \examples{ 22 | n <- 10 # 10 spin sites 23 | mySites <- genConfig1D(n) # Generate sites 24 | # now flip 100 times 25 | mySitesNew <- flipConfig1Dmany(mySites, 100) 26 | } 27 | \author{ 28 | Mehmet Suzen 29 | } 30 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: isingLenzMC 2 | Version: 0.2.8 3 | Date: 2025-09-25 4 | Title: Monte Carlo for Classical Ising Model 5 | Authors@R: c( 6 | person("Mehmet", "Suzen", 7 | email = "mehmet.suzen@physics.org", role = c("aut", "cre"))) 8 | Maintainer: Mehmet Suzen 9 | Depends: R (>= 3.0) 10 | NeedsCompilation: yes 11 | BuildVignettes: yes 12 | Description: Classical Ising Model is a land mark system in statistical physics.The model explains the physics of spin glasses and magnetic materials, and cooperative phenomenon in general, for example phase transitions and neural networks.This package provides utilities to simulate one dimensional Ising Model with Metropolis and Glauber Monte Carlo with single flip dynamics in periodic boundary conditions. Utility functions for exact solutions are provided. Such as transfer matrix for 1D. Utility functions for exact solutions are provided. Example use cases are as follows: Measuring effective ergodicity and power-laws in so called functional-diffusion. 13 | License: GPL (>= 3) 14 | -------------------------------------------------------------------------------- /man/transitionProbability1D_R.Rd: -------------------------------------------------------------------------------- 1 | \name{transitionProbability1D_R} 2 | \alias{transitionProbability1D_R} 3 | \title{Compute transition probability using Boltzmann distribution.} 4 | \usage{ 5 | transitionProbability1D_R(ikBT, x, xFlip, J, H) 6 | } 7 | \arguments{ 8 | \item{ikBT}{1/kB*T (Boltzmann factor)} 9 | \item{x}{1D Spin sites on the lattice.} 10 | \item{xFlip}{1D Spin sites on the lattice: after a flip.} 11 | \item{J}{Interaction strength} 12 | \item{H}{External field} 13 | } 14 | \value{ 15 | Returns transition probability. 16 | } 17 | \description{ 18 | Given a vector of flip sites, 1s or -1s, representing up and down spins 19 | respectively, and an other flip sites, return the transition probability, 20 | applying periodic boundary conditions, i.e., cyclic. 21 | This function is pure R implementation. 22 | } 23 | \examples{ 24 | n <- 10 # 10 spin sites 25 | mySites <- genConfig1D_R(n) # Generate sites 26 | mySitesNew <- flipConfig1D_R(mySites) 27 | # only short-range part 28 | transitionProbability1D_R(1.0, mySites, mySitesNew, 1.0, 0.0) 29 | } 30 | \author{ 31 | Mehmet Suzen 32 | } 33 | -------------------------------------------------------------------------------- /R/isingLibR.R: -------------------------------------------------------------------------------- 1 | # 2 | # Ising Model MC functions 3 | # R functions: That maps the C code for measuring the performance 4 | # (c) 2013 by Dr.Mehmet Suzen 5 | # GPLv3 or higher 6 | # 7 | 8 | 9 | genConfig1D_R <- function(n) { 10 | mapply(genUniform, 1:n) 11 | } 12 | 13 | genUniform <- function(n=1) { 14 | x <- 0.0; 15 | a<-runif(1); 16 | if(a>=0.5) { 17 | x <-1.0 18 | } else { 19 | x <--1.0 20 | } 21 | x 22 | } 23 | 24 | flipConfig1D_R <- function(x) { 25 | rn <- round(runif(1)*length(x)) 26 | x[rn] <- -1*x[rn] 27 | x 28 | } 29 | 30 | lattice1DenergyNN_R <- function(x) { 31 | n <- length(x); 32 | energy <- sum(x[2:n] * x[1:(n-1)])+x[n]*x[1] 33 | energy 34 | } 35 | 36 | totalEnergy1D_R <- function(x, J, H) { 37 | energy <- J*lattice1DenergyNN_R(x) + H*sumVec_R(x) 38 | energy 39 | } 40 | 41 | transitionProbability1D_R <- function(ikBT, x, xFlip, J, H) { 42 | energyOrg <- totalEnergy1D_R(x, J, H) 43 | energyFlip <- totalEnergy1D_R(xFlip, J, H) 44 | DeltaE <- energyOrg-energyFlip 45 | prob <- exp(-ikBT*DeltaE)/(1 + exp(-ikBT*DeltaE)) 46 | prob 47 | } 48 | 49 | 50 | sumVec_R <- function(x) { 51 | sum(x); 52 | } 53 | -------------------------------------------------------------------------------- /man/isStep1D.Rd: -------------------------------------------------------------------------------- 1 | \name{isStep1D} 2 | \alias{isStep1D} 3 | \title{Carry one step Metropolis Monte Carlo on 1D ising model} 4 | \usage{ 5 | isStep1D(ikBT, x, J, H, probSel) 6 | } 7 | \arguments{ 8 | \item{ikBT}{1/kB*T (Boltzmann factor)} 9 | \item{x}{1D Spin sites on the lattice.} 10 | \item{J}{Interaction strength} 11 | \item{H}{External field} 12 | \item{probSel}{Which transition probability to use. 1 for Metropolis 2 for Glauber} 13 | } 14 | \value{ 15 | A pair list, flip states (vec) and if step is accepted (accept). 16 | } 17 | \description{ 18 | Given a vector of flip sites, 1s or -1s, representing up and down spins 19 | respectively and the usual thermodynamic parameters ikBt, J and H. 20 | Perform 1 step metropolis Monte Carlo, applying periodic boundary conditions, 21 | i.e., cyclic. This function calls the C function 'isStep1D'. Importance sampling 22 | is applied. 23 | } 24 | \examples{ 25 | n <- 10 # 10 spin sites 26 | mySites <- genConfig1D(n) # Generate sites 27 | # only short-range part 28 | isStep1D(1.0, mySites, 1.0, 0.0, 1) # Metropolis 29 | isStep1D(1.0, mySites, 1.0, 0.0, 2) # Glauber 30 | } 31 | \author{ 32 | Mehmet Suzen 33 | } 34 | -------------------------------------------------------------------------------- /man/transitionProbability1D.Rd: -------------------------------------------------------------------------------- 1 | \name{transitionProbability1D} 2 | \alias{transitionProbability1D} 3 | \title{Compute transition probability using Boltzmann distribution.} 4 | \usage{ 5 | transitionProbability1D(ikBT, x, xflip, J, H, probSel) 6 | } 7 | \arguments{ 8 | \item{ikBT}{1/kB*T (Boltzmann factor)} 9 | \item{x}{1D Spin sites on the lattice.} 10 | \item{xflip}{1D Spin sites on the lattice: after a flip.} 11 | \item{J}{Interaction strength} 12 | \item{H}{External field} 13 | \item{probSel}{Which transition probability to use. 1 for Metropolis 2 for Glauber} 14 | } 15 | \value{ 16 | Returns transition probability. 17 | } 18 | \description{ 19 | Given a vector of flip sites, 1s or -1s, representing up and down spins 20 | respectively, and an other flip sites, return the transition probability, 21 | applying periodic boundary conditions, i.e., cyclic. 22 | This function calls the C function 'transitionProbability1D'. 23 | } 24 | \examples{ 25 | n <- 10 # 10 spin sites 26 | mySites <- genConfig1D(n) # Generate sites 27 | mySitesNew <- flipConfig1D(mySites) 28 | # only short-range part 29 | transitionProbability1D(1.0, mySites, mySitesNew, 1.0, 0.0, 1) # Metropolis 30 | transitionProbability1D(1.0, mySites, mySitesNew, 1.0, 0.0, 2) # Glauber 31 | } 32 | \author{ 33 | Mehmet Suzen 34 | } 35 | -------------------------------------------------------------------------------- /inst/examples/effectiveErgodicity/run.R: -------------------------------------------------------------------------------- 1 | # 2 | # Ergodic Dynamics of Ising Model 3 | # R simulation functions, data generation 4 | # (c) 2013, 2014 by Dr.Mehmet Suzen 5 | # GPLv3 or higher 6 | # 7 | 8 | source("isingErgodicity.R"); # 9 | 10 | 11 | # Generate Data 12 | # Parameters 13 | N <- c(32, 64, 128, 256, 512) 14 | ikBT <- c(0.5, 1.0, 1.5, 2.0) 15 | H <- c(-1.0, -0.50, 0.0, 0.50, 1.0) 16 | # 17 | J <- 1.0 18 | nstep <- 500000 19 | 20 | for(i in 1:length(N)) { 21 | for(j in 1:length(ikBT)) { 22 | for(k in 1:length(H)) { 23 | print(N[i]) 24 | print(ikBT[j]) 25 | print(H[k]) 26 | runSim(ikBT[j], J, H[k], N[i], nstep, 1) # metropolis 27 | runSim(ikBT[j], J, H[k], N[i], nstep, 2) # glauber 28 | } 29 | } 30 | } 31 | 32 | 33 | # This is an example analysis 34 | # 35 | # magnetisationMetric <- magnetisationMetricTM1D(1.0, 1.0, 1.0, 50, 500000, 1) # metropolis 36 | # metricTM <- magnetisationMetric[1]/magnetisationMetric # TM metric 37 | # time <- 1:length(metricTM) 38 | # Dt <- 1:length(metricTM)/metricTM # time evolution of the diffusion coefficient 39 | # ff <- lm(metricTM ~ time) 40 | # coeff <- ff$coefficients 41 | # stdErrorsCoefficients <- coef(summary(ff))[, "Std. Error"] # metricTM == D_G t + intercept 42 | # plot(time, metricTM) 43 | # lines(time, ff$fitted.values) 44 | -------------------------------------------------------------------------------- /man/isPerform1D.Rd: -------------------------------------------------------------------------------- 1 | \name{isPerform1D} 2 | \alias{isPerform1D} 3 | \title{Perform metropolis MC on 1D Ising model} 4 | \usage{ 5 | isPerform1D(ikBT, x, J, H, nstep, ensembleM, probSel) 6 | } 7 | \arguments{ 8 | \item{ikBT}{1/kB*T (Boltzmann factor)} 9 | \item{x}{1D Spin sites on the lattice.} 10 | \item{J}{Interaction strength} 11 | \item{H}{External field} 12 | \item{nstep}{Number of MC steps requested} 13 | \item{ensembleM}{Value of the theoretical magnetization (could be thermodynamic limit value)} 14 | \item{probSel}{Which transition probability to use. 1 for Metropolis 2 for Glauber} 15 | } 16 | \value{ 17 | Returns a pair list containing values for omegaM, Fluctuating metric vector for Magnetisation (length of naccept), 18 | naccept, number of MC steps accepted and nreject, number of MC steps rejected and times as accepted time steps. 19 | Times corresponds to times where flips occur, this is so-called transition times ('metropolis time' or 'single flip time') 20 | to judge the timings between two accepted steps. 21 | } 22 | \description{ 23 | Given a vector of flip sites, 1s or -1s, representing up and down spins 24 | respectively, and an other flip sites, perform Metropolis Monte Carlo 25 | applying periodic boundary conditions, i.e., cyclic. 26 | This function calls the C function 'isPerform1D'. 27 | } 28 | \examples{ 29 | n <- 10 # 10 spin sites 30 | mySites <- genConfig1D(n) # Generate sites 31 | output <- isPerform1D(1.0, mySites, 1.0, 0.0, 10, 0.5, 1) # Metropolis 32 | output <- isPerform1D(1.0, mySites, 1.0, 0.0, 10, 0.5, 2) # Glauber 33 | } 34 | \author{ 35 | Mehmet Suzen 36 | } 37 | -------------------------------------------------------------------------------- /inst/examples/powerLawErgodicity/README.md: -------------------------------------------------------------------------------- 1 | # Ergodic Dynamics of Ising Model : functional-diffusion regimes 2 | 3 | 4 | (c) 2013, 2014, 2015, 2016, 2025 5 | Süzen 6 | GPL v3 7 | 8 | Reproducing the data and analysis for the article: 9 | 10 | Anomalous diffusion in convergence to effective ergodicity 11 | M. Suezen 12 | [arXiv:1606.08693](https://arxiv.org/abs/1606.08693) 13 | 14 | ## Notebooks 15 | 16 | We provide notebooks for data generation and analysis 17 | 18 | * `data_generate.ipynb` : Notebook will generate the dynamic trajectories of Ising Models with external field under 19 | different temperatures at N=512,1024 and Metropolis/Glauber dynamics. 20 | Parameters reads 21 | ```R 22 | N <- c(512, 1024) 23 | ikBT <- seq(0.5,2.0,0.025) 24 | H <- c(1.0) 25 | # 26 | J <- 1.0 27 | nstep <- 2.0e6 28 | ``` 29 | * `data_analysis.ipynb` : This will compute the approach the ergodicity 30 | and power-law exponents. Ploting the results. Resulting data.frames are also stored. 31 | 32 | ## Generated Data Outputs 33 | 34 | Expected output is `ising_ergo.RData` file. 35 | This contains all the trajectories. 36 | 37 | ## Analysis Outputs 38 | 39 | Analysis generates eps, png and csv files. 40 | Plots are for approach to ergodicity and 41 | power-law exponents showing 42 | 43 | ```txt 44 | glauberN1024.csv 45 | glauberN1024.eps 46 | glauberN1024.png 47 | glauberN512.csv 48 | glauberN512.eps 49 | glauberN512.png 50 | glauber_N1024scaling_exponents.eps 51 | glauber_N1024scaling_exponents.png 52 | glauber_N512scaling_exponents.eps 53 | glauber_N512scaling_exponents.png 54 | metropolisN1024.csv 55 | metropolisN1024.eps 56 | metropolisN1024.png 57 | metropolisN512.csv 58 | metropolisN512.eps 59 | metropolisN512.png 60 | metropolis_N1024scaling_exponents.eps 61 | metropolis_N1024scaling_exponents.png 62 | metropolis_N512scaling_exponents.eps 63 | metropolis_N512scaling_exponents.png 64 | ``` 65 | 66 | ## License 67 | 68 | This project and all contributions are licensed under : 69 | * All non-code [![License: CC BY 4.0](https://i.creativecommons.org/l/by/4.0/88x31.png)](https://creativecommons.org/licenses/by/4.0/) 70 | * Code under [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![CRAN Version](https://www.r-pkg.org/badges/version/isingLenzMC)](https://cran.r-project.org/package=isingLenzMC) 2 | [![Total RStudio Cloud Downloads](https://cranlogs.r-pkg.org/badges/grand-total/isingLenzMC?color=brightgreen)](https://cran.r-project.org/package=isingLenzMC) 3 | [![RStudio Cloud Downloads](https://cranlogs.r-pkg.org/badges/isingLenzMC?color=brightgreen)](https://cran.r-project.org/package=isingLenzMC) 4 | [![arXiv:1606.08693](http://img.shields.io/badge/arXiv-1606.08693-B31B1B.svg)](https://arxiv.org/abs/1606.08693) 5 | [![arXiv:1405.4497](http://img.shields.io/badge/arXiv-1405.4497-B31B1B.svg)](https://arxiv.org/abs/1405.4497) 6 | [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1065942.svg)](https://doi.org/10.5281/zenodo.1065942) 7 | [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.17151290.svg)](https://doi.org/10.5281/zenodo.17151290) 8 | 9 | 10 | # isingLenzMC: Monte Carlo for Classical Ising Model 11 | 12 | * [Stable release on CRAN](https://CRAN.R-project.org/package=isingLenzMC) 13 | * [Development repository](https://github.com/msuzen/isingLenzMC) 14 | 15 | ## Description 16 | 17 | Classical Ising Model is a land mark system in statistical physics. The model explains 18 | the physics of spin glasses and magnetic materials, and cooperative phenomenon 19 | in general, for example phase transitions and neural networks. This package provides 20 | utilities to simulate one dimensional Ising Model with Metropolis and Glauber Monte 21 | Carlo with single flip dynamics in periodic boundary conditions. Utility functions 22 | for exact solutions are provided. Such as transfer matrix for 1D. Example use cases 23 | are as follows: Measuring effective ergodicity and power-laws in so called 24 | functional-diffusion. 25 | 26 | ## Example use cases 27 | 28 | These examples are scientific use cases of the package, some corresponds to papers. 29 | 30 | * [Measuring effective ergodicity on differring temperature ranges](inst/examples/effectiveErgodicity/README.md) 31 | * [Ergodic Dynamics of Ising Model : functional-diffusion regimes](inst/examples/powerLawErgodicity) 32 | 33 | ## Related Publications and Datasets 34 | 35 | * Effective ergodicity in single-spin-flip dynamics 36 | Mehmet Suezen, [Phys. Rev. E 90, 032141](https://doi.org/10.1103/PhysRevE.90.032141) 37 | [Dataset](https://doi.org/10.5281/zenodo.1065942) 38 | * Anomalous diffusion in convergence to effective ergodicity, 39 | Suezen, Mehmet, [arXiv:1606.08693](https://arxiv.org/abs/1606.08693) 40 | [Dataset](https://doi.org/10.5281/zenodo.17151290) 41 | 42 | -------------------------------------------------------------------------------- /inst/examples/effectiveErgodicity/isingErgodicity.R: -------------------------------------------------------------------------------- 1 | # 2 | # Ergodic Dynamics of Ising Model 3 | # R simulation functions, data generation, analysis and other utilities 4 | # (c) 2013, 2014 by Dr.Mehmet Suzen 5 | # GPLv3 or higher 6 | # 7 | 8 | require("isingLenzMC"); # 9 | 10 | # 11 | # Using Analytic solution for ensemble magnetisation 12 | # using transfer matrix 13 | # 14 | # Two state ising model: general case 15 | # http://micro.stanford.edu/~caiwei/me334/ 16 | # Ch 7 page 35 17 | # 18 | #Z(h, B, J, N) := exp(N*B*J) * ((cosh(B*h) + sqrt(sinh(B*h)^2+exp(-4*B*J)))^N + (cosh(B*h) - sqrt(sinh(B*h)^2+exp(-4*B*J)))^N); 19 | 20 | # now the magnetisation (mulitply with 1/B) compute with maxima 21 | # very long! 22 | #diff(log(Z(h, B, J, N)), h); 23 | # 24 | #(%i4) diff(log(Z(h, B, J, N)), h); 25 | # B cosh(h B) sinh(h B) 26 | #(%o4) ((---------------------------- + B sinh(h B)) 27 | # - 4 B J 2 28 | # sqrt(%e + sinh (h B)) 29 | # - 4 B J 2 N - 1 30 | # (sqrt(%e + sinh (h B)) + cosh(h B)) N 31 | # B cosh(h B) sinh(h B) 32 | # + (B sinh(h B) - ----------------------------) 33 | # - 4 B J 2 34 | # sqrt(%e + sinh (h B)) 35 | # - 4 B J 2 N - 1 36 | # (cosh(h B) - sqrt(%e + sinh (h B))) N) 37 | # - 4 B J 2 N 38 | #/((sqrt(%e + sinh (h B)) + cosh(h B)) 39 | # - 4 B J 2 N 40 | # + (cosh(h B) - sqrt(%e + sinh (h B))) ) 41 | 42 | getEnsembleMagnetisation <- function(n, ikBT, J, H) { 43 | # Derivative of Equation 35 of Wu notes at Standford 44 | # Maxima output above 45 | if(n < 700) { # This is ad-hoc assumption is that we recover n -> inf solution above this 46 | cHB <- cosh(H*ikBT) 47 | sHB <- sinh(H*ikBT) 48 | e4B <- exp(-4*ikBT*J) 49 | sq4B <- sqrt(e4B+sHB^2) 50 | isq4B <- ikBT*cHB*sHB/sq4B 51 | # Per site ensemble averaged magnetisation 52 | eMag <- isq4B + ikBT*sHB 53 | eMag <- n * eMag * (sq4B+cHB)^(n-1) 54 | eMag <- eMag + n*(ikBT*sHB - isq4B) * (cHB - sq4B)^(n-1) 55 | eMag <- eMag * ((sq4B+cHB)^(n) + (cHB-sq4B)^(n))^(-1) 56 | if(is.nan(eMag)) return(0.9934344) 57 | return(eMag/ikBT/n) 58 | } else { 59 | return(0.9934344) 60 | } 61 | } 62 | 63 | # 64 | # This is to perform 1D Ising simulation and Getting TM metric 65 | # Thirumalai - Mountain Fluctuation Metric 66 | # 67 | magnetisationMetricTM1D <- function(ikBT, J, H, n, nstep, transP) { 68 | ensembleM <- getEnsembleMagnetisation(n, ikBT, J, H) # ensemble average magnetisation per-site 69 | x <- genConfig1D(n) 70 | mySim <- isPerform1D(ikBT, x, J, H, nstep, ensembleM, transP) 71 | time <- 1:mySim$naccept 72 | # Note that, Metropolis variable names! could be glauber as well depending transP value (1 or 2) 73 | magnetisationMetric <- mySim$omegaM[time] 74 | metropolisTime <- mySim$times[time] 75 | out <- list(magnetisationMetric=magnetisationMetric, metropolisTime=metropolisTime); 76 | out 77 | } 78 | 79 | 80 | # 81 | # Running a single sim (time vs. magnetisation metric and 82 | # generate data file with the parametrisation as fileName 83 | # 84 | runSim <- function(ikBT, J, H, n, nstep, transP) { 85 | if(transP == 1) dynamicsName <- 'metropolis'; 86 | if(transP == 2) dynamicsName <- 'glauber'; 87 | dataFileName <- paste(dynamicsName, "TmMetric-n=", sprintf('%.3e', n), 88 | "ikBT=", sprintf('%.3f', ikBT), 89 | "H=", sprintf('%.3f', H), ".dat", 90 | sep="") 91 | out <- magnetisationMetricTM1D(ikBT, J, H, n, nstep, transP) 92 | # Note that, Metropolis variable names! could be glauber as well depending transP value (1 or 2) 93 | ll <- 2*length(out$metropolisTime) 94 | timeMag <- matrix(1:ll, ncol= 2, nrow=length(out$metropolisTime)) 95 | timeMag[,1] <- out$metropolisTime 96 | timeMag[,2] <- out$magnetisationMetric 97 | write.table(timeMag, file=dataFileName, row.names=FALSE, col.names=FALSE) 98 | } 99 | 100 | # 101 | # Read the data file: coloumns: c("metropolisTime", "magnetisationTM") 102 | readDat <- function(filePath) { 103 | matrixMC <- as.matrix(read.csv(filePath, sep=" ", header=0)) 104 | colnames(matrixMC) <- NULL 105 | return(matrixMC) 106 | } 107 | 108 | # 109 | # Obtain power law exponent alpha x ~ t^alpha 110 | # with Using formulation given by Newman-2005-Contemp. Phys. Vol 46 111 | # Appendix B 112 | # 113 | getPowerLaw <- function(x) { 114 | n <- length(x) 115 | xMin <- min(x) 116 | sumLn <- 0 117 | for(i in 1:n) { 118 | sumLn <- sumLn + log(x[i]/xMin) 119 | } 120 | alpha <- 1 + n/sumLn 121 | alpha 122 | } 123 | # 124 | # 125 | 126 | -------------------------------------------------------------------------------- /inst/examples/effectiveErgodicity/plotData.R: -------------------------------------------------------------------------------- 1 | # Plot Data 2 | # (c) 2013, 2014 by Dr.Mehmet Suzen 3 | # GPLv3 or higher 4 | # 5 | 6 | source("isingErgodicity.R"); # 7 | 8 | # Plots 9 | # Two sets: metropolis and glauber 120 plots total. 10 | # 1. Fixed N (5 cases) (total of 40 plots) 11 | # a. Fixed T vary H (4 cases) 12 | # b. Fixed H vary T (4 cases) 13 | # 2. Given (T, H) vary N (20 cases) 14 | 15 | 16 | getFileName <- function(dirData, dynamicsName, N, ikBT, H) { 17 | dataFileName <- paste(dirData, '/', dynamicsName, "TmMetric-n=", sprintf('%.3e', N), 18 | "ikBT=", sprintf('%.3f', ikBT), 19 | "H=", sprintf('%.3f', H), ".dat", 20 | sep="") 21 | dataFileName 22 | } 23 | 24 | # Parameters 25 | N <- c(32, 64, 128, 256, 512) 26 | ikBT <- c(0.5, 1.0, 1.5, 2.0) 27 | #H <- c(-1.0, -0.50, 0.0, 0.50, 1.0) 28 | H <- c(-1.0, -0.50, 0.50, 1.0) 29 | 30 | # 1(a) Fixed N, kBT : Vary H 31 | dynamicsName <- 'metropolis'; # switch names for additional plots 32 | dynamicsName <- 'glauber'; 33 | dirData <- 'data'; 34 | dirPlot <- 'plots/varyH'; 35 | for(i in 1:length(N)) { 36 | for(j in 1:length(ikBT)) { 37 | plotName <- paste(dirPlot, "/", dynamicsName, "VaryH-N=", sprintf('%.3e', N[i]), sprintf('ikBT=%.3f', ikBT[j]), ".png", sep="") 38 | print(plotName) 39 | png(filename=plotName); 40 | legendText <- c() 41 | fData <- getFileName(dirData, dynamicsName, N[i], ikBT[j], H[1]) 42 | aa <- readDat(fData); 43 | plot(aa[,1], aa[1,2]/aa[,2], log="xy", type="l", lty=1, axes=FALSE, ann=FALSE) # col, pch not need while ploting lines 44 | # col, pch not need while ploting lines 45 | mainText<- paste(dynamicsName, " N=", sprintf('%.3e', N[i]), "ikBT=", sprintf('%.3f', ikBT[j])) 46 | title(main=mainText , xlab="MC Time", ylab="Inverse Effective Ergodic Convergence Rate"); 47 | axis(1) 48 | axis(2) 49 | box() 50 | legendText[1] <- paste("h=", sprintf('%.3e', H[1])); 51 | for(k in 2:length(H)) { 52 | aa <- matrix() 53 | fData <- getFileName(dirData, dynamicsName, N[i], ikBT[j], H[k]) 54 | aa <- readDat(fData); 55 | lines(aa[,1], aa[1,2]/aa[,2], type="l", lty=k) 56 | legendText[k] <- paste("h=", sprintf('%.3e', H[k])); 57 | 58 | } 59 | legend(1, max(aa[1,2]/aa[,2])*0.8, legendText, lty=1:5) 60 | dev.off(); 61 | } 62 | } 63 | # 1(b) Fixed N, H : Vary kBT 64 | dirData <- 'data'; 65 | dirPlot <- 'plots/varyT'; 66 | for(i in 1:length(N)) { 67 | for(k in 1:length(H)) { 68 | plotName <- paste(dirPlot, "/", dynamicsName, "VaryT-N=", sprintf('%.3e', N[i]), sprintf('H=%.3f', H[k]), ".png", sep="") 69 | print(plotName) 70 | png(filename=plotName); 71 | legendText <- c() 72 | fData <- getFileName(dirData, dynamicsName, N[i], ikBT[1], H[k]) 73 | aa <- readDat(fData); 74 | plot(aa[,1], aa[1,2]/aa[,2], log="xy", type="l", lty=1, axes=FALSE, ann=FALSE) # col, pch not need while ploting lines 75 | # col, pch not need while ploting lines 76 | mainText<- paste(dynamicsName, " N=", sprintf('%.3e', N[i]), "H=", sprintf('%.3f', H[k])) 77 | title(main=mainText , xlab="MC Time", ylab="Inverse Effective Ergodic Convergence Rate"); 78 | axis(1) 79 | axis(2) 80 | box() 81 | legendText[1] <- paste("1/kBT=", sprintf('%.3e', ikBT[1])); 82 | for(j in 2:length(ikBT)) { 83 | aa <- matrix() 84 | fData <- getFileName(dirData, dynamicsName, N[i], ikBT[j], H[k]) 85 | aa <- readDat(fData); 86 | lines(aa[,1], aa[1,2]/aa[,2], type="l", lty=j) 87 | legendText[j] <- paste("1/kBT=", sprintf('%.3e', ikBT[j])); 88 | } 89 | legend(1, max(aa[1,2]/aa[,2])*0.65, legendText, lty=1:5) 90 | dev.off(); 91 | } 92 | } 93 | 94 | # 2) Given T,H Vary N 95 | dirData <- 'data'; 96 | dirPlot <- 'plots/varyN'; 97 | for(j in 1:length(ikBT)) { 98 | for(k in 1:length(H)) { 99 | plotName <- paste(dirPlot, "/", dynamicsName, "VaryN-T=", sprintf('%.3e', ikBT[j]), sprintf('H=%.3f', H[k]), ".png", sep="") 100 | print(plotName) 101 | png(filename=plotName); 102 | legendText <- c() 103 | fData <- getFileName(dirData, dynamicsName, N[1], ikBT[j], H[k]) 104 | aa <- readDat(fData); 105 | plot(aa[,1], aa[1,2]/aa[,2], log="xy", type="l", lty=1, axes=FALSE, ann=FALSE) # col, pch not need while ploting lines 106 | # col, pch not need while ploting lines 107 | mainText<- paste(dynamicsName, " ikBT=", sprintf('%.3e', ikBT[j]), "H=", sprintf('%.3f', H[k])) 108 | title(main=mainText , xlab="MC Time", ylab="Inverse Effective Ergodic Convergence Rate"); 109 | axis(1) 110 | axis(2) 111 | box() 112 | legendText[1] <- paste("N=", sprintf('%.3e', N[1])); 113 | for(i in 2:length(N)) { 114 | aa <- matrix() 115 | fData <- getFileName(dirData, dynamicsName, N[i], ikBT[j], H[k]) 116 | aa <- readDat(fData); 117 | lines(aa[,1], aa[1,2]/aa[,2], type="l", lty=i) 118 | legendText[i] <- paste("N=", sprintf('%.3e', N[i])); 119 | } 120 | legend(1, max(aa[1,2]/aa[,2])*0.65, legendText, lty=1:5) 121 | dev.off(); 122 | } 123 | } 124 | 125 | -------------------------------------------------------------------------------- /R/isingLibWrapper.R: -------------------------------------------------------------------------------- 1 | # 2 | # Ising Model Dynamics MC 3 | # R wrapper functions to C library functions 4 | # (c) 2013 by Dr.Mehmet Suzen 5 | # GPLv3 or higher 6 | # 7 | 8 | # Generate Random Configuration in 1D 9 | # Arguments 10 | # n : number of sites 11 | genConfig1D <- function(n) { 12 | x <- rep(0.0,n) 13 | out <- .C("genConfig1D", n=as.integer(n), x=as.double(x)); 14 | out$x 15 | } 16 | 17 | # Random single flip configuration in 1D 18 | # Arguments 19 | # x : sites vector 20 | # Return random flip single site 21 | flipConfig1D <- function(x) { 22 | out <- .C("flipConfig1D", n=as.integer(length(x)), x=as.double(x)); 23 | out$x 24 | } 25 | 26 | # Random many flip configuration in 1D 27 | # Arguments 28 | # x : sites 29 | # upperF : Number of repeats for random flip 30 | flipConfig1Dmany <- function(x, upperF) { 31 | out <- .C("flipConfig1Dmany", n=as.integer(length(x)), x=as.double(x), upperF=as.integer(upperF)); 32 | out$x 33 | } 34 | 35 | # Nearest-Neighbour energy in periodic boundary conditions in 1D 36 | # Arguments 37 | # ll : number of sites 38 | # vec : site spin configuration 39 | # energy : energy to be returned 40 | lattice1DenergyNN <- function(x) { 41 | energy <-0 42 | if(!is.numeric(x)) 43 | stop("argument x must be numeric"); 44 | out <- .C("lattice1DenergyNN", n=as.integer(length(x)), vec=as.double(x), energy=as.double(energy)); 45 | out$energy 46 | } 47 | 48 | # 49 | # Sum given vector 50 | # Arguments 51 | # x : site spin configuration 52 | sumVec <- function(x) { 53 | sum <-0 54 | if(!is.numeric(x)) 55 | stop("argument x must be numeric"); 56 | out <- .C("sumVec", n=as.integer(length(x)), vec=as.double(x), sum=as.double(sum)); 57 | out$sum 58 | } 59 | 60 | # Total Energy in 1D 61 | # x : site spin configuration 62 | # J : interaction strength 63 | # H : external field 64 | totalEnergy1D <- function(x, J, H) { 65 | energy <- 0 66 | if(!is.numeric(x)) 67 | stop("argument x must be numeric"); 68 | out <- .C("totalEnergy1D", n=as.integer(length(x)), vec=as.double(x), J=as.double(J), H=as.double(H), totalEnergy=as.double(energy)); 69 | out$totalEnergy 70 | } 71 | 72 | # Compute transition probability 73 | # Arguments 74 | # ikBT : 1/kB*T (boltzmann factor) 75 | # x : 1D Spin sites on the lattice 76 | # xflip: 1D Spin sites on the lattice: after a flip 77 | # J : interaction strength 78 | # H : external field 79 | # probSel : which transition probability to use 1 Metropolis 2 Glauber 80 | transitionProbability1D <- function(ikBT, x, xflip, J, H, probSel) { 81 | prob <- 0.0; 82 | if(!is.numeric(x)) 83 | stop("argument x must be numeric"); 84 | if(!is.numeric(xflip)) 85 | stop("argument xflip must be numeric"); 86 | out <- .C("transitionProbability1D", ikBT=as.double(ikBT), n=as.integer(length(x)), vec=as.double(x), vecFlip=as.double(xflip), 87 | J=as.double(J), H=as.double(H), prob=as.double(prob), probSel=as.integer(probSel)); 88 | out$prob 89 | } 90 | 91 | 92 | # Take One MC Step : importance sampling! 93 | # Author : msuzen 94 | # Arguments 95 | # ikBT : 1 over Temperature times Boltzmann constant 96 | # x : 1D Spin sites on the lattice 97 | # J : interaction strength 98 | # H : external field 99 | # rout : Pair list, flip states (vec) and if step is accepted (accept) 100 | # probSel : which transition probability to use 1 Metropolis 2 Glauber 101 | isStep1D <- function(ikBT, x, J, H, probSel) { 102 | prob <- 0.0; 103 | accept <- 0.0; 104 | if(!is.numeric(x)) 105 | stop("argument x must be numeric"); 106 | out <- .C("isStep1D", ikBT=as.double(ikBT), n=as.integer(length(x)), vec=as.double(x), 107 | J=as.double(J), H=as.double(H), prob=as.double(prob), accept=as.integer(accept), 108 | probSel=as.integer(probSel)); 109 | rout <- list(vec=out$vec, accept=out$accept) 110 | rout 111 | } 112 | 113 | # Perform importance sampling MC on 1D 114 | # 115 | # Author : msuzen 116 | # Arguments 117 | # ikBT : 1 over Temperature times Boltzmann constant 118 | # x : 1D Spin sites on the lattice 119 | # J : interaction strength 120 | # H : external field 121 | # nstep : number of MC steps requested 122 | # ensembleM : Value of the theoretical magnetization (could be thermodynamic limit value) 123 | # Output pair list: 124 | # omegaM : Fluctuating metric vector for Magnetisation (length of naccept) 125 | # naccept : number of MC steps accepted 126 | # nreject : number of MC steps rejected 127 | # probSel : which transition probability to use 1 Metropolis 2 Glauber 128 | # 129 | isPerform1D <- function(ikBT, x, J, H, nstep, ensembleM, probSel) { 130 | if(!is.numeric(x)) 131 | stop("argument x must be numeric"); 132 | omegaM <- rep(0.0, nstep); # Let R allocate memory; assume all steps will be accepted 133 | # index 1 to naccept will be reported in the vector 134 | times <- rep(1.0, nstep); # Let R allocate memory: this is the so called time to accepted flip! 135 | naccept <- 0; 136 | nreject <- 0; 137 | out <- .C("isPerform1D", ikBT=as.double(ikBT), n=as.integer(length(x)), vec=as.double(x), 138 | J=as.double(J), H=as.double(H), ensembleM=as.double(ensembleM), 139 | omegaM=as.double(omegaM), nstep=as.integer(nstep), naccept=as.integer(naccept), 140 | nreject=as.integer(nreject), times=as.integer(times), probSel=as.integer(probSel)); 141 | rout <- list(omegaM=out$omegaM, nreject=out$nreject, naccept=out$naccept, times=out$times); 142 | rout 143 | } 144 | -------------------------------------------------------------------------------- /src/isingLib.c: -------------------------------------------------------------------------------- 1 | /* 2 | MC Dynamics of Ising Model 3 | C functions 4 | (c) 2013 by msuzen (Dr.Mehmet Suezen) 5 | GPLv3 or higher 6 | */ 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | /* 15 | Generate Random Configuration in 1D 16 | Author : msuzen 17 | Arguments 18 | ll : number of sites 19 | myNum : site spin configuration [1 or -1] 20 | Uses R's unif_rand(); (default generator MT if not changed from called) 21 | */ 22 | void genConfig1D(int *ll, double *myNum) { 23 | double uNum=0; 24 | int i, n=ll[0]; 25 | for(i=0; i= 0.5) { 30 | uNum=1.0; 31 | } else { 32 | uNum=-1.0; 33 | } 34 | myNum[i]=uNum; 35 | } 36 | } 37 | 38 | /* 39 | Random single given flip configuration in 1D 40 | Author : msuzen 41 | Arguments 42 | ll : number of sites 43 | myNum : site spin configuration [1 or -1] 44 | Uses R's unif_rand() (default generator MT) 45 | */ 46 | void flipConfig1D(int *ll, double *myNum) { 47 | int n=ll[0], rn; 48 | GetRNGstate(); 49 | rn= (int) ((double) n* unif_rand()); 50 | PutRNGstate(); 51 | myNum[rn] = -1.0 * myNum[rn]; 52 | } 53 | 54 | /* 55 | Random flip given configuration in 1D many times 56 | Author : msuzen 57 | Arguments 58 | ll : number of sites 59 | myNum : site spin configuration [1 or -1] 60 | upperF : Number of flips to perform 61 | Uses R's unif_rand() (default generator MT) 62 | */ 63 | void flipConfig1Dmany(int *ll, double *myNum, int *upperF) { 64 | int i=0; 65 | for(i=0;i< upperF[0];i++) { 66 | flipConfig1D(ll, myNum); 67 | } 68 | } 69 | 70 | /* 71 | Sum given vector 72 | Author : msuzen 73 | Arguments 74 | ll : number of sites 75 | vec : site spin configuration 76 | sum : sum over vec to be returned 77 | */ 78 | void sumVec(int *ll, double *x, double *sum) { 79 | int i, n = ll[0]; 80 | sum[0] = 0.0; 81 | for(i=0; i< n; i++) { 82 | sum[0] += x[i]; 83 | } 84 | } 85 | 86 | /* 87 | Nearest-Neighbour energy in periodic boundary conditions in 1D 88 | Author : msuzen 89 | Arguments 90 | ll : number of sites 91 | vec : site spin configuration 92 | energy : energy to be returned 93 | */ 94 | void lattice1DenergyNN(int *ll, double *vec, double *energy) { 95 | int i, n = ll[0]; 96 | energy[0] = 0.0; 97 | for(i=1; i< n; i++) { 98 | energy[0] += vec[i] * vec[i-1]; 99 | } 100 | /* Additional contribution because of 101 | periodic boundary conditions */ 102 | energy[0] += vec[(n-1)] * vec[0]; 103 | } 104 | 105 | /* Total Energy in 1D 106 | Author : msuzen 107 | Arguments 108 | ll : length of the configuration 109 | vec : spin configuration 110 | J : interaction strength 111 | H : external field 112 | totalEnergy 113 | */ 114 | void totalEnergy1D(int *ll, double *vec, double *J, double *H, double *totalEnergy) { 115 | double energyNN[1], energySum[1]; 116 | lattice1DenergyNN(ll, vec, energyNN); 117 | sumVec(ll, vec, energySum); 118 | totalEnergy[0] = J[0] * energyNN[0] + H[0] * energySum[0]; 119 | } 120 | 121 | /* 122 | Compute Transition probability 123 | Author : msuzen 124 | Arguments 125 | ikBT : 1 over Temperature times Boltzmann constant 126 | ll : n spins 127 | vecOrg : Original spin states 128 | vecFlip : one flip spin states 129 | prob : transition probability 130 | probSel : which transition probability to use 1 Metropolis 2 Glauber 131 | */ 132 | void transitionProbability1D(double *ikBT, int *ll, double *vecOrg, double *vecFlip, double *J, double *H, double *prob, int *probSel) { 133 | double energyOrg[1], energyFlip[1], DeltaE; 134 | totalEnergy1D(ll, vecOrg, J, H, energyOrg); 135 | totalEnergy1D(ll, vecFlip, J, H, energyFlip); 136 | DeltaE = energyOrg[0] - energyFlip[0]; 137 | if(probSel[0] == 1) prob[0] = fmin(1, exp(-ikBT[0]*DeltaE)); /* Metropolis */ 138 | if(probSel[0] == 2) prob[0] = 1.0/(1.0+exp(ikBT[0]*DeltaE)); /* Glauber */ 139 | } 140 | 141 | /* 142 | Take One importance sampling MC Step 143 | Author : msuzen 144 | Arguments 145 | ikBT : 1 over Temperature times Boltzmann constant 146 | ll : n spins 147 | vec : Original spin states 148 | prob : transition probability 149 | accept : if step accepted it will be 1 (so pass/make it zero before running this function) 150 | probSel : which transition probability to use 1 Metropolis 2 Glauber 151 | */ 152 | void isStep1D(double *ikBT, int *ll, double *vec, double *J, double *H, double *prob, int *accept, int *probSel) { 153 | double energyOrg[1], energyFlip[1], DeltaE, flipId, rnd; 154 | int rn,i; 155 | totalEnergy1D(ll, vec, J, H, energyOrg); 156 | GetRNGstate(); 157 | rn= (int) ((double) ll[0]*unif_rand()); 158 | PutRNGstate(); 159 | //printf("flip id=%d\n", rn); 160 | vec[rn] = -1.0*vec[rn]; // flip 161 | totalEnergy1D(ll, vec, J, H, energyFlip); 162 | vec[rn] = -1.0*vec[rn]; // flip back 163 | DeltaE = energyOrg[0] - energyFlip[0]; 164 | if(probSel[0] == 1) prob[0] = fmin(1, exp(-ikBT[0]*DeltaE)); /* Metropolis */ 165 | if(probSel[0] == 2) prob[0] = 1.0/(1.0+exp(ikBT[0]*DeltaE)); /* Glauber */ 166 | GetRNGstate(); 167 | rnd = unif_rand(); 168 | PutRNGstate(); 169 | accept[0] = 0; 170 | if(prob[0] > rnd) { 171 | accept[0] = 1; 172 | vec[rn] = -1.0*vec[rn]; //flip it accepted 173 | } 174 | } 175 | 176 | /* 177 | 178 | # Perform importance sampling MC on 1D 179 | # 180 | # Author : msuzen 181 | # Arguments 182 | # ikBT : 1 over Temperature times Boltzmann constant 183 | # ll : number of sites 184 | # vec : 1D Spin sites on the lattice 185 | # J : interaction strength 186 | # H : external field 187 | # ensembleM : Value of the theoretical magnetization (could be thermodynamic limit value) 188 | # omegaM : Fluctuating metric vector for Magnetisation (nstep length) 189 | # nstep : number of MC steps requested 190 | # naccept : number of MC steps accepted 191 | # nreject : number of MC steps rejected 192 | # times : this is 193 | # probSel : which transition probability to use 1 Metropolis 2 Glauber 194 | # 195 | */ 196 | void isPerform1D(double *ikBT, int *ll, double *vec, double *J, double *H, double *ensembleM, 197 | double *omegaM, int *nstep, int *naccept, int *nreject, int *times, int *probSel) { 198 | int i, k, accept[1]; 199 | double prob[1]; 200 | double timeM[1], diff, magtime; /* time average magnetization */ 201 | prob[0] = 0.0; 202 | timeM[0] = 0.0; 203 | magtime = 0.0; 204 | k = 0; 205 | for(i=0 ;i < nstep[0]; i++) { 206 | accept[0] = 0; 207 | isStep1D(ikBT, ll, vec, J, H, prob, accept, probSel); 208 | if(accept[0] < 1) nreject[0]++; 209 | if(accept[0] > 0) { 210 | times[naccept[0]] = i; 211 | sumVec(ll, vec, timeM); 212 | magtime += timeM[0]/ll[0]; 213 | diff = (magtime/(k+1) - ensembleM[0]); 214 | omegaM[k] = diff*diff; 215 | k++; 216 | naccept[0]++; 217 | } 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /vignettes/isingLenzMC.Rnw: -------------------------------------------------------------------------------- 1 | \documentclass[a4paper]{article} 2 | 3 | 4 | \title{isingLenzMC v0.2: Glauber and Metropolis single spin flip dynamics for the Ising Model \footnote{ This package supports following work, {\it Effective ergodicity in single-spin-flip dynamics}, Phys. Rev. E 90, 032141 (2014) DOI: 10.1103/PhysRevE.90.03214, Mehmet Suezen} } 5 | \author{M. S\"uzen, \footnote{mehmet.suzen@physics.org}} 6 | 7 | \begin{document} 8 | \SweaveOpts{concordance=TRUE} 9 | %\VignetteIndexEntry{Ising Model: Single spin flip dynamics} 10 | \maketitle 11 | 12 | The Ising-Lenz Model \footnote{E. Ising 1924} appear as one of the land mark systems in statistical physics, 13 | as well as in many other fields including computational neuroscience. Because of its simplicity and success 14 | in explaining critical phenomenon, Ising Model is routinely used in research and as a teaching concept in 15 | statistical mechanics and in standard Monte Carlo methods. There exist analytical solutions for 1D and 2D 16 | Ising Model. Still, numerical solutions with MC could provide insights. 17 | 18 | {\bf isingLenzMC} package provides utilities to simulate one dimensional Ising Model with Metropolis and Glauber 19 | Monte Carlo with single flip dynamics in periodic boundary conditions \footnote{Higher dimensional models may be 20 | introduced in future releases.}. Computationally intensive parts are written in {\it low-level language (C)} 21 | for efficiency reasons. 22 | 23 | The model is identical to{\it Hopfield network} as well, as Glauber dynamics corresponds to learning dynamics. 24 | 25 | \section{Ising Model} 26 | 27 | Consider one dimensional lattice that contains $N$ sites. Each site values can be labelled as $\{s_{i}\}_{i=1}^{N}$. 28 | In two state version of a lattice, which is an Ising Model, sites can take two values, such as $\{1,-1\}$, 29 | corresponding to spin up and spin down states, for example as a model of magnetic material or the state of a 30 | neuron. 31 | 32 | The total energy, so called Hamiltonian, of the system can be expressed as follows, for short-range parts with 33 | interaction strength $J$: 34 | 35 | $$ \mathcal{H}(\{s_{i}\}_{i=1}^{N}, J, H) = J \big( (\sum_{i=1}^{N-1} s_{i} s_{i+1}) + (s_{1} s_{N}) \big) + H \sum_{1}^{N} s_{i} $$ 36 | 37 | This expression contains two interactions, due to nearest-neighbors (NN) and due to an external field. Coefficients 38 | $J$ and $H$ corresponds to these interactions respectively. Note that, additional term in NN interactions $s_{1} s_{N}$ 39 | appears due to periodic (cyclic) boundary conditions. 40 | 41 | 42 | \section{Simulation of the Ising Model} 43 | 44 | \subsection{Single-flip dynamics} 45 | One of the common ways to generate dynamics for a lattice system explained in the previous section is changing 46 | the value of a randomly choosen site to its opposite value as a dynamical step. This procedure is called single-flip 47 | dynamics. An example dynamics for 5 site lattice can be as follows: 48 | 49 | $$\{1, -1, 1, 1, -1\}$$ 50 | $$\{1, -1, 1, -1, -1\}$$ 51 | $$\{1, 1, 1, -1, -1\}$$ 52 | $$\{-1, 1, 1, -1, -1\}$$ 53 | 54 | Note that, the quality of this kind of dynamics depends on the quality of the random number generator (RNG) we use in selecting 55 | flipped site. However, we assume that RNG in use is sufficiently good for this purpose. This matter is beyond the scope of 56 | this document, however default RNG in R, Marsenne-Twister is an appropriate choice. 57 | 58 | \subsection{Transition Probability} 59 | 60 | The transition probability associated to single spin flip, for Glauber and Metropolis dynamics, 61 | can be computed as follows 62 | 63 | $$p_{Glauber}(\{s_{i}\}_{i=1}^{N}) = \exp(-k \Delta \mathcal{H})/ \big( 1 + \exp(k -\Delta \mathcal{H}) \big) $$ 64 | $$ = 1/\big( 1 + \exp(k \Delta \mathcal{H}) \big)$$ 65 | $$p_{Metropolis}(\{s_{i}\}_{i=1}^{N}) = min\big(1, \exp(-k \Delta \mathcal{H}) \big)$$ 66 | 67 | where $k = \frac{1}{k_{B}T}$ is the Boltzmann factor and $\Delta \mathcal{H}$ is the total energy difference. 68 | 69 | \subsection{Metropolis Monte Carlo} 70 | 71 | In metropolis Monte Carlo, the above transition probability is compared with a uniform number between $[0, 1]$ 72 | to check the new lattice configuration induced by the spin flip is an acceptable move. Note that the above formulation 73 | of the transition probability numerically ensures that transition probability lies in between $[0,1]$. This procedure 74 | mimics importance sampling. This is a special case of Metropolis-Hastings Markov Chain Monte Carlo (MCMC). 75 | 76 | \section{Utilities} 77 | 78 | Package provides utilities to perform Metropolis MC for two state 1D $N$-site lattice, i.e., Ising Model. Functions with suffices with 79 | $\_R$ are pure R implementations. In this section we document only C based implementations, while functionality is the same. 80 | 81 | One can generate a random configuration, perform single flip on the given configuration, compute nearest-neighbour energy and 82 | total energy. In the following example we generate 7 sites randomly and perform a single spin flip. We compute energies 83 | 84 | <>= 85 | require(isingLenzMC) 86 | set.seed(123456) 87 | N <- 7 88 | myInitialConfig <- genConfig1D(N) 89 | myInitialConfig 90 | myNextConfig <- flipConfig1D(myInitialConfig) 91 | myNextConfig 92 | # nearest neighbour energy for initial config 93 | lattice1DenergyNN(myInitialConfig) 94 | # transition probability at J=H=1/kBT=1.0 95 | transitionProbability1D(1.0, myInitialConfig, myNextConfig, 1.0, 1.0, 1) # Metropolis 96 | @ 97 | 98 | It is possible to do the above steps in one go by applying MC move 99 | <>= 100 | require(isingLenzMC) 101 | set.seed(123456) 102 | N <- 7 103 | myInitialConfig <- genConfig1D(N) 104 | myInitialConfig 105 | # 1 step Monte Carlo move 106 | isStep1D(1.0, myInitialConfig, 1.0, 1.0, 1) # Metropolis 107 | @ 108 | 109 | \section{Simulations} 110 | \subsection{Free Energy} 111 | The partition function $Z_{N}$ can be computed by using the eigenvalues $\lambda_{1}$ and $\lambda_{2}$ of the transfer matrix. 112 | $$Z_{N}(J, H) = \lambda_{1}^{N} + \lambda_{2}^{N} $$ 113 | 114 | For example for 7 sites 115 | 116 | <>= 117 | Tm <- transferMatrix(1.0, 1.0, 1.0) 118 | # Free Energy 119 | log(Tm$evalues[1]^7 + Tm$evalues[2]^7) 120 | @ 121 | \subsection{Magnetisation: Finite Size Effects} 122 | 123 | The average magnetisation of the 1D ising model is simply defined as the average of the lattice site values in the finite case. 124 | However, in theory magnetisation of 1D bulk system ($N \to \infty $) is analytically known 125 | $$ M_{ensemble}(H, T) = exp(J/k_{B} T) sinh(H/k_{B} T) \Big( exp(2K) sinh^{2}(J/k_{B}T) + exp(-2J/k_{B}T) \Big)^{-1/2}$$ 126 | 127 | This is approximately $0.9934346$ for $J=H=1/k_{B}T=1.0$. This value represents the ensemble average magnetisation for the bulk system. 128 | 129 | Now if we simulate a long enough lattice, we see that simulated magnetisation, time average value, approaches the ensemble average magnetisation value. 130 | <>= 131 | require(isingLenzMC) 132 | set.seed(123456) 133 | ensembleM <- 0.9934346 134 | N <- 200 135 | x <- genConfig1D(N) 136 | mcData <- isPerform1D(1.0, x, 1.0, 1.0, 10000, ensembleM, 1) # Metropolis 137 | @ 138 | a member of {\it mcData} named list {\it omegaM} reports so called a fluctuation metric over accepted steps, and it is defined as 139 | follows 140 | $$ \Omega_{M}(k) = \Big( (\sum_{i=1}^{k} M_{ave}^{i}) - M_{ensemble} \Big)^{2} $$ 141 | where $M_{ave}^{i}$ is the average magnetisation per site at a given accepted step $i$. It is left as an exercise to see how this 142 | fluctuation mDetric changes with the system size $N$. The larger the lattice, longer simulation needed to reach to ensemble average. 143 | 144 | \end{document} 145 | -------------------------------------------------------------------------------- /inst/examples/powerLawErgodicity/data_generate.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "0201d596", 6 | "metadata": {}, 7 | "source": [ 8 | "# Ergodic Dynamics of Ising Model : Diffusion regimes : Data Generation\n", 9 | "\n", 10 | " \n", 11 | " (c) 2013, 2014, 2015, 2016, 2025 Süzen\n", 12 | " GPL v3 \n", 13 | "\n", 14 | "This notebook contains IsingLenzMC simulation functions, data generation." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "id": "47c00df9", 20 | "metadata": {}, 21 | "source": [ 22 | "## Utility Functions" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": null, 28 | "id": "700ab7a7", 29 | "metadata": { 30 | "vscode": { 31 | "languageId": "r" 32 | } 33 | }, 34 | "outputs": [], 35 | "source": [ 36 | "rm(list=ls())\n", 37 | "source(\"functions.R\"); \n", 38 | "sessionInfo()" 39 | ] 40 | }, 41 | { 42 | "cell_type": "code", 43 | "execution_count": null, 44 | "id": "e079462d", 45 | "metadata": { 46 | "vscode": { 47 | "languageId": "r" 48 | } 49 | }, 50 | "outputs": [], 51 | "source": [ 52 | "require(\"isingLenzMC\"); # 0.2.5" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": null, 58 | "id": "3856a69f", 59 | "metadata": { 60 | "vscode": { 61 | "languageId": "r" 62 | } 63 | }, 64 | "outputs": [], 65 | "source": [ 66 | " \n", 67 | "#\n", 68 | "# Using Analytic solution for ensemble magnetisation \n", 69 | "# using transfer matrix\n", 70 | "#\n", 71 | "# Two state ising model: general case\n", 72 | "# http://micro.stanford.edu/~caiwei/me334/\n", 73 | "# Ch 7 page 35\n", 74 | "# \n", 75 | "#Z(h, B, J, N) := exp(N*B*J) * ((cosh(B*h) + sqrt(sinh(B*h)^2+exp(-4*B*J)))^N + (cosh(B*h) - sqrt(sinh(B*h)^2+exp(-4*B*J)))^N);\n", 76 | "\n", 77 | "# now the magnetisation (mulitply with 1/B) compute with maxima\n", 78 | "# very long!\n", 79 | "#diff(log(Z(h, B, J, N)), h);\n", 80 | "#\n", 81 | "#(%i4) diff(log(Z(h, B, J, N)), h);\n", 82 | "# B cosh(h B) sinh(h B)\n", 83 | "#(%o4) ((---------------------------- + B sinh(h B))\n", 84 | "# - 4 B J 2\n", 85 | "# sqrt(%e + sinh (h B))\n", 86 | "# - 4 B J 2 N - 1\n", 87 | "# (sqrt(%e + sinh (h B)) + cosh(h B)) N\n", 88 | "# B cosh(h B) sinh(h B)\n", 89 | "# + (B sinh(h B) - ----------------------------)\n", 90 | "# - 4 B J 2\n", 91 | "# sqrt(%e + sinh (h B))\n", 92 | "# - 4 B J 2 N - 1\n", 93 | "# (cosh(h B) - sqrt(%e + sinh (h B))) N)\n", 94 | "# - 4 B J 2 N\n", 95 | "#/((sqrt(%e + sinh (h B)) + cosh(h B))\n", 96 | "# - 4 B J 2 N\n", 97 | "# + (cosh(h B) - sqrt(%e + sinh (h B))) )\n", 98 | "\n", 99 | "getEnsembleMagnetisation <- function(n, ikBT, J, H) {\n", 100 | "# Derivative of Equation 35 of Wu notes at Standford\n", 101 | "# Maxima output above\n", 102 | " if(n < 700) { # This is ad-hoc assumption is that we recover n -> inf solution above this\n", 103 | " cHB <- cosh(H*ikBT)\n", 104 | " sHB <- sinh(H*ikBT)\n", 105 | " e4B <- exp(-4*ikBT*J)\n", 106 | " sq4B <- sqrt(e4B+sHB^2)\n", 107 | " isq4B <- ikBT*cHB*sHB/sq4B\n", 108 | " # Per site ensemble averaged magnetisation\n", 109 | " eMag <- isq4B + ikBT*sHB\n", 110 | " eMag <- n * eMag * (sq4B+cHB)^(n-1)\n", 111 | " eMag <- eMag + n*(ikBT*sHB - isq4B) * (cHB - sq4B)^(n-1)\n", 112 | " eMag <- eMag * ((sq4B+cHB)^(n) + (cHB-sq4B)^(n))^(-1)\n", 113 | " if(is.nan(eMag) || is.infinite(eMag)) return(0.9934344) # 0.9934344 infinite solution\n", 114 | " return(eMag/ikBT/n)\n", 115 | " } else {\n", 116 | " return(0.9934344)\n", 117 | " }\n", 118 | "}" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": null, 124 | "id": "c85eee50", 125 | "metadata": { 126 | "vscode": { 127 | "languageId": "r" 128 | } 129 | }, 130 | "outputs": [], 131 | "source": [ 132 | "#\n", 133 | "# This is to perform 1D Ising simulation and Getting TM metric\n", 134 | "# Thirumalai - Mountain Fluctuation Metric\n", 135 | "#\n", 136 | "magnetisationMetricTM1D <- function(ikBT, J, H, n, nstep, transP) {\n", 137 | " ensembleM <- getEnsembleMagnetisation(n, ikBT, J, H) # ensemble average magnetisation per-site\n", 138 | " x <- genConfig1D(n)\n", 139 | " mySim <- isPerform1D(ikBT, x, J, H, nstep, ensembleM, transP) \n", 140 | " time <- 1:mySim$naccept\n", 141 | " # Note that, Metropolis variable names! could be glauber as well depending transP value (1 or 2)\n", 142 | " magnetisationMetric <- mySim$omegaM[time]\n", 143 | " metropolisTime <- mySim$times[time]\n", 144 | " out <- list(magnetisationMetric=magnetisationMetric, metropolisTime=metropolisTime);\n", 145 | " out\n", 146 | "}" 147 | ] 148 | }, 149 | { 150 | "cell_type": "code", 151 | "execution_count": null, 152 | "id": "9bcf4fad", 153 | "metadata": { 154 | "vscode": { 155 | "languageId": "r" 156 | } 157 | }, 158 | "outputs": [], 159 | "source": [ 160 | "#\n", 161 | "# Running a single sim (time vs. magnetisation metric and \n", 162 | "# generate data file with the parametrisation as fileName\n", 163 | "#\n", 164 | "runSim <- function(ikBT, J, H, n, nstep, transP) {\n", 165 | " if(transP == 1) dynamicsName <- 'metropolis';\n", 166 | " if(transP == 2) dynamicsName <- 'glauber';\n", 167 | " out <- magnetisationMetricTM1D(ikBT, J, H, n, nstep, transP)\n", 168 | " # Note that, Metropolis variable names! could be glauber as well depending transP value (1 or 2)\n", 169 | " ll <- 2*length(out$metropolisTime) \n", 170 | " timeMag <- matrix(1:ll, ncol= 2, nrow=length(out$metropolisTime))\n", 171 | " timeMag[,1] <- out$metropolisTime\n", 172 | " timeMag[,2] <- out$magnetisationMetric\n", 173 | " timeMag\n", 174 | "}\n" 175 | ] 176 | }, 177 | { 178 | "cell_type": "code", 179 | "execution_count": null, 180 | "id": "d6c699e5", 181 | "metadata": { 182 | "vscode": { 183 | "languageId": "r" 184 | } 185 | }, 186 | "outputs": [], 187 | "source": [ 188 | "#' 2015_ more data to measure the power laws.\n", 189 | "#' \n", 190 | "install.packages(\"matlab\")\n" 191 | ] 192 | }, 193 | { 194 | "cell_type": "markdown", 195 | "id": "b62d8bac", 196 | "metadata": {}, 197 | "source": [ 198 | "## Generate Data: Ising Model" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": null, 204 | "id": "53faca7c", 205 | "metadata": { 206 | "vscode": { 207 | "languageId": "r" 208 | } 209 | }, 210 | "outputs": [], 211 | "source": [ 212 | "\n", 213 | "#' 2015_ more data to measure the power laws.\n", 214 | "#' \n", 215 | "library(matlab)\n", 216 | "\n", 217 | "# Generate Data \n", 218 | "# Parameters for scaling law\n", 219 | "N <- c(512, 1024)\n", 220 | "ikBT <- seq(0.5,2.0,0.025)\n", 221 | "H <- c(1.0)\n", 222 | "#\n", 223 | "J <- 1.0\n", 224 | "nstep <- 2.0e6\n", 225 | "\n", 226 | "#' sim parameter lengths\n", 227 | "nn <- length(N)\n", 228 | "kk <- length(ikBT)\n", 229 | "hh <- length(H)" 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": null, 235 | "id": "c8c577a0", 236 | "metadata": { 237 | "vscode": { 238 | "languageId": "r" 239 | } 240 | }, 241 | "outputs": [], 242 | "source": [ 243 | "ising_ergo <- vector(\"list\", nn*kk*hh)\n", 244 | "l <- 1\n", 245 | "tic();\n", 246 | "for(i in 1:nn) {\n", 247 | " for(j in 1:kk) {\n", 248 | " for(k in 1:hh) {\n", 249 | " print(N[i])\n", 250 | " print(ikBT[j])\n", 251 | " print(H[k])\n", 252 | " # magnetisation metric\n", 253 | " ising_ergo[[l]]$N <- N[i]\n", 254 | " ising_ergo[[l]]$ikBT <- ikBT[j]\n", 255 | " ising_ergo[[l]]$H <- H[k]\n", 256 | " ising_ergo[[l]]$metropolis <- runSim(ikBT[j], J, H[k], N[i], nstep, 1) # metropolis\n", 257 | " ising_ergo[[l]]$glauber <- runSim(ikBT[j], J, H[k], N[i], nstep, 2) # glauber\n", 258 | " l <- l + 1\n", 259 | " }\n", 260 | " }\n", 261 | "}\n", 262 | "toc();" 263 | ] 264 | }, 265 | { 266 | "cell_type": "code", 267 | "execution_count": null, 268 | "id": "7f2732c9", 269 | "metadata": { 270 | "vscode": { 271 | "languageId": "r" 272 | } 273 | }, 274 | "outputs": [], 275 | "source": [ 276 | "save(ising_ergo, file=\"ising_ergo.RData\")" 277 | ] 278 | } 279 | ], 280 | "metadata": { 281 | "kernelspec": { 282 | "display_name": "R", 283 | "language": "R", 284 | "name": "ir" 285 | }, 286 | "language_info": { 287 | "codemirror_mode": "r", 288 | "file_extension": ".r", 289 | "mimetype": "text/x-r-source", 290 | "name": "R", 291 | "pygments_lexer": "r", 292 | "version": "4.5.1" 293 | } 294 | }, 295 | "nbformat": 4, 296 | "nbformat_minor": 5 297 | } 298 | -------------------------------------------------------------------------------- /inst/examples/powerLawErgodicity/data_analysis.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "id": "788b8860", 6 | "metadata": {}, 7 | "source": [ 8 | "# Ergodic Dynamics of Ising Model : Diffusion regimes : Data Generation\n", 9 | "\n", 10 | " \n", 11 | " (c) 2013, 2014, 2015, 2016, 2025 Süzen\n", 12 | " GPL v3 \n", 13 | "\n", 14 | "This notebook contains IsingLenzMC simulation functions, data analysis." 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "id": "7f6429a7", 21 | "metadata": { 22 | "vscode": { 23 | "languageId": "r" 24 | } 25 | }, 26 | "outputs": [], 27 | "source": [ 28 | "rm(list=ls())\n", 29 | "load(\"ising_ergo.RData\") # Generated Data\n", 30 | "library(igraph) # for power-law fit\n" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": null, 36 | "id": "6c732610", 37 | "metadata": { 38 | "vscode": { 39 | "languageId": "r" 40 | } 41 | }, 42 | "outputs": [], 43 | "source": [ 44 | "run_analysis <- function(N, mg, ising_ergo) {\n", 45 | " ll = length(ising_ergo)\n", 46 | " ikBT <- seq(0.5,2.0,0.025)\n", 47 | " H <- c(1.0)\n", 48 | " #' sim parameter lengths\n", 49 | " kk <- length(ikBT)\n", 50 | " hh <- length(H)\n", 51 | " ising_ergo_analysis <- vector(\"list\", kk*hh)\n", 52 | " l <- 1\n", 53 | " for(i in 1:ll) {\n", 54 | " data_current <- ising_ergo[[i]]\n", 55 | " if(data_current$N == N) {\n", 56 | " ising_ergo_analysis[[l]] = data_current\n", 57 | " l <- l + 1\n", 58 | " }\n", 59 | " }\n", 60 | "\n", 61 | " # function to read data\n", 62 | " get_omega_time <- function(ii, mg=\"metropolis\") {\n", 63 | " data_current <- ising_ergo_analysis[[ii]]\n", 64 | " if(mg == \"metropolis\") {\n", 65 | " time_ <- data_current$metropolis[,1]\n", 66 | " omega_ <- data_current$metropolis[,2]\n", 67 | " }\n", 68 | " if(mg == \"glauber\") {\n", 69 | " time_ <- data_current$glauber[,1]\n", 70 | " omega_ <- data_current$glauber[,2]\n", 71 | " }\n", 72 | " ll <- length(time) # sample by 100\n", 73 | " return(list(time_=time_, omega_=omega_, ikBT=data_current$ikBT, N=data_current$N))\n", 74 | " }\n", 75 | "\n", 76 | " ####################################################################\n", 77 | " ## Compute exponents\n", 78 | " ####################################################################\n", 79 | " ll <- length(ising_ergo_analysis)\n", 80 | " pf_list <- list()\n", 81 | " time_list <- list()\n", 82 | " omega_list <- list()\n", 83 | " temp <- c()\n", 84 | " for(i in 1:ll) {\n", 85 | " print(i)\n", 86 | " time_omega <- get_omega_time(i, mg=mg)\n", 87 | " temp[i] <- time_omega$ikBT \n", 88 | " time_ <- time_omega$time_\n", 89 | " omega_ <- time_omega$omega_\n", 90 | " time_list[[i]] <- time_\n", 91 | " omega_list[[i]] <- omega_\n", 92 | " lo <- length(omega_)\n", 93 | " ixx <- 1:lo\n", 94 | " if(lo >10000) {\n", 95 | " ixx<-seq(1,lo,100)\n", 96 | " }\n", 97 | " pf <- power.law.fit(omega_[ixx])\n", 98 | " pf_list[[i]] <- pf\n", 99 | " }\n", 100 | " # alphas\n", 101 | " alphas <- c()\n", 102 | " xmins <- c()\n", 103 | " ks_stats<- c()\n", 104 | " for(i in 1:ll) {\n", 105 | " alphas[i] <- pf_list[[i]]$alpha \n", 106 | " xmins[i] <- pf_list[[i]]$xmin\n", 107 | " ks_stats[i] <- pf_list[[i]]$KS.stat\n", 108 | " }\n", 109 | "\n", 110 | " if(mg == \"glauber\") { \n", 111 | " naccept<-sapply(1:ll, function(i) length(ising_ergo[[i]]$glauber[,1]))\n", 112 | " }\n", 113 | " if(mg == \"metropolis\") { \n", 114 | " naccept<-sapply(1:ll, function(i) length(ising_ergo[[i]]$metropolis[,1]))\n", 115 | " }\n", 116 | " df <- data.frame(temp=temp, alphas=alphas, xmins=xmins, ks_stats=ks_stats, naccept=naccept)\n", 117 | " write.table(df,file=paste(c(mg, \"N\", N, \".csv\"),collapse = \"\"),sep=\",\")\n", 118 | "\n", 119 | "\n", 120 | " ####################################################################\n", 121 | " ## plot two curve\n", 122 | " ## One with alpha >2.0 and one with alpha <2.0\n", 123 | " ####################################################################\n", 124 | " ps.options(pointsize=25)\n", 125 | " plotName <- paste(c(mg,\"N\", N, \".eps\"), collapse=\"\")\n", 126 | " csvName <- paste(c(mg, \"N\", N, \".csv\"), collapse=\"\")\n", 127 | " setEPS()\n", 128 | " postscript(plotName)\n", 129 | " par(mar=c(4,4,0.5,0.5), xaxs = \"i\", yaxs = \"i\")\n", 130 | " # \n", 131 | " AT <- c(0, 10, 100, 1000, 10000, 100000, 1000000)\n", 132 | " AT.label <- expression(0, 10^1, 10^2, 10^3, 10^4, 10^5, 10^6) \n", 133 | " AT2 <- c(0, 0.1, 0.01, 0.001, 0.0001, 0.00001,0.000001)\n", 134 | " AT2.label <- expression(0, 10^-1, 10^-2, 10^-3, 10^-4, 10^-5, 10^-6) \n", 135 | " legendText <- c()\n", 136 | "\n", 137 | " ix_vec <- which(alphas < 3.0)\n", 138 | " ixx <- ix_vec[1]\n", 139 | " time_ <- time_list[[ixx]][-1] # omit 1\n", 140 | " omega_ <- omega_list[[ixx]][-1]\n", 141 | " \n", 142 | " plot(time_, omega_, log=\"xy\", type=\"l\", lty=1, axes=FALSE, ann=FALSE,\n", 143 | " lwd=5, cex.lab=5.5, cex.axis=5.5, cex.main=5.5, cex.sub=5.5) # \n", 144 | " title(xlab=\"MC Time\", ylab=\"Inverse Rate\");\n", 145 | " axis(1, at=AT, labels=AT.label)\n", 146 | " axis(2, at=AT2, labels=AT2.label)\n", 147 | " box()\n", 148 | " legendText[1] <- paste(\"1/kT=\", sprintf('%.1f', temp[1]));\n", 149 | " pf_list[[1]] <- pf\n", 150 | " k <- 1 # legend\n", 151 | " for(i in ix_vec[-1]) {\n", 152 | " # print(length(omega_))\n", 153 | " if(i%%8 == 0) { # plot at every 10\n", 154 | " k <- k +1\n", 155 | " time_ <- time_list[[i]]\n", 156 | " omega_ <- omega_list[[i]]\n", 157 | " lines(time_, omega_, type=\"l\", lty=i, lwd=5)\n", 158 | " legendText[k] <- paste(\"1/kT=\", sprintf('%.1f', temp[i]));\n", 159 | " }\n", 160 | " }\n", 161 | "\n", 162 | " legend(\"bottomleft\", legendText, lty=1:k, bty=\"n\", lwd=5)\n", 163 | " dev.off()\n", 164 | "\n", 165 | " plotName <- paste(c(mg,\"N\", N, \".png\"), collapse=\"\")\n", 166 | " png(plotName, pointsize=25)\n", 167 | " par(mar=c(4,4,0.5,0.5), xaxs = \"i\", yaxs = \"i\")\n", 168 | " # \n", 169 | " AT <- c(0, 10, 100, 1000, 10000, 100000, 1000000)\n", 170 | " AT.label <- expression(0, 10^1, 10^2, 10^3, 10^4, 10^5, 10^6) \n", 171 | " AT2 <- c(0, 0.1, 0.01, 0.001, 0.0001, 0.00001,0.000001)\n", 172 | " AT2.label <- expression(0, 10^-1, 10^-2, 10^-3, 10^-4, 10^-5, 10^-6) \n", 173 | " legendText <- c()\n", 174 | "\n", 175 | " ix_vec <- which(alphas < 3.0)\n", 176 | " ixx <- ix_vec[1]\n", 177 | " time_ <- time_list[[ixx]][-1] # omit 1\n", 178 | " omega_ <- omega_list[[ixx]][-1]\n", 179 | " \n", 180 | " plot(time_, omega_, log=\"xy\", type=\"l\", lty=1, axes=FALSE, ann=FALSE,\n", 181 | " lwd=5, cex.lab=5.5, cex.axis=5.5, cex.main=5.5, cex.sub=5.5) # \n", 182 | " title(xlab=\"MC Time\", ylab=\"Inverse Rate\");\n", 183 | " axis(1, at=AT, labels=AT.label)\n", 184 | " axis(2, at=AT2, labels=AT2.label)\n", 185 | " box()\n", 186 | " legendText[1] <- paste(\"1/kT=\", sprintf('%.1f', temp[1]));\n", 187 | " pf_list[[1]] <- pf\n", 188 | " k <- 1 # legend\n", 189 | " for(i in ix_vec[-1]) {\n", 190 | " if(i%%8 == 0) { # plot at every 10\n", 191 | " k <- k +1\n", 192 | " time_ <- time_list[[i]]\n", 193 | " omega_ <- omega_list[[i]]\n", 194 | " lines(time_, omega_, type=\"l\", lty=i, lwd=5)\n", 195 | " legendText[k] <- paste(\"1/kT=\", sprintf('%.1f', temp[i]));\n", 196 | " }\n", 197 | " }\n", 198 | " legend(\"bottomleft\", legendText, lty=1:k, bty=\"n\", lwd=5)\n", 199 | " dev.off()\n", 200 | "\n", 201 | " # Scaling exponents vs. Temperature\n", 202 | " ps.options(pointsize=25)\n", 203 | " plotName <- paste(c(mg, \"_N\" , N, \"scaling_exponents.png\"), collapse=\"\")\n", 204 | " postscript(plotName)\n", 205 | " plot(temp[ix_vec], alphas[ix_vec], log=\"xy\", type=\"p\", lty=1, axes=FALSE, ann=FALSE,\n", 206 | " lwd=5, cex.lab=5.5, cex.axis=5.5, cex.main=5.5, cex.sub=5.5) # \n", 207 | " title(xlab=\"Temperature\", ylab=\"Scaling Exponents\");\n", 208 | " axis(1)\n", 209 | " axis(2)\n", 210 | " box()\n", 211 | " dev.off()\n", 212 | "\n", 213 | " plotName <- paste(c(mg, \"_N\" , N, \"scaling_exponents.png\"), collapse=\"\")\n", 214 | " png(plotName, pointsize=25)\n", 215 | " plot(temp[ix_vec], alphas[ix_vec], log=\"xy\", type=\"p\", lty=1, axes=FALSE, ann=FALSE,\n", 216 | " lwd=5, cex.lab=5.5, cex.axis=5.5, cex.main=5.5, cex.sub=5.5) # \n", 217 | " title(xlab=\"Temperature\", ylab=\"Scaling Exponents\");\n", 218 | " axis(1)\n", 219 | " axis(2)\n", 220 | " box()\n", 221 | " dev.off()\n", 222 | "\n", 223 | "}\n" 224 | ] 225 | }, 226 | { 227 | "cell_type": "code", 228 | "execution_count": null, 229 | "id": "3fa4d281", 230 | "metadata": { 231 | "vscode": { 232 | "languageId": "r" 233 | } 234 | }, 235 | "outputs": [], 236 | "source": [ 237 | "# Run Analysis with N=512, 1024 mg=\"metropolis\", \"glauber\"\n", 238 | "run_analysis(512, \"glauber\", ising_ergo)\n", 239 | "run_analysis(512, \"metropolis\", ising_ergo)\n", 240 | "run_analysis(1024, \"glauber\", ising_ergo)\n", 241 | "run_analysis(1024, \"metropolis\", ising_ergo)" 242 | ] 243 | } 244 | ], 245 | "metadata": { 246 | "kernelspec": { 247 | "display_name": "R", 248 | "language": "R", 249 | "name": "ir" 250 | }, 251 | "language_info": { 252 | "codemirror_mode": "r", 253 | "file_extension": ".r", 254 | "mimetype": "text/x-r-source", 255 | "name": "R", 256 | "pygments_lexer": "r", 257 | "version": "4.5.1" 258 | } 259 | }, 260 | "nbformat": 4, 261 | "nbformat_minor": 5 262 | } 263 | -------------------------------------------------------------------------------- /GPL-3: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------