File:Mutual Information Examples.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Original file(SVG file, nominally 506 × 318 pixels, file size: 3.62 MB)

Captions

Captions

Add a one-line explanation of what this file represents

Summary

[edit]
Description
English: Recreation of File:Correlation_examples2.svg using mutual information
Date
Source Own work
Author Naught101
#Title: An example of the mutual information of x and y for various distributions of (x,y) pairs
#Tags: Mathematics; Statistics; Information theory
#Author: Denis Boigelot
#Packets needed : mvtnorm (rmvnorm), RSVGTipsDevice (devSVGTips), entropy, gplots
#How to use: output()
#
#This is an translated version in R of an Matematica 6 code by Imagecreator.

library(mvtnorm)
library(entropy)
library(gplots)
library(RSVGTipsDevice)

MyPlot <- function(xy, xlim = c(-4, 4), ylim = c(-4, 4), eps = 1e-15) {
  counts = hist2d(xy[,1], xy[,2], show=FALSE, bins=500)'counts'
  title = round(mi.plugin(counts), 1)
  plot(xy, main = title, xlab = "", ylab = "",
       col = "darkblue", pch = 16, cex = 0.2,
       xaxt = "n", yaxt = "n", bty = "n",
       xlim = xlim, ylim = ylim)
}

MvNormal <- function(n = 1000, cor = 0.8) {
  for (i in cor) {
     sd = matrix(c(1, i, i, 1), ncol = 2)
     x = rmvnorm(n, c(0, 0), sd)
     MyPlot(x)
  }
}

rotation <- function(t, X) return(X %*% matrix(c(cos(t), sin(t), -sin(t), cos(t)), ncol = 2))

RotNormal <- function(n = 1000, t = pi/2) {
  sd = matrix(c(1, 1, 1, 1), ncol = 2)
  x = rmvnorm(n, c(0, 0), sd)
  for (i in t)
     MyPlot(rotation(i, x))
}

Others <- function(n = 1000, spread = 1) {
  # x = seq(-1, 1, length.out = n) #generates a time series (serial dependence)
  x = runif(n, -1, 1) #same image, not a time series (no serial dependence)
  y = 4 * (x^2 - 1/2)^2 + runif(n, -1, 1) /3 * spread
  MyPlot(cbind(x,y), xlim = c(-1, 1), ylim = c(-1/3, 1+1/3))

  y = runif(n, -1, 1)
  xy = rotation(-pi/8, cbind(x,y))
  lim = sqrt(2+sqrt(2)) / sqrt(2)
  MyPlot(cbind(xy[,1], xy[,2]*spread), xlim = c(-lim, lim), ylim = c(-lim, lim))

  xy = rotation(-pi/8, xy)
  MyPlot(cbind(xy[,1], xy[,2]*spread), xlim = c(-sqrt(2), sqrt(2)), ylim = c(-sqrt(2), sqrt(2)))
  y = 2*x^2 + runif(n, -1, 1) * spread
  MyPlot(cbind(x,y), xlim = c(-1, 1), ylim = c(-1, 3))

  y = (x^2 + runif(n, 0, 1/2) * spread) * sample(seq(-1, 1, 2), n, replace = TRUE)
  MyPlot(cbind(x,y), xlim = c(-1.5, 1.5), ylim = c(-1.5, 1.5))

  y = cos(x*pi) + rnorm(n, 0, 1/8) * spread
  x = sin(x*pi) + rnorm(n, 0, 1/8) * spread
  MyPlot(cbind(x,y), xlim = c(-1.5, 1.5), ylim = c(-1.5, 1.5))

  xy1 = rmvnorm(n/4, c( 3,  3), diag(2)*spread)
  xy2 = rmvnorm(n/4, c(-3,  3), diag(2)*spread)
  xy3 = rmvnorm(n/4, c(-3, -3), diag(2)*spread)
  xy4 = rmvnorm(n/4, c( 3, -3), diag(2)*spread)
  MyPlot(rbind(xy1, xy2, xy3, xy4), xlim = c(-3-4, 3+4), ylim = c(-3-4, 3+4))
}

output <- function() {
  devSVGTips(width = 7, height = 4.4) # remove first and last line for no svg exporting
  par(mfrow = c(4, 7), oma = c(0,0,0,0), mar=c(2,2,2,0))
  MvNormal(800, c(1.0, 0.8, 0.4, 0.0, -0.4, -0.8, -1.0));
  RotNormal(200, c(0, pi/12, pi/6, pi/4, pi/2-pi/6, pi/2-pi/12, pi/2));
  Others(800)
  Others(800, 0.3)
  dev.off() # remove first and last line for no svg exporting
}

Licensing

[edit]
I, the copyright holder of this work, hereby publish it under the following licenses:
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
You may select the license of your choice.

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current00:07, 27 January 2016Thumbnail for version as of 00:07, 27 January 2016506 × 318 (3.62 MB)Naught101 (talk | contribs){{Information |Description ={{en|1=Recreation of File:Correlation_examples2.svg using mutual information}} |Source ={{own}} |Author =Naught101 |Date =2016-01-27 |Permission = |other_versions = }} #T...

There are no pages that use this file.

Metadata