| 189 | } |
| 190 | |
| 191 | @Override |
| 192 | public double pNorm(double p) |
| 193 | { |
| 194 | if(!isSparse()) |
| 195 | return super.pNorm(p); |
| 196 | //else sparse base, we can save some work |
| 197 | //contributes of zero values |
| 198 | double baseZeroContribs = pow(abs(shift), p)*(length()-base.nnz()); |
| 199 | //+ contribution of non zero values |
| 200 | double baseNonZeroContribs = 0; |
| 201 | for(IndexValue iv : base) |
| 202 | baseNonZeroContribs += pow(abs(iv.getValue()+shift), p); |
| 203 | return pow(baseNonZeroContribs+baseZeroContribs, 1/p); |
| 204 | } |
| 205 | |
| 206 | // TODO: In the case of the y also being a ShiftedVec and sparse some significant performance could be saved. |
| 207 | // public double pNormDist(double p, Vec y) |