import matplotlib.pyplot as plt
import numpy as np

data = np.loadtxt("swc-python/data/inflammation-01.csv", delimiter=",")
image = plt.imshow(data)
plt.show()

"""
Explanation: Introduction to Python part V (And a discussion of vector calculus / optimization)
Activity 1: Discussion of vector caclulus / optimization


What are the Jacobian, the gradient and the Hessian and how do these relate to Taylor's expansion?  What is a special property about the Hessian that relates to the concepts of diagonalization and orthogonality?


What do we refer to when we describe a "linear" or a "tangent-linear" approximation to a function?  Based on the dimensionality, which of the above objects are used for this approximation?


What is a "nonlinear inverse problem" and how does this relate to the inverse function theorem and Newton's method?


What is gradient descent and what is Newton's descent?  How do these differ?  How does this relate to the geometry of an optimization problem and notions such as convexity and the Hessian?


Activity 2: Basic data visualization
The mathematician Richard Hamming once said, "The purpose of computing is insight, not numbers."  Separately, Hamming also said "The way mathematics is currently taught it is exceedingly dull. In the calculus book we are currently using on my campus, I found no single problem whose answer I felt the student would care about! The problems in the text have the dignity of solving a crossword puzzle – hard to be sure, but the result is of no significance in life." We will take this philosophy in part, where we will not stress rigour for rigour's sake. Instead, we will stress empirical intuition for the purpose of insight. 
The best way to develop insight about a problem is often to visualize data. We will explore a few features of Python’s matplotlib library here. While there is no official plotting library, matplotlib is the de facto standard, though is supported and extended by other libraries such as seaborn. First, we will import the pyplot module from matplotlib in its standard convention along with numpy:
End of explanation
"""


plt.plot(data[0,:])
plt.show()

"""
Explanation: Exercise 1:
Blue pixels in the heat map above represent low values, while yellow pixels represent high values. As we can see, inflammation rises and falls over a 40-day period. 
We can make a basic line plot for the time-change in inflammation for the first patient with the following code
End of explanation
"""


import numpy
import matplotlib.pyplot

fig = plt.figure(figsize=(10.0, 3.0))

ax1 = fig.add_subplot(1, 3, 1)
ax2 = fig.add_subplot(1, 3, 2)
ax3 = fig.add_subplot(1, 3, 3)

ax1.set_ylabel('average')
ax1.plot(numpy.mean(data, axis=0))

ax2.set_ylabel('max')
ax2.plot(numpy.max(data, axis=0))

ax3.set_ylabel('min')
ax3.plot(np.min(data, axis=0))

fig.tight_layout()

plt.savefig('inflammation.png')
plt.show()

"""
Explanation: Recalling how the data is ordered by patients in rows and days in columns, generate a plot for the mean / min / max inflammation over all patients in time.  Try using the following commands to include a relevant label for the axes and a relevant title

plt.xlabel
plt.ylabel
plt.title
plt.legend
plt.figtext

Note, some of these options can also be supplied with a keyword argument in the plt.plot function itself.
Exercise 2:
The real strength of matplotlib is not in how we can combine lines in a single plot, but how flexible its object-oriented design is for changing every attribute of a figure.  We gain this functionality principally by using the fig class and axis class API.  An example of creating a fig is below, in which we add axis attributes to the fig and henceforth set axis attributes to adjust the plot.
End of explanation
"""


