Passed
Push — master ( 44f0a8...120e65 )
by Ruben
01:45
created

src/CategoricalDataset.php (5 issues)

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
0 ignored issues
show
The type SiteAnalyzer\list was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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 = [];
0 ignored issues
show
Documentation Bug introduced by
It seems like array() of type array is incompatible with the declared type SiteAnalyzer\list of property $encodedValues.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
62
        $this->sortedEncodedFeatures = $array;
0 ignored issues
show
Documentation Bug introduced by
It seems like $array of type boolean is incompatible with the declared type SiteAnalyzer\list of property $sortedEncodedFeatures.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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 = [];
0 ignored issues
show
The assignment to $ndata is dead and can be removed.
Loading history...
109
        $n = count($this->data);
110
        $ndim = count($this->data[0]);
111
        for ($j=0; $j<$d; $j++) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $d seems to be never defined.
Loading history...
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