# Using Flux to construct a CES function

**URL:** <https://discourse.julialang.org/t/using-flux-to-construct-a-ces-function/68842>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [September 28, 2021, 1:35am UTC](https://discourse.julialang.org/t/using-flux-to-construct-a-ces-function/68842 "2021-09-28T01:35:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [September 28, 2021, 1:35am UTC](https://discourse.julialang.org/t/using-flux-to-construct-a-ces-function/68842/1 "2021-09-28T01:35:48Z")

</div>

I’m wondering if I `Flux.jl` can be used to construct a multi layer [CES function](https://en.wikipedia.org/wiki/Constant_elasticity_of_substitution). I won’t be training the function in Flux, just leverage its multi layer flexibility. For example, consider the function

F(x; a, \rho) = \left(\sum\_{i=1}^{n} a\_i \; x\_i^\rho \right)^{1/\rho},

where x and a are vectors of length n, and \rho is a scalar. a and \rho represent parameters, and x represents inputs. In turn, each x\_i can possibly be also composed of other layers:

x\_i = F(y; b, r),

for parameters b, r and inputs y.

Can that be accommodated in `Flux.jl`?

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [September 28, 2021, 8:19am UTC](https://discourse.julialang.org/t/using-flux-to-construct-a-ces-function/68842/2 "2021-09-28T08:19:24Z")

</div>

What would you like Flux to do ? To chain the layers? If you aren’t interested in training/finding the parameters, why not just using function piping ?

---

<div class="post-metadata">

**Author:** ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)\
**Post date:** [September 28, 2021, 8:51am UTC](https://discourse.julialang.org/t/using-flux-to-construct-a-ces-function/68842/3 "2021-09-28T08:51:39Z")

</div>

I wanted to leverage the model building of Flux. For example, for specifying non-fully connected networks, which means that I can specify what inputs go into which x\_i. I suppose that could be relatively easy to do in Flux.

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [September 28, 2021, 4:32pm UTC](https://discourse.julialang.org/t/using-flux-to-construct-a-ces-function/68842/4 "2021-09-28T16:32:13Z")

</div>

Flux layers are just callable structs, so I don’t see any fundamental limitation preventing this from working. I’m not sure you need most of the functionality in Flux if you’re not planning on using AD, however.
