# Black Box Curve Fitting Problem with Extra Layer Between Input and Output Vectors

MAJOR EDIT:

I attempted to better describe my problem here. My original post (more or less) is below, if for whatever reason that is needed.

$$\underline x$$ is a linearly spaced vector of arbitrary element spacing (and thus size). Let's call the length of $$\underline x$$ the scalar quantity $$l$$. Written in terms of its elements, $$\underline x$$ is defined as:

$$\underline x=[x_1,\space x_2,\space ...,\space x_i,\space ...,\space x_l]$$

Now, I have a set of $$n$$ vectors $$\underline y_j$$ which are all of length $$l$$ as well. Each element $$i$$ for all $$\underline y_j$$ is defined as some function of all $$x_i$$ as shown below:

$$\underline y_1=[y_{11},\space y_{12},\space ...,\space y_{1i},\space ...,\space y_{1l}]=[f_1(x_1),\space f_1(x_2),\space ...,\space f_1(x_i),\space ...,\space f_1(x_l)]$$ ... $$\underline y_j=[y_{j1},\space y_{j2},\space ...,\space y_{ji},\space ...,\space y_{jl}]=[f_j(x_1),\space f_j(x_2),\space ...,\space f_j(x_i),\space ...,\space f_j(x_l)]$$ ... $$\underline y_n=[y_{n1},\space y_{n2},\space ...,\space y_{ni},\space ...,\space y_{nl}]=[f_n(x_1),\space f_n(x_2),\space ...,\space f_n(x_i),\space ...,\space f_n(x_l)]$$

It is unknown how any $$f_j$$ is defined, and this will be important later. Now is when it gets fun. I have a set of $$m$$ vectors $$\underline z_k$$ that are once again of length $$l$$. Each element $$i$$ for all $$\underline z_k$$ is defined as some function of all $$\underline y_j$$ as shown below:

$$\underline z_1=[z_{11},\space z_{12},\space ...,\space z_{1i},\space ...,\space z_{1l}]=g_1([\underline y_1,\space \underline y_2,\space ...,\space \underline y_i,\space ...\space \underline y_n])$$ $$\underline z_k=[z_{11},\space z_{12},\space ...,\space z_{1i},\space ...,\space z_{1l}]=g_k([\underline y_1,\space \underline y_2,\space ...,\space \underline y_i,\space ...\space \underline y_n])$$ $$\underline z_m=[z_{11},\space z_{12},\space ...,\space z_{1i},\space ...,\space z_{1l}]=g_m([\underline y_1,\space \underline y_2,\space ...,\space \underline y_i,\space ...\space \underline y_n])$$

Something to note is $$m$$ and $$n$$ are not necessarily equal quantities. Now for the crux of the problem: I have data analogous to all $$\underline z_k$$ as a function of $$\underline x$$. Let's call these vectors $$\underline z_{k,\space data}$$. Essentially, I want to determine all $$f_j$$ by iteratively changing all $$\underline y_j$$ until the black box programs $$g_k$$ output $$\underline z_k$$ approximately equal to $$\underline z_{k,\space data}$$. Does that make sense? What I am looking for is, I think, analogous to finding $$f(x)$$ given data for $$g(f(x))$$ versus $$x$$.

In any case, I would love a solution in Python using SciPy's optimization functions. I would be happy with freely available resources like textbook or lecture PDFs as well.

ORIGINAL POST:

I am not a mathematician but here goes.

x is a linearly spaced vector with arbitrary element spacing. I have a set of n vectors yi that each have the same length as x (call this length l). The elements of each vector yi are (theoretically) functions of x's elements. That is to say, yij = f(xj) for all elements j in x and yi (each comprising l elements).

I also have a set of m vectors zk, the elements of which are defined by some function acting on all n vectors yi. That is to say, zk = g(y1, ... yi, ... yn) for all k. I want to be very clear that m and n are not necessarily equal, but each zk also comprises l elements. I will be referring to g(y1, ... yi, ... yn) as the black box for the remainder of this post.

I have data for each zk plotted against x, and cannot get data for each zk against all yi. Is there a way to programmatically construct each yi such that by passing all yi to the black box results in plots that correctly match the data for zk versus x in a reasonable amount of time? Basically, can I find all yi(x) given data between x and all zk(x) = zk(y1(x), ... yi(x), ... yn(x))?

A general solution in Python using SciPy would be incredible. My particular problem regards an n = 2 and m = 4 (albeit z2 = z4, if that changes anything) case. But I will gladly take links to freely available texts and lectures, as well. Thank you!

• What is a line space? Apr 2 at 19:48
• @TedBlack linearly spaced vector, like what you'd get from np.linspace in Python using NumPy. Apr 2 at 19:56
• Did you mean to say $z_k = g_k(y_1 \dots y_n)$? The way you have it written, every $z_k$ is the same. Apr 2 at 20:36
• @AlexK You are correct. I am going to rewrite this entire post once I get home, bear with me. I wrote it all on mobile as that is all I have at the minute. Apr 2 at 20:40
• @AlexK It is done. Apr 2 at 23:18