MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / pNorm

Method pNorm

JSAT/src/jsat/linear/ShiftedVec.java:191–204  ·  view source on GitHub ↗
(double p)

Source from the content-addressed store, hash-verified

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)

Callers 1

testPNormMethod · 0.95

Calls 5

isSparseMethod · 0.95
lengthMethod · 0.95
powMethod · 0.45
nnzMethod · 0.45
getValueMethod · 0.45

Tested by 1

testPNormMethod · 0.76