[lab4] Now arrays are dynamically sized
This commit is contained in:
parent
70742fad8b
commit
332ca62569
@ -1,12 +1,12 @@
|
|||||||
fn compute_potential<const Is: usize, const Os: usize>(
|
fn compute_potential/*<const Is: usize, const Os: usize>*/(
|
||||||
weights: &[[f64; Is]; Os],
|
weights: &[&[f64/*; Is*/]/*; Os*/],
|
||||||
input_data: &[f64; Is],
|
input_data: &[f64/*; Is*/],
|
||||||
potential_data: &mut [f64; Is],
|
potential_data: &mut [f64/*; Is*/],
|
||||||
output_data: &mut [f64; Is],
|
output_data: &mut [f64/*; Is*/],
|
||||||
f: impl Fn(f64) -> f64,
|
f: impl Fn(f64) -> f64,
|
||||||
) {
|
) {
|
||||||
for (i, n) in weights.iter().enumerate() {
|
for (i, n) in weights.iter().enumerate() {
|
||||||
let P = input_data.iter().zip(n).map(|(x, w)| x * w).sum();
|
let P = input_data.iter().zip(n.iter()).map(|(x, w)| x * w).sum();
|
||||||
potential_data[i] = P;
|
potential_data[i] = P;
|
||||||
output_data[i] = f(P);
|
output_data[i] = f(P);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
fn calc_error<const Cs: usize, const Ns: usize>(
|
fn calc_error/*<const Cs: usize, const Ns: usize>*/(
|
||||||
next_errors: &[f64; Ns],
|
next_errors: &[f64/*; Ns*/],
|
||||||
weights: &[[f64; Cs]; Ns],
|
weights: &[&[f64/*; Cs*/]/*; Ns*/],
|
||||||
current_errors: &mut [f64; Cs]
|
current_errors: &mut [f64/*; Cs*/]
|
||||||
) {
|
) {
|
||||||
for i in 0..Cs {
|
for i in 0..current_errors.len() {
|
||||||
current_errors[i] = weights
|
current_errors[i] = weights
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
@ -12,17 +12,17 @@ fn calc_error<const Cs: usize, const Ns: usize>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn apply_error<const Cs: usize, const Ns: usize>(
|
fn apply_error/*<const Cs: usize, const Ns: usize>*/(
|
||||||
n: f64,
|
n: f64,
|
||||||
errors: &[f64; Ns],
|
errors: &[f64/*; Ns*/],
|
||||||
weights: &mut [[f64; Cs]; Ns],
|
weights: &mut [&mut [f64/*; Cs*/]/*; Ns*/],
|
||||||
current_potentials: &[f64; Cs],
|
current_potentials: &[f64/*; Cs*/],
|
||||||
next_potentials: &[f64; Cs],
|
next_potentials: &[f64/*; Cs*/],
|
||||||
f: impl Fn(f64) -> f64,
|
f: impl Fn(f64) -> f64,
|
||||||
f1: impl Fn(f64) -> f64
|
f1: impl Fn(f64) -> f64
|
||||||
) {
|
) {
|
||||||
for i in 0..Cs {
|
for i in 0..current_potentials.len() {
|
||||||
for j in 0..Ns {
|
for j in 0..next_potentials.len() {
|
||||||
let dw = n * errors[j] * f1(next_potentials[j]) * f(current_potentials[i]);
|
let dw = n * errors[j] * f1(next_potentials[j]) * f(current_potentials[i]);
|
||||||
weights[j][i] += dw;
|
weights[j][i] += dw;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user