MCPcopy Create free account
hub / github.com/daniel-e/rustml / predict

Method predict

src/nn.rs:107–117  ·  view source on GitHub ↗

Computes the output of the neural network for the given input.

(&self, input: &[f64])

Source from the content-addressed store, hash-verified

105
106 /// Computes the output of the neural network for the given input.
107 pub fn predict(&self, input: &[f64]) -> Vec<f64> {
108
109 assert!(self.layers.len() >= 2, "At least two layers are required.");
110 assert!(input.len() == self.input_size(), "Dimension of input vector does not match.");
111
112 self.params.iter()
113 .fold(input.to_vec(),
114 |v, ref params| [1.0].append(&params.mul_vec(&v).sigmoid())
115 )
116 .iter().skip(1).cloned().collect() // skip the bias unit TODO more elegant way?
117 }
118
119 pub fn optimize(&self, x: &Matrix<f64>, labels: &Matrix<f64>, p: OptParams<f64>) -> NeuralNetwork {
120

Callers 5

errorMethod · 0.80
test_predict_two_layerFunction · 0.80
test_predict_three_layerFunction · 0.80
mainFunction · 0.80
plot_nnFunction · 0.80

Calls 4

appendMethod · 0.80
sigmoidMethod · 0.80
iterMethod · 0.45
to_vecMethod · 0.45

Tested by 2

test_predict_two_layerFunction · 0.64
test_predict_three_layerFunction · 0.64