/** * Preset Weights - Initialize a BPNN with (pre-trained) weight matrices W (which also determines X dimensions). * @param W pre-trained weight matrix (should include bias weights, assume W[-1]-1 hidden units in penultimate layer not including bias]) * @param L the number of labels (for making the final matrix) */ public void presetWeights(Matrix W[], int L) throws Exception { r = new Random(0); this.W = new Matrix[W.length+1]; for(int l = 0; l < W.length; l++) { this.W[l] = W[l]; } int h = W[1].getRowDimension()-1; this.W[W.length] = MatrixUtils.randomn(h + 1, L, r).timesEquals(0.1); makeMomentumMatrices(); }
/** * InitWeights - Initialize a BPNN of H.length hidden layers with H[0], H[1], etc hidden units in each layer (W will be random, and of the corresponding dimensions). * @param d number of visible units * @param L number of labels (output units) * @param H number of units in hidden layers, H.length = number of hidden layers. CURRENTLY LIMITED TO 1. */ public void initWeights(int d, int L, int H[]) throws Exception { int numHidden = H.length; if (getDebug()) { System.out.println("Initializing "+(H.length)+" hidden Layers ..."); System.out.println("d = "+d); System.out.println("L = "+L); } // We need weights for Z to Y, as well as from X to Z Matrix W[] = new Matrix[H.length+1]; int h = H[0]; H = new int[]{d,h,L}; // Hidden layers System.out.println(""+Arrays.toString(H)); for(int n = 0; n < H.length-1; n++) { W[n] = MatrixUtils.randomn(H[n] + 1, H[n + 1], r).timesEquals(0.1); if (getDebug()) System.out.println("W["+n+"] = "+(H[n]+1)+" x "+H[n+1]); } //setWeights(W, L); this.W = W; makeMomentumMatrices(); }
/** * Preset Weights - Initialize a BPNN with (pre-trained) weight matrices W (which also determines X dimensions). * @param W pre-trained weight matrix (should include bias weights, assume W[-1]-1 hidden units in penultimate layer not including bias]) * @param L the number of labels (for making the final matrix) */ public void presetWeights(Matrix W[], int L) throws Exception { r = new Random(0); this.W = new Matrix[W.length+1]; for(int l = 0; l < W.length; l++) { this.W[l] = W[l]; } int h = W[1].getRowDimension()-1; this.W[W.length] = MatrixUtils.randomn(h + 1, L, r).timesEquals(0.1); makeMomentumMatrices(); }
/** * InitWeights - Initialize a BPNN of H.length hidden layers with H[0], H[1], etc hidden units in each layer (W will be random, and of the corresponding dimensions). * @param d number of visible units * @param L number of labels (output units) * @param H number of units in hidden layers, H.length = number of hidden layers. CURRENTLY LIMITED TO 1. */ public void initWeights(int d, int L, int H[]) throws Exception { int numHidden = H.length; if (getDebug()) { System.out.println("Initializing "+(H.length)+" hidden Layers ..."); System.out.println("d = "+d); System.out.println("L = "+L); } // We need weights for Z to Y, as well as from X to Z Matrix W[] = new Matrix[H.length+1]; int h = H[0]; H = new int[]{d,h,L}; // Hidden layers System.out.println(""+Arrays.toString(H)); for(int n = 0; n < H.length-1; n++) { W[n] = MatrixUtils.randomn(H[n] + 1, H[n + 1], r).timesEquals(0.1); if (getDebug()) System.out.println("W["+n+"] = "+(H[n]+1)+" x "+H[n+1]); } //setWeights(W, L); this.W = W; makeMomentumMatrices(); }