1 | <?php |
||||
2 | /** |
||||
3 | * |
||||
4 | * (c) Ruben Dorado <[email protected]> |
||||
5 | * |
||||
6 | * For the full copyright and license information, please view the LICENSE |
||||
7 | * file that was distributed with this source code. |
||||
8 | */ |
||||
9 | namespace SiteAnalyzer; |
||||
10 | /** |
||||
11 | * class CategoricalDataset |
||||
12 | * |
||||
13 | * @package SiteAnalyzer |
||||
14 | * @author Ruben Dorado <[email protected]> |
||||
15 | * @copyright 2018 Ruben Dorado |
||||
16 | * @license http://www.opensource.org/licenses/MIT The MIT License |
||||
17 | */ |
||||
18 | class CategoricalDataset |
||||
19 | { |
||||
20 | |||||
21 | /* |
||||
22 | * @param |
||||
23 | */ |
||||
24 | function __construct($data) |
||||
0 ignored issues
–
show
|
|||||
25 | { |
||||
26 | $this->data = $data; |
||||
0 ignored issues
–
show
|
|||||
27 | } |
||||
28 | |||||
29 | /* |
||||
30 | * @param |
||||
31 | */ |
||||
32 | function setEncodedFeatures($array) |
||||
0 ignored issues
–
show
|
|||||
33 | { |
||||
34 | $array = sort($array); |
||||
35 | $this->encodedValues = []; |
||||
0 ignored issues
–
show
|
|||||
36 | $this->sortedEncodedFeatures = $array; |
||||
0 ignored issues
–
show
|
|||||
37 | $this->newEncodedSize = count($array); |
||||
0 ignored issues
–
show
$array of type boolean is incompatible with the type Countable|array expected by parameter $var of count() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
38 | foreach($this->sortedEncodedFeatures as $col){ |
||||
39 | $vals = $this->getUniqueValues($col); |
||||
40 | $this->encodedValues[] = $vals; |
||||
41 | $this->featIndexMap[$col] = count($vals); |
||||
0 ignored issues
–
show
|
|||||
42 | $this->featEncode[$col] = $this->encodeFeature(count($vals)); |
||||
0 ignored issues
–
show
|
|||||
43 | //$this->featDecode[$col] = function($val, $arr){ return $this->getDecodedFeature($val, $arr, ); } |
||||
44 | //$this->newEncodedSize += count($vals)-1; |
||||
45 | } |
||||
46 | |||||
47 | /*for ($i=0;$i<$this->newEncodedSize:$i++) { |
||||
48 | |||||
49 | }*/ |
||||
50 | } |
||||
51 | |||||
52 | /* |
||||
53 | * @param |
||||
54 | */ |
||||
55 | function getUniqueValues($col) |
||||
0 ignored issues
–
show
|
|||||
56 | { |
||||
57 | $resp = []; |
||||
58 | $resp = Matrix::getColumn($data, $col); |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
59 | $resp = array_unique($resp); |
||||
60 | return $resp; |
||||
61 | } |
||||
62 | |||||
63 | |||||
64 | /* |
||||
65 | * @param |
||||
66 | */ |
||||
67 | function encodeFeature($size) |
||||
0 ignored issues
–
show
|
|||||
68 | { |
||||
69 | $resp = []; |
||||
70 | for ($i=0;$i<$size;$i++) { |
||||
71 | $tmp = array_fill(0, $size, 0); |
||||
72 | $tmp[$i] = 1; |
||||
73 | $resp[] = $tmp; |
||||
74 | } |
||||
75 | return $resp; |
||||
76 | } |
||||
77 | |||||
78 | /* |
||||
79 | * @param |
||||
80 | */ |
||||
81 | function encode(){ |
||||
0 ignored issues
–
show
|
|||||
82 | $transformer = []; |
||||
83 | $ndata = []; |
||||
0 ignored issues
–
show
|
|||||
84 | for ($j=0; $j<$ndim; $j++) { |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
85 | $transformer[] = function($val){ return [$val]; }; |
||||
86 | } |
||||
87 | foreach($this->sortedEncodedFeatures as $col) { |
||||
88 | $transformer[$col] = function($val) { return $this->featEncode[$col][$val]; }; |
||||
89 | } |
||||
90 | $ndata = []; |
||||
91 | for ($i=0; $i<$npoints; $i++) { |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
92 | $npoint = []; |
||||
93 | for ($j=0; $j<$ndim; $j++) { |
||||
94 | $npoint += $transformer[$j]($data[$i][$j]); |
||||
95 | } |
||||
96 | $ndata[] = $npoint; |
||||
97 | } |
||||
98 | return $ndata; |
||||
99 | } |
||||
100 | |||||
101 | /* |
||||
102 | * @param |
||||
103 | * |
||||
104 | function decode($ndata){ |
||||
105 | $resp = []; |
||||
106 | foreach ($ndata as $row) { |
||||
107 | $resp[] = $this->decodeRow($row); |
||||
108 | } |
||||
109 | return $resp; |
||||
110 | } |
||||
111 | |||||
112 | /* |
||||
113 | * @param |
||||
114 | * |
||||
115 | function decodeRow($row){ |
||||
116 | $resp = []; |
||||
117 | $n = count($row); |
||||
118 | for ($i=0; $i<$n; $i++) { |
||||
119 | $resp[] = $this->decodeFeature($i, $row); |
||||
120 | } |
||||
121 | return $resp; |
||||
122 | }*/ |
||||
123 | |||||
124 | } |
||||
125 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.