Gradient descent: Difference between revisions
m
→{{header|Perl 6}}: more mindless golfing
m (→{{header|Perl 6}}: more mindless golfing) |
|||
Line 202:
use v6.d;
sub steepestDescent(@x, $alpha is copy, $
my $g0 = g(@x) ; # Initial estimate of result.▼
my @fi = gradG(@x, $h, $g0) ; # Calculate initial
my $b = $alpha / (my $delG = (map {@fi[$_]²}, ^N).sum ).sqrt;▼
▲ # Calculate next value.
while ( $delG
for @fi.kv -> $i, $j { @x[$i] -= $b * $j } # Calculate next
@fi
}▼
$g1 > $g0 ?? ( $alpha /= 2 ) !! ( $g0 = $g1 ) # Adjust parameter.
}
sub gradG(@x is copy, $h, $g0) {
}
# Function for which minimum is to be found.
sub g(\x) { (x[0]-1)² * exp(-x[1]²)
|