Passed
Push — master ( 3989eb...44f0a8 )
by Ruben
01:51
created

src/CategoricalDataset.php (1 issue)

Check for undefined variables.

Best Practice Comprehensibility Minor
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) 
25
    {
26
        $this->data = $data;
27
    }
28
    
29
    /*
30
     * @param
31
     */    
32
    function setEncodedFeatures($array) 
33
    {
34
        $array = sort($array);
35
        $this->encodedValues = [];
36
        $this->sortedEncodedFeatures = $array;
37
        $this->newEncodedSize = count($array);
38
        foreach($this->sortedEncodedFeatures as $col){
39
            $vals = $this->getUniqueValues($col);
40
            $this->encodedValues[] = $vals;
41
            $this->featIndexMap[$col] = count($vals);
42
            $this->featEncode[$col] = $this->encodeFeature(count($vals));
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) 
56
    {
57
        $resp = [];
58
        $resp = Matrix::getColumn($data, $col);
59
        $resp = array_unique($resp);
60
        return $resp;
61
    }
62
    
63
    
64
    /*
65
     * @param
66
     */
67
    function encodeFeature($size) 
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(){
82
        $transformer  = [];
83
        $ndata = [];
84
        for ($j=0; $j<$ndim; $j++) {
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
The variable $npoints does not exist. Did you maybe mean $npoint?
Loading history...
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