plot_compare.py

plot_compare.get_frames_and_titles()

The function get_frames_and_titles returns a list of dataframes and a list of titles based on the command line arguments. :return: two lists: fields and titles.

plot_compare.add_log(key, value)
plot_compare.remove_returns(xs, ys)

The function removes points from the given lists that have an earlier timestep than their predecessor.

Parameters:
  • xs – A list of x-coordinates of points

  • ys – The parameter ys represents a list of values corresponding to the y-axis of a graph

Returns:

The function remove_returns returns two lists, newxs and newys.

plot_compare.filter(xs, ys)

The filter function takes two arrays, xs and ys, and returns new arrays containing every nth element of xs and ys, where n is specified by the plot_every argument.

Parameters:
  • xs – The parameter xs is a list of values. It is used to filter the x-values in the function

  • ys – The parameter ys represents a list of values that you want to filter. It is used to determine which values to keep and which ones to discard

Returns:

two numpy arrays, newxs and newys.

plot_compare.sort_data(xs, ys)

The function sorts two arrays, xs and ys, based on the values in xs.

Parameters:
  • xs – An array or list of values representing the x-coordinates of the data points

  • ys – The parameter “ys” represents a list or array of values that are associated with the corresponding values in the “xs” parameter

Returns:

two arrays, newxs and newys, which are the sorted versions of the input arrays xs and ys respectively.

plot_compare.add_plot(ax, x, y, name='', apply_filter=False, split=True)

The function add_plot takes in an ax object, x and y data, and optional parameters to apply filters and split the data into forward paths, and plots the data on the given axes object.

Parameters:
  • ax – The ax parameter is the matplotlib Axes object on which the plot will be drawn

  • x – The x-axis values for the plot

  • y – The y parameter is a list or array of values representing the y-coordinates of the data points to be plotted

  • name – The name parameter is a string that represents the label for the plot. It is used to identify the data being plotted in the legend of the plot

  • apply_filter – apply_filter is a boolean parameter that determines whether or not to apply a filter to the data before plotting. If apply_filter is set to True, the function will call the filter function on the x and y data before plotting. If apply_filter is set to False, the function will plot the original x, defaults to False (optional)

  • split – The “split” parameter determines whether the data should be split into separate paths before plotting. If set to True, the data will be split into separate paths based on the x-values. Each path will be plotted separately. If set to False, the data will be plotted as a single continuous line, defaults to True (optional)

plot_compare.fields_to_string(fields)

The function “fields_to_string” takes a list of fields and returns a string representation of the fields separated by underscores.

Parameters:

fields – A list of fields, where each field is a string

Returns:

a string that concatenates all the elements in the “fields” list, separated by underscores.

plot_compare.plot_field(fields=['mx', 'my', 'mz'])

The function plot_field plots specified fields from multiple data frames and saves the figure if specified.

Parameters:

fields – The fields parameter is a list of strings that specifies the fields to be plotted. By default, it is set to [“mx”, “my”, “mz”], which means that the function will plot the fields “mx”, “my”, and “mz”. However, you

plot_compare.split_data_to_forward_paths(xs, ys)

The function split_data_to_forward_paths takes two lists, xs and ys, and splits the data into forward paths based on the values in xs.

Parameters:
  • xs – A list of time values. Each value represents a time point in a sequence

  • ys – The ys parameter represents a list of values. It is assumed that each value in ys corresponds to a specific time point

Returns:

a list of lists, where each inner list represents a forward path. Each inner list contains the corresponding values from the ys list that belong to that forward path.

plot_compare.split_to_forward_paths(df, field)

The function split_to_forward_paths takes a data frame df and a field name field, and returns an array of forward paths for the given field.

Parameters:
  • df – The parameter “df” is a data frame that contains the time series data. It should have at least two columns: “time” and the specified field

  • field – The “field” parameter is the name of the column in the data frame that contains the values to be split into forward paths

Returns:

an array of forward paths for the given data frame and field.

plot_compare.normalize(Ls)

The function “normalize” takes a list of vectors as input and returns the normalized vectors in canonical form.

Parameters:

Ls – Ls is a list of vectors. Each vector represents a time step in a sequence. The function normalize takes this list of vectors and normalizes them. The normalization is done in two steps:

Returns:

the normalized list of vectors, where each vector is normalized to the canonical form.

