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
|
|
|
* @var list |
|
|
|
|
23
|
|
|
*/ |
24
|
|
|
protected $data; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var list |
28
|
|
|
*/ |
29
|
|
|
protected $sortedEncodedFeatures; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var list |
33
|
|
|
*/ |
34
|
|
|
protected $encodedValues; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var list |
38
|
|
|
*/ |
39
|
|
|
protected $featEncode; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var list |
43
|
|
|
*/ |
44
|
|
|
protected $featIndexMap; |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/* |
48
|
|
|
* @param |
49
|
|
|
*/ |
50
|
|
|
public function __construct($data) |
51
|
|
|
{ |
52
|
|
|
$this->data = $data; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/* |
56
|
|
|
* @param |
57
|
|
|
*/ |
58
|
|
|
public function setEncodedFeatures($array) |
59
|
|
|
{ |
60
|
|
|
$array = sort($array); |
61
|
|
|
$this->encodedValues = []; |
|
|
|
|
62
|
|
|
$this->sortedEncodedFeatures = $array; |
|
|
|
|
63
|
|
|
foreach($this->sortedEncodedFeatures as $col){ |
|
|
|
|
64
|
|
|
$vals = $this->getUniqueValues($col); |
65
|
|
|
$this->encodedValues[] = $vals; |
66
|
|
|
$this->featIndexMap[$col] = count($vals); |
67
|
|
|
$this->featEncode[$col] = $this->encodeFeature(count($vals)); |
68
|
|
|
//$this->featDecode[$col] = function($val, $arr){ return $this->getDecodedFeature($val, $arr, ); } |
69
|
|
|
//$this->newEncodedSize += count($vals)-1; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/*for ($i=0;$i<$this->newEncodedSize:$i++) { |
73
|
|
|
|
74
|
|
|
}*/ |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/* |
78
|
|
|
* @param |
79
|
|
|
*/ |
80
|
|
|
private function getUniqueValues($col) |
81
|
|
|
{ |
82
|
|
|
$resp = []; |
|
|
|
|
83
|
|
|
$resp = Matrix::getColumn($this->data, $col); |
84
|
|
|
$resp = array_unique($resp); |
85
|
|
|
return $resp; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
/* |
90
|
|
|
* @param |
91
|
|
|
*/ |
92
|
|
|
private function encodeFeature($size) |
93
|
|
|
{ |
94
|
|
|
$resp = []; |
95
|
|
|
for ($i=0;$i<$size;$i++) { |
96
|
|
|
$tmp = array_fill(0, $size, 0); |
97
|
|
|
$tmp[$i] = 1; |
98
|
|
|
$resp[] = $tmp; |
99
|
|
|
} |
100
|
|
|
return $resp; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/* |
104
|
|
|
* @param |
105
|
|
|
*/ |
106
|
|
|
public function encode(){ |
107
|
|
|
$transformer = []; |
108
|
|
|
$ndata = []; |
|
|
|
|
109
|
|
|
$n = count($this->data); |
110
|
|
|
$ndim = count($this->data[0]); |
111
|
|
|
for ($j=0; $j<$d; $j++) { |
|
|
|
|
112
|
|
|
$transformer[] = function($val){ return [$val]; }; |
113
|
|
|
} |
114
|
|
|
foreach($this->sortedEncodedFeatures as $col) { |
115
|
|
|
$transformer[$col] = function($val) { return $this->featEncode[$col][$val]; }; |
|
|
|
|
116
|
|
|
} |
117
|
|
|
$ndata = []; |
118
|
|
|
for ($i=0; $i<$n; $i++) { |
119
|
|
|
$npoint = []; |
120
|
|
|
for ($j=0; $j<$ndim; $j++) { |
121
|
|
|
$npoint += $transformer[$j]($data[$i][$j]); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
$ndata[] = $npoint; |
124
|
|
|
} |
125
|
|
|
return $ndata; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/* |
129
|
|
|
* @param |
130
|
|
|
* |
131
|
|
|
function decode($ndata){ |
132
|
|
|
$resp = []; |
133
|
|
|
foreach ($ndata as $row) { |
134
|
|
|
$resp[] = $this->decodeRow($row); |
135
|
|
|
} |
136
|
|
|
return $resp; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/* |
140
|
|
|
* @param |
141
|
|
|
* |
142
|
|
|
function decodeRow($row){ |
143
|
|
|
$resp = []; |
144
|
|
|
$n = count($row); |
145
|
|
|
for ($i=0; $i<$n; $i++) { |
146
|
|
|
$resp[] = $this->decodeFeature($i, $row); |
147
|
|
|
} |
148
|
|
|
return $resp; |
149
|
|
|
}*/ |
150
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths