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

Method pNorm

JSAT/src/jsat/linear/Vec.java:801–829  ·  view source on GitHub ↗

Returns the p-norm of this vector. @param p the norm type. 2 is a common value @return the p-norm of this vector

(double p)

Source from the content-addressed store, hash-verified

799 * @return the p-norm of this vector
800 */
801 public double pNorm(double p)
802 {
803 if (p <= 0)
804 throw new IllegalArgumentException("norm must be a positive value, not " + p);
805 double result = 0;
806 if (p == 1)
807 {
808 for (IndexValue iv : this)
809 result += abs(iv.getValue());
810 }
811 else if (p == 2)
812 {
813 for (IndexValue iv : this)
814 result += iv.getValue() * iv.getValue();
815 result = Math.sqrt(result);
816 }
817 else if (Double.isInfinite(p))
818 {
819 for (IndexValue iv : this)
820 result = Math.max(result, abs(iv.getValue()));
821 }
822 else
823 {
824 for (IndexValue iv : this)
825 result += pow(abs(iv.getValue()), p);
826 result = pow(result, 1 / p);
827 }
828 return result;
829 }
830
831 /**
832 * Computes the dot product between two vectors, which is equivalent to<br>

Callers 15

testGetSqrdNormMethod · 0.95
normalizeMethod · 0.95
pNormDistMethod · 0.95
updateMethod · 0.95
updateMethod · 0.95
applyRegularizationMethod · 0.95
runMethod · 0.95
mutableTransformMethod · 0.95
optimizeMethod · 0.95
testSetMethod · 0.45
testMutableAdd_doubleMethod · 0.45

Calls 3

getValueMethod · 0.45
maxMethod · 0.45
powMethod · 0.45

Tested by 15

testGetSqrdNormMethod · 0.76
testSetMethod · 0.36
testMutableAdd_doubleMethod · 0.36
testMutableMultiplyMethod · 0.36
testMutableDivideMethod · 0.36
testZeroOutMethod · 0.36
testPNormMethod · 0.36
testPNormMethod · 0.36
testSolveCGNR_4argsMethod · 0.36