Guest User

Untitled

a guest
Dec 10th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. def geneateRandomWeight(shape: Int*): Tensor = 2 * np.rand(shape.toArray) - 1
  2.  
  3. val biasedTrainSet = np.concatenate(Seq(trainSet, np.ones(trainSet.shape(0)).T), 1)
  4.  
  5. def initializeWeights(layers: List[Int], weights: List[Tensor] = List()): List[Tensor] = {
  6.  
  7. // the last layer is our networks target, so doesn't need any further weights
  8. if(layers.length < 2) return weights
  9.  
  10. // the second last layer doesn't need to take an account an additional bias column
  11. if(layers.length == 2) weights :+ geneateRandomWeight(layers.head + 1, layers.last)
  12.  
  13. // generate weigths aware of added bias column
  14. else initializeWeights(layers.tail, weights :+ geneateRandomWeight(layers.head + 1, layers.tail.head + 1))
  15. }
Add Comment
Please, Sign In to add comment