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

Function test_update_params

src/nn.rs:492–518  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

490
491 #[test]
492 fn test_update_params() {
493
494 let params1 = mat![ 0.1, 0.2, 0.4; 0.2, 0.1, 2.0 ];
495 let params2 = mat![ 0.8, 1.2, 0.6; 0.4, 0.5, 0.8;
496 1.4, 1.5, 2.0
497 ];
498
499 let mut n = NeuralNetwork::new()
500 .add_layer(3)
501 .add_layer(2)
502 .add_layer(3)
503 .set_params(0, params1)
504 .set_params(1, params2);
505
506 let d1 = mat![ 0.5, 0.3, 0.2; 0.5, 0.9, 1.4 ];
507 let d2 = mat![ 0.1, 1.0, 1.2; 0.1, 0.4, 1.1;
508 1.0, 2.0, 3.0
509 ];
510
511 n.update_params(&[d1, d2]);
512 assert!(n.params[0].similar(&mat![
513 0.6, 0.5, 0.6; 0.7, 1.0, 3.4
514 ], 0.001));
515 assert!(n.params[1].similar(&mat![
516 0.9, 2.2, 1.8; 0.5, 0.9, 1.9; 2.4, 3.5, 5.0
517 ], 0.001));
518 }
519
520 #[test]
521 fn test_params() {

Callers

nothing calls this directly

Calls 3

set_paramsMethod · 0.80
add_layerMethod · 0.80
update_paramsMethod · 0.80

Tested by

no test coverage detected