FAQ

Does my function need to be vectorized?

No, it does not need to be vectorized in order for you to use this tool. There is a vectorized parameter that allows for both vectorized functions and non-vectorized functions. If your function is not vectorized, we will iterate through the x-values to generate the x-value matrix that will be used for the projection plots. If your function is vectorized, this will run more efficiently with generating the projection plots.

What is the point of generating the x-value matrix separately?

The x-value matrix generates the combinations with the varying parameters that we will be inputting into the objective function to visualize the resulting changes in the output. By having this outputted separately, the user is able to view the values that will be inputted prior to plotting and alter it. In the future, an equalize() function will be added to fine-tune the scale to be more accurate. An example of what the x-value matrix looks like is given below (based on the documentation example):

import numpy as np
import projplot as pjp

# setup
x_opt = np.array([-0.765,  1.647]) # optimal values
x_lims = np.array([[-3., 1], [0, 4]]) # plot limits
n_pts = 10 # number of plotting points

x_vals = pjp.proj_xvals(x_opt, x_lims, n_pts)
x_vals
array([[-3.        ,  1.647     ],
       [-2.55555556,  1.647     ],
       [-2.11111111,  1.647     ],
       [-1.66666667,  1.647     ],
       [-1.22222222,  1.647     ],
       [-0.77777778,  1.647     ],
       [-0.33333333,  1.647     ],
       [ 0.11111111,  1.647     ],
       [ 0.55555556,  1.647     ],
       [ 1.        ,  1.647     ],
       [-0.765     ,  0.        ],
       [-0.765     ,  0.44444444],
       [-0.765     ,  0.88888889],
       [-0.765     ,  1.33333333],
       [-0.765     ,  1.77777778],
       [-0.765     ,  2.22222222],
       [-0.765     ,  2.66666667],
       [-0.765     ,  3.11111111],
       [-0.765     ,  3.55555556],
       [-0.765     ,  4.        ]])

Can I see the data that is plotted as a DataFrame?

Yes, if you want to see the data that is being plotted as a pandas.DataFrame, you can set plot=False in projplot.proj_plot() and it will return the DataFrame of values that would have been plotted. If we were to assign this to a variable plot_data and call it, we would have the following DataFrame outputted (based on the documentation example):

x_names = ["x1", "x2"] # variable names

# objective function
def obj_fun(x):
    A = np.array([[3., 2.],
                  [2., 7.]])
    b = np.array([1., 10.])
    y = np.dot(np.dot(x.T, A), x) - 2 * np.dot(b, x)
    return y

plot_data = pjp.proj_data(obj_fun, x_vals, x_names)
plot_data
y x variable
0 -0.715737 -3.000000 x1
1 -6.084033 -2.555556 x1
2 -10.267144 -2.111111 x1
3 -13.265070 -1.666667 x1
4 -15.077811 -1.222222 x1
5 -15.705367 -0.777778 x1
6 -15.147737 -0.333333 x1
7 -13.404922 0.111111 x1
8 -10.476922 0.555556 x1
9 -6.363737 1.000000 x1
10 3.285675 0.000000 x2
11 -5.580498 0.444444 x2
12 -11.681239 0.888889 x2
13 -15.016547 1.333333 x2
14 -15.586424 1.777778 x2
15 -13.390868 2.222222 x2
16 -8.429881 2.666667 x2
17 -0.703461 3.111111 x2
18 9.788391 3.555556 x2
19 23.045675 4.000000 x2

Do I have to include names for each parameter?

No, as a default if the list of names is empty, the function will label them x1, x2, …, xd based on \(d\) parameters.

What is the point of the opt_vlines and vlines parameters?

This allows the user to see where the solution for each parameter lies on the plot. For exxample, if the projection plot is given for values between -2 and 2 and was minimized at 0, if we believed the minimum was at -1, we would be able to visually tell that our optimization didn’t work since the vertical line would not be at 0.

With projplot.proj_plot() you are only able to plot vertical lines at the optimal values using opt_vlines. However, for the more advanced users, vertical lines (vlines) can be plotted at any values as long as an array is provided that is the length of the parameters for projplot.proj_plot_show().