def _setup_gauss_newton_lagrangian_hessian(self): gauss_newton_lagrangian_hessian_diag = ci.vertcat([ \ ci.mx(self._cov_matrix_derivative_directions.shape[0] - \ self._weightings_vectorized.shape[0], 1), \ self._weightings_vectorized]) self._gauss_newton_lagrangian_hessian = ci.diag( \ gauss_newton_lagrangian_hessian_diag)
def gauss_newton_lagrangian_hessian(self): gauss_newton_lagrangian_hessian_diag = ci.vertcat([ \ ci.mx(self._optimization_variables.shape[0] - \ self._weightings_vectorized.shape[0], 1), \ self._weightings_vectorized]) gauss_newton_lagrangian_hessian = ci.diag( \ gauss_newton_lagrangian_hessian_diag) return gauss_newton_lagrangian_hessian
def standard_deviations(self): try: return ci.sqrt([abs(var) for var \ in ci.diag(self.covariance_matrix)]) except AttributeError: raise AttributeError(''' Standard deviations for the estimated parameters not yet computed. Run compute_covariance_matrix() to do so. ''')
def standard_deviations(self): try: variances = [] for k in range(ci.diag(self.covariance_matrix).numel()): variances.append(abs(ci.diag(self.covariance_matrix)[k])) standard_deviations = ci.sqrt(variances) return standard_deviations # return ci.sqrt([abs(var) for var \ # in ci.diag(self.covariance_matrix)]) except AttributeError: raise AttributeError(''' Standard deviations for the estimated parameters not yet computed. Run compute_covariance_matrix() to do so. ''')
def _print_experimental_properties(self, covariance_matrix): np.set_printoptions(linewidth = 200, \ formatter={'float': lambda x: format(x, ' 10.8e')}) print("\nParameters p_i:") for k, pk in enumerate(self._pdata): print(" p_{0:<3} = {1} +/- {2}".format( \ k, pk, ci.sqrt(abs(ci.diag(covariance_matrix)[k])))) print("\nCovariance matrix for this setup:") print(np.atleast_2d(covariance_matrix))
def _plot_confidence_ellipsoids(self, pdata, properties = "initial"): if properties == "initial": covariance_matrix = {"initial": self.covariance_matrix_initial} elif properties == "optimized": covariance_matrix = {"optimized": self.covariance_matrix_optimized} elif properties == "all": covariance_matrix = {"initial" : self._covariance_matrix_initial, \ "optimized" : self._covariance_matrix_optimized} else: raise ValueError(''' Input-value not supported, choose either "initial", "final", or "all". ''') plotting_directory = "confidence_ellipsoids_" + \ os.path.basename(__main__.__file__).strip(".py") try: os.mkdir(plotting_directory) except OSError: if not os.path.isdir(plotting_directory): raise OSError(''' Plotting directory "confidence_ellipsoids_{0}" does not yet exist, but could not be created. Do you have write access within your working folder, or is some file with this name already present within your working folder? '''.format(plotting_directory)) xy = np.array([np.cos(np.linspace(0, 2*np.pi, 100)), np.sin(np.linspace(0, 2*np.pi, 100))]) for p1 in range(pdata.size): for p2 in range(pdata.size)[p1+1:]: plt.figure() for prop, cm in covariance_matrix.iteritems(): covariance_matrix_p1p2 = np.array([ \ [cm[p1, p1], cm[p1, p2]], \ [cm[p2, p1], cm[p2, p2]] ]) w, v = np.linalg.eig(covariance_matrix_p1p2) ellipsoid = ci.repmat(np.array([pdata[p1], pdata[p2]]), 1, 100) + \ ci.mul([v, ci.diag(w), xy]) plt.plot(ellipsoid[0,:].T, ellipsoid[1,:].T, label = \ "p_" + str(p1) + ", p_" + str(p2) + " " + prop) plt.scatter(pdata[p1], pdata[p2], color = "k") plt.legend(loc="upper right") plt.savefig(plotting_directory + "/p_" + str(p1) + \ "-p_" + str(p2) + "-" + properties + ".png", bbox_inches='tight') plt.close()