0
$\begingroup$

Suppose we have a simple neural network as follows:

f = NetChain[
  {
    LinearLayer[32],
    ElementwiseLayer["ReLU"],
    LinearLayer[16],
    ElementwiseLayer["ReLU"],
    LinearLayer[1]
  },
  "Input" -> 3,
  "Output" -> 1
]

How can we represent the function g as a neural network that behaves like the function below?

g[v_] := Max@Map[f[Append[v, #]] &, Range[10000]]
$\endgroup$

1 Answer 1

0
$\begingroup$

Here is one possible solution in case someone has a similar question.

op = NetGraph[
  <|
    "f" -> f,
    "cat" -> CatenateLayer[]
  |>,
  {
    {NetPort["Input1"], NetPort["Input2"]} -> "cat" -> "f" -> NetPort["Output"]
  }
]

g = NetGraph[
  <|
    "repl" -> ReplicateLayer[10000],
    "const" -> NetArrayLayer["Array" -> Transpose[{Range[10000]}], "LearningRateMultipliers" -> None],
    "mapthread" -> NetMapThreadOperator[op],
    "max" -> AggregationLayer[Max, All]
  |>,
  {
    NetPort["Input"] -> "repl" -> "mapthread",
    "const" -> "mapthread" -> "max" -> NetPort["Output"]
  }
]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.