Define function as a composition

62 Views Asked by At

I have a function $f$ which takes another function $h(x_i)$ and weight vector $\vec{w}$ with $i$ components:

$$f := \sum_i h(x_i)w_i$$

What is the proper way to define $f$? Should it be $f \; \circ \; h(x_i) = \sum_i h(x_i)w_i$? $f(h)$? I assume what I did above is wrong, but I don't know how to define a function if its a composition.

UPDATE: Defining $h$ if it helps: $$h(x_i, \hat{w_i}) := \sigma(\sum_i x_i\hat{w}_i) $$

where $\hat{w_i}$ is another weight vector unique to $h$, and $\sigma$ is some non-linear transformation.

1

There are 1 best solutions below

1
On

I have a function $f$ which takes another function $h(x_i)$ and weight vector $\vec{w}$ with $i$ components:

$$f := \sum_i h(x_i)w_i$$

If I'm understanding you right, I would write this definition by listing out the names of the parameters (which are $h$ and $w$), like this:

$$f(h, w) := \sum_i h(x_i)w_i$$

I have a question, though: what does $x_i$ mean here? You didn't say that $x_i$ is one of the parameters to the function $f$. Is $x_i$ defined somewhere else?


Edit: I have a few remarks after reading your question update and your comment:

  • The definition I wrote above, $f := \sum_i h(x_i)w_i$, raises a question in my mind: where does the value of $x_i$ come from? In other words, how does $f$ know what the value of $x_i$ is? If the answer is "the value of $x_i$ is defined somewhere else", that's fine, but I need to know that in order to know if this is a valid definition. If the answer is "$f$ takes $x$ as a parameter", then you need to edit the parameter list of $f$ to $f(h, x, w)$ or something, so that we know that it's a parameter.

  • Since the parameter list of $f$ contains $h$, this means that there are multiple different functions $h$ that $f$ can use in order to calculate $\sum_i h(x_i)w_i$, and $f$ will use whatever version of $h$ it is given. However, you also gave a definition for $h$, which seems to imply that there is only one function $h$ that $f$ will ever use to calculate $\sum_i h(x_i)w_i$.

    If there are multiple different functions $h$ that $f$ can use, then there are two things you've named $h$ (the function you've defined, and the function which is a parameter to $f$), and you should change the name of one or the other. If there is only one function $h$ that $f$ can use, then you should remove $h$ from the parameter list of $f$.

  • In the definition of $f$, you are applying $h$ to just one parameter, but your definition of $h$ says that $h$ takes two parameters. Which one is it?

  • You asked about writing the definition using the equals sign $=$ instead of the defined-as-equal symbol $:=$. That's totally fine. (I probably would have used $=$ instead of $:=$ myself.) But if you do use the equals sign, make sure it's clear that you're writing a definition and not a mere statement of equality.

Now, I suspect I know what you're trying to communicate, but I'm not sure. If my hunches are right, then here are two ways of writing it.

Here is the "explicit argument" style:

For all such-and-such kind of non-linear transformations $\sigma$, weight vectors $\hat w$, and input vectors $x$, define

$$h_{\sigma, \hat w}(x) = \sigma \left (\sum_i x_i \hat w_i \right).$$

Then, for all functions $a$ with the same domain and codomain as $h_{\sigma, \hat w}$ defined above, and all weight vectors $w$ and input vectors $x$, define

$$f(a, x, w) = \sum_i a(x_i)w_i.$$

Now that we are done with definitions, suppose we have such-and-such type of things $a$, $b$, and $c$, whose values are such-and-such. Then we can say such-and-such about $f(a, b, c)$...

And here is the "implicit argument" style:

Suppose we have such-and-such kind of non-linear transformation $\sigma$ and weight vector $\hat w$. Then, for all input vectors $x$, define

$$h(x) = \sigma \left (\sum_i x_i \hat w_i \right).$$

Furthermore, suppose that we also have another weight vector $w$. Then define

$$f(x) = \sum_i h(x_i)w_i.$$

Now that we are done with definitions, suppose that $\sigma$, $\hat w$, and $w$ have such-and-such values. Suppose also that we have an input vector $b$ whose value is such-and-such. Then we can say such-and-such about $f(b)$...

The only substantial difference between the above two excerpts is that in the first one, $f$ can use any possible function for $a$, whereas in the second one, $f$ is defined as always using the given function $h$.