Evaluate an ensemble of M small two-layer MLPs on one shared batch of inputs, where the weights of all members are stacked along a leading member axis, and return every member's predictions together with their average.
Member m computes
fm(x)=relu(xW1(m)+b1(m))W2(m)+b2(m),where relu(z) = max(z, 0) is applied elementwise. The dict params has the keys w1 of shape (M, D, K), b1 of shape (M, K), w2 of shape (M, K, O) and b2 of shape (M, O), so W1(m) is params["w1"][m], b1(m) is params["b1"][m], and so on. The input x has shape (N, D) and holds N rows that every member sees. Here D is the input width, K is the hidden width and O is the output width.
Return a dict with two float32 JAX arrays, outputs of shape (M, N, O), where outputs[m] is fm(x), and mean of shape (N, O), the average of outputs over the M members.
Input: params = {"w1":[[[1,0],[0,1]],[[1,1],[0,1]],[[-1,0],[0,2]]],"b1":[[0,0],[0,-1],[1,0]],"w2":[[[1],[1]],[[2],[-1]],[[0.5],[1]]],"b2":[[0],[1],[-1]]}, x = [[1,2],[-1,0.5]]
Output: {"outputs":[[[3.0],[0.5]],[[1.0],[1.0]],[[3.0],[1.0]]],"mean":[[2.333333],[0.833333]]}
Explanation: Member 0 maps the input (1, 2) to the hidden values relu(1, 2) = (1, 2) and then to 1 + 2 = 3. The three members predict 3, 1 and 3 for that input, so its mean is 7 / 3 = 2.333333.
Input: params = {"w1":[[[1,-1,0],[0,1,1],[1,0,-1]],[[0.5,0.5,0],[-1,0,1],[0,2,0]]],"b1":[[0,0.5,0],[0.1,0,-0.2]],"w2":[[[1,0],[0,1],[1,-1]],[[2,0],[0,-1],[1,1]]],"b2":[[0,0],[0.5,-0.5]]}, x = [[1,-2,0.5]]
Output: {"outputs":[[[1.5,0.0]],[[5.7,-2.0]]],"mean":[[3.6,-1.0]]}
Input: params = {"w1":[[[2,-1]]],"b1":[[-1,1]],"w2":[[[1],[3]]],"b2":[[0.25]]}, x = [[0],[1],[-1]]
Output: {"outputs":[[[3.25],[1.25],[6.25]]],"mean":[[3.25],[1.25],[6.25]]}
jax.vmap(f, in_axes=(0, None)) maps the first argument and shares the second.
in_axes=0 on a dict argument maps every array in the dict.
jnp.mean(outs, axis=0) averages over the ensemble axis.
Accepts: object
Accepts: array
Evaluate an ensemble of M small two-layer MLPs on one shared batch of inputs, where the weights of all members are stacked along a leading member axis, and return every member's predictions together with their average.
Member m computes
fm(x)=relu(xW1(m)+b1(m))W2(m)+b2(m),where relu(z) = max(z, 0) is applied elementwise. The dict params has the keys w1 of shape (M, D, K), b1 of shape (M, K), w2 of shape (M, K, O) and b2 of shape (M, O), so W1(m) is params["w1"][m], b1(m) is params["b1"][m], and so on. The input x has shape (N, D) and holds N rows that every member sees. Here D is the input width, K is the hidden width and O is the output width.
Return a dict with two float32 JAX arrays, outputs of shape (M, N, O), where outputs[m] is fm(x), and mean of shape (N, O), the average of outputs over the M members.
Input: params = {"w1":[[[1,0],[0,1]],[[1,1],[0,1]],[[-1,0],[0,2]]],"b1":[[0,0],[0,-1],[1,0]],"w2":[[[1],[1]],[[2],[-1]],[[0.5],[1]]],"b2":[[0],[1],[-1]]}, x = [[1,2],[-1,0.5]]
Output: {"outputs":[[[3.0],[0.5]],[[1.0],[1.0]],[[3.0],[1.0]]],"mean":[[2.333333],[0.833333]]}
Explanation: Member 0 maps the input (1, 2) to the hidden values relu(1, 2) = (1, 2) and then to 1 + 2 = 3. The three members predict 3, 1 and 3 for that input, so its mean is 7 / 3 = 2.333333.
Input: params = {"w1":[[[1,-1,0],[0,1,1],[1,0,-1]],[[0.5,0.5,0],[-1,0,1],[0,2,0]]],"b1":[[0,0.5,0],[0.1,0,-0.2]],"w2":[[[1,0],[0,1],[1,-1]],[[2,0],[0,-1],[1,1]]],"b2":[[0,0],[0.5,-0.5]]}, x = [[1,-2,0.5]]
Output: {"outputs":[[[1.5,0.0]],[[5.7,-2.0]]],"mean":[[3.6,-1.0]]}
Input: params = {"w1":[[[2,-1]]],"b1":[[-1,1]],"w2":[[[1],[3]]],"b2":[[0.25]]}, x = [[0],[1],[-1]]
Output: {"outputs":[[[3.25],[1.25],[6.25]]],"mean":[[3.25],[1.25],[6.25]]}
jax.vmap(f, in_axes=(0, None)) maps the first argument and shares the second.
in_axes=0 on a dict argument maps every array in the dict.
jnp.mean(outs, axis=0) averages over the ensemble axis.
Accepts: object
Accepts: array