| 205 | return hessian |
| 206 | |
| 207 | def plot_density(self,file=None): |
| 208 | |
| 209 | xmin = self.xmin |
| 210 | xmax = self.xmax |
| 211 | ymin = self.ymin |
| 212 | ymax = self.ymax |
| 213 | |
| 214 | data_xy = np.array([self.x,self.y]) |
| 215 | cov_matrix = np.cov( data_xy ) |
| 216 | v, w = np.linalg.eigh( cov_matrix ) |
| 217 | |
| 218 | x_avg, y_avg = np.mean( data_xy, axis=1 ) |
| 219 | first_component = np.sqrt(v[1])*w[:,1] |
| 220 | second_component = np.sqrt(v[0])*w[:,0] |
| 221 | u = [first_component[0],second_component[0]] |
| 222 | v = [first_component[1],second_component[1]] |
| 223 | origin = [x_avg], [y_avg] |
| 224 | |
| 225 | fig = plt.figure() |
| 226 | ax = fig.add_subplot(111) |
| 227 | ax.imshow(np.rot90(self.Z), cmap=plt.cm.jet_r, extent=[xmin, xmax, ymin, ymax], aspect='auto',zorder=0) |
| 228 | cset = ax.contour(self.X,self.Y,self.Z,zorder=1) |
| 229 | ax.clabel(cset, inline=1, fontsize=10) |
| 230 | ax.plot(self.x_ss_min[0],self.x_ss_min[1], 'k.', markersize=10, color='red') |
| 231 | ax.plot(self.x_ss_max[0],self.x_ss_max[1], 'k.', markersize=10, color='red') |
| 232 | ax.quiver(x_avg, y_avg, first_component[0], first_component[1], color='white', angles='xy', scale_units='xy', scale=1,zorder=3) |
| 233 | ax.quiver(x_avg, y_avg, second_component[0], second_component[0], color='gray', angles='xy', scale_units='xy', scale=1,zorder=3) |
| 234 | ax.set_xlim([xmin, xmax]) |
| 235 | ax.set_ylim([ymin, ymax]) |
| 236 | ax.set_title('T-squared='+str(self.hotelling_t_squared)) |
| 237 | ax.set_xlabel('spliced') |
| 238 | ax.set_ylabel('unspliced') |
| 239 | if file!=None: |
| 240 | plt.savefig(file) |
| 241 | |
| 242 | def confidence_level(self, point): |
| 243 | density = self.density |