Passed
Push — main ( a92fbe...d29be2 )
by N.
05:41 queued 01:24
created

Generera   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 41
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A träna_fann() 0 29 2
A __construct() 0 3 1
1
<?php
2
3
/**
4
 * Klass FANNGenerera.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Moduler\FANNGenerera;
11
12
use Tips\Moduler\FANN;
13
14
/**
15
 * Klass FANNGenerera.
16
 */
17
final class Generera extends Fordelning {
18
	/**
19
	 * Uppdatera konstruktor.
20
	 */
21
	public function __construct(public FANN $fann) {
22
		parent::__construct($this->fann);
23
		$this->träna_fann();
24
	}
25
26
	/**
27
	 * Träna neuralt nätverk på befintliga data.
28
	 */
29
	private function träna_fann(): void {
30
		$this->hämta_värden($this->fann->odds->spel->db);
31
		$this->generera_träningsdata();
32
33
		$lager = [$this->neuroner_in, $this->neuroner_ut];
34
		$this->antal_lager = count($lager);
35
		$this->fann->fann = fann_create_shortcut_array($this->antal_lager, $lager);
36
37
		/**
38
		 * Aktiveringsfunktioner och träningsalgoritm.
39
		 */
40
		fann_set_activation_function_hidden($this->fann->fann, FANN_SIGMOID_SYMMETRIC_STEPWISE);
41
		fann_set_activation_function_output($this->fann->fann, FANN_SIGMOID_SYMMETRIC_STEPWISE);
42
		fann_set_training_algorithm($this->fann->fann, FANN_TRAIN_RPROP);
43
44
		$this->exists_fann = fann_cascadetrain_on_file($this->fann->fann, $this->fann->indatafil, $this->max_neuroner, 0, $this->fann->feltolerans);
45
46
		$logg = "Kunde inte träna FANN.<br>";
47
		if ($this->exists_fann) {
48
			fann_save($this->fann->fann, $this->fann->utdatafil);
49
			unlink($this->fann->indatafil);
50
			$logg = 'MSE: ' . fann_get_mse($this->fann->fann) . '<br>';
51
		}
52
		$this->fann->logg .= $logg;
53
54
		$this->fann->db_preferenser->spara_preferens('fann.status', $this->fann->logg);
55
56
		$this->generera_parametrar();
57
		$this->beräkna_fannfördelning();
58
	}
59
}
60