Last active
March 25, 2025 10:32
-
-
Save trikitrok/68e3193588ce4ae022048fcded74a9f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ConjugatedGradient { | |
private readonly float $tolerance; | |
private readonly int $maxIterations; | |
public function __construct(float $tolerance = 1e-6, int $maxIterations = 1000) { | |
$this->tolerance = $tolerance; | |
$this->maxIterations = $maxIterations; | |
} | |
public function minimize(callable $gradFn, array $init): array { | |
// minimization code... | |
} | |
// more code... | |
} | |
<?php | |
class LinearDescent { | |
public function min( | |
callable $gradFn, | |
array $init, | |
array $config | |
): array { | |
// minimization code... | |
} | |
// more code... | |
} | |
/////////////////////////////////// | |
<?php | |
class ConjugatedGradient { | |
private readonly float $tolerance; | |
private readonly int $maxIterations; | |
public function __construct(float $tolerance = 1e-6, int $maxIterations = 1000) { | |
$this->tolerance = $tolerance; | |
$this->maxIterations = $maxIterations; | |
} | |
public function minimize(callable $gradFn, array $init): array { | |
// minimization code... | |
} | |
// more code... | |
} | |
<?php | |
class LinearDescent { | |
private readonly float $tolerance; | |
private readonly int $maxIterations; | |
private readonly float $learningRate; | |
public function __construct(float $tolerance = 1e-6, int $maxIterations = 1000, float $learningRate = 0.01) { | |
$this->tolerance = $tolerance; | |
$this->maxIterations = $maxIterations; | |
$this->learningRate = $learningRate; | |
} | |
public function minimize(callable $gradFn, array $init): array { | |
// minimization code... | |
} | |
/////////////////////////////////// | |
<?php | |
interface Minimization { | |
public function minimize(callable $gradFn, array $init): array; | |
} | |
<?php | |
class ConjugatedGradientMinimization implements Minimization { | |
private readonly float $tolerance; | |
private readonly int $maxIterations; | |
public function __construct(float $tolerance = 1e-6, int $maxIterations = 1000) { | |
$this->tolerance = $tolerance; | |
$this->maxIterations = $maxIterations; | |
} | |
public function minimize(callable $gradFn, array $init): array { | |
// minimization code... | |
} | |
// more code... | |
} | |
<?php | |
class LinearDescentMinimization implements Minimization { | |
private readonly float $tolerance; | |
private readonly int $maxIterations; | |
private readonly float $learningRate; | |
public function __construct(float $tolerance = 1e-6, int $maxIterations = 1000, float $learningRate = 0.01) { | |
$this->tolerance = $tolerance; | |
$this->maxIterations = $maxIterations; | |
$this->learningRate = $learningRate; | |
} | |
public function minimize(callable $gradFn, array $init): array { | |
// minimization code... | |
} | |
// more code... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment