package DeepLearning;
import java.util.Random;
import java.util.function.DoubleFunction;
import static DeepLearning.utils.*;
public class HiddenLayer {
public int N;
public int n_in;
public int n_out;
public double[][] W;
public double[] b;
public Random rng;
public DoubleFunction activation;
public DoubleFunction dactivation;
public HiddenLayer(int N, int n_in, int n_out, double[][] W, double[] b, Random rng, String activation) {
this.N = N;
this.n_in = n_in;
this.n_out = n_out;
if (rng == null) this.rng = new Random(1234);
else this.rng = rng;
if (W == null) {
this.W = new double[n_out][n_in];
double a = 1.0 / this.n_in;
for(int i=0; i sigmoid(x);
this.dactivation = (double x) -> dsigmoid(x);
} else if (activation == "tanh") {
this.activation = (double x) -> tanh(x);
this.dactivation = (double x) -> dtanh(x);
} else if (activation == "ReLU") {
this.activation = (double x) -> ReLU(x);
this.dactivation = (double x) -> dReLU(x);
} else {
throw new IllegalArgumentException("activation function not supported");
}
}
public double output(double[] input, double[] w, double b) {
double linear_output = 0.0;
for(int j=0; j