plot_compare.compat_error3D(J_exact, J, m)

The function compat_error3D calculates the compatibility error between the exact Jacobian J_exact and the estimated Jacobian J for a given input m.

Parameters:
  • J_exact – J_exact is a tensor representing the exact Jacobian matrix. It has shape (batch_size, 3, 3), where batch_size is the number of samples in the batch. Each element J_exact[i] is a 3x3 matrix representing the Jacobian matrix for the i-th sample

  • J – J is a tensor of shape (batch_size, 3), where each row represents a 3D vector

  • m – The parameter m represents the input tensor or variable. It is used to compute the gradients of the loss function J with respect to m

Returns:

The function compat_error3D returns the square of the sum of the element-wise multiplication between J_exact and rot_J, along the axis 1.

plot_compare.dotUV(U, V)

The function dotUV calculates the dot product between corresponding rows of two matrices U and V.

Parameters:
  • U – U is a numpy array representing a matrix with shape (n, m), where n is the number of rows and m is the number of columns

  • V – The parameter V is a numpy array representing a matrix

Returns:

a list of dot products between corresponding rows of matrices U and V.

plot_compare.compat_error_superintegrable(U_exact, V_exact, U, V)

The function compat_error_superintegrable calculates the square of the compatibility error for a superintegrable system.

Parameters:
  • U_exact – The parameter U_exact represents the exact solution for the variable U. It is a numpy array that contains the values of U at each point in the domain

  • V_exact – The parameter V_exact is a variable representing the exact solution for V

  • U – The parameter U is a numpy array representing a vector U

  • V – The parameter V is a numpy array representing a vector

Returns:

the square of the value of Lambda.

plot_compare.get_learned_models()

The function get_learned_models() returns a dictionary of learned models based on the command line arguments provided.

Returns:

a dictionary of learned models. Each model is represented by a key-value pair in the dictionary. The key represents the type of model (“without”, “soft”, “implicit”), and the value is another dictionary containing the specific models for energy and L (or J) depending on the type of model.

plot_compare.load_normalized_Ls(df, dim)

The function load_normalized_Ls takes a dataframe df and a dimension dim as input, and returns a normalized array Ls based on the dimension.

Parameters:
  • df – The parameter df is a DataFrame object that contains the data from which the normalized L matrices will be constructed

  • dim – The parameter “dim” represents the dimensionality of the data. It can take values of 3, 4, or 6

Returns:

a numpy array of normalized L matrices.

plot_compare.reject_outliers(data, m=3)

The function reject_outliers removes outliers from a given dataset using a specified threshold.

Parameters:
  • data – The “data” parameter is the input array or list of data points from which outliers need to be rejected

  • m – The parameter “m” in the function “reject_outliers” is used to determine the threshold for rejecting outliers. It is multiplied by the standard deviation of the data to define the range within which data points are considered non-outliers. Any data point that falls outside this range is considered an outlier and, defaults to 3 (optional)

Returns:

the filtered data after removing outliers.

plot_compare.plot_first(field)

The function plot_first plots different fields based on the given arguments and saves the figure if specified.

Parameters:

field – The field parameter is a string that represents the field or variable you want to plot. It is used to access the corresponding data from the dfgt, dfls, dfli, and dflw dataframes

plot_compare.generate_E_points(args, energy)

The function generate_E_points generates random initial conditions for a given energy function and returns the corresponding points in space and their energies.

Parameters:
  • args – The args parameter is a dictionary or object that contains various parameters for the function. It is used to specify the initial conditions and other settings for generating the points

  • energy – The energy parameter is a function that takes in a tensor total_m and calculates the energy based on the values in total_m. The total_m tensor represents the initial conditions for the system, with each row representing a different set of initial conditions.

Returns:

The function generate_E_points returns different variables depending on the value of args.model.

plot_compare.generate_L_points(args, L_tensor)

The function generate_L_points generates random initial conditions for a given model and returns the corresponding L points.

Parameters:
  • args – The “args” parameter is a set of arguments that specify the configuration for generating the points. It likely contains information such as the initial conditions for the points, the density of the points, and the model type

  • L_tensor – The L_tensor is a function that takes a batch of initial conditions total_m_batched as input and returns the corresponding output L_batched. It is used to compute the output L for each batch of initial conditions in the function generate_L_points

Returns:

The function generate_L_points returns different variables depending on the value of args.model.