Python Forum
Level curves don't match after rotation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Level curves don't match after rotation
#1
Consider the general 2D Gaussian function, centered at (0.5,0.5),

A*exp(-a*(-0.5 + x)**2-b*(-0.5 + x)*(-0.5 + y)-c*(-0.5 + y)**2)
where the covariance matrix can be written in terms of the coefficients a,b, and c as


2a & b
b & 2c


Rotating by 45 degrees counterclockwise gives

(a-b+c) & (a-c)
(a-c) & (a+b+c)


However, given a=1.25, b=0 and c=10000, and using Python to integrate over the unit square,

import numpy as np
import matplotlib.pyplot as plt
a=1.25
b=0   
c=10000
d=(a-b+c)/2
e=a-c
f=(a+b+c)/2
fig, ax = plt.subplots()
x,y=np.meshgrid(np.linspace(0,1,50),np.linspace(0,1,50))
z=3*np.exp(-a*(-0.5 + x)**2-b*(-0.5 + x)*(-0.5 + y)-c*(-0.5 + y)**2)
w=3*np.exp(-d*(-0.5 + x)**2-e*(-0.5 + x)*(-0.5 + y)-f*(-0.5 + y)**2) #rotated by 45 degrees counterclockwise
cs=ax.contour(x,y,z,levels=[0.8],colors='k',linestyles='dashed');
cs=ax.contour(x,y,w,levels=[0.8],colors='k',linestyles='dashed');

from scipy import integrate
h = lambda y, x: 3*np.exp(-a*(-0.5 + x)**2-b*(-0.5 + x)*(-0.5 + y)-c*(-0.5 + y)**2)
g = lambda y, x: 3*np.exp(-d*(-0.5 + x)**2-e*(-0.5 + x)*(-0.5 + y)-f*(-0.5 + y)**2)
print(integrate.dblquad(h, 0, 1, lambda x: 0, lambda x: 1))
print(integrate.dblquad(g, 0, 1, lambda x: 0, lambda x: 1))
And output:

(0.061757213121080706, 1.4742783672680448e-08)
(0.048117567144166894, 5.930455188853047e-12)
As well as the plot (where the one with coefficients a,b,c is the horizontal one, and the level curves are for C=z(x,y)=w(x,y)=0.8, both plotted over the unit square):

[Image: AeAiT.png]
Reply
#2
This has been solved. The curves do match, it is just that, when the function is rotated, its central axes changes, and in the square, it is longer than that of the non-rotated one.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python logging RotatingFileHandler writes to random file after the first log rotation rawatg 0 418 Feb-15-2024, 11:15 AM
Last Post: rawatg
  Plot multiple 2D Curves in 3D stc 5 993 Jun-11-2023, 05:48 PM
Last Post: snippsat
  Array Rotation Solution hannah 3 1,508 Mar-31-2022, 09:28 AM
Last Post: paul18fr
  Calculate transformation and Rotation Sandra2312 1 1,814 Jan-31-2021, 12:53 PM
Last Post: jefsummers
  Rotation Effect on live Webcam Feed Leziiy 0 1,620 Sep-12-2020, 04:25 PM
Last Post: Leziiy
  Unindent does not match any outer intendation level -error MaartenRo 3 2,286 Jun-28-2020, 11:46 AM
Last Post: MaartenRo
  HELP! unindent does not match any outer indentation level blackjesus24 2 1,966 Jan-29-2020, 08:00 AM
Last Post: blackjesus24
  how to show the distance between two curves in a graph termo 6 7,042 Oct-21-2019, 09:08 AM
Last Post: DeaD_EyE
  Logger file rotation not working when python code started from windows service as exe nirvantosh 1 6,680 Jun-14-2019, 03:58 PM
Last Post: nirvantosh
  unindent does not match any outer indentation level , How can i fix it the_fire_pharaoh 2 2,525 Jan-01-2019, 10:52 AM
Last Post: the_fire_pharaoh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020