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

Method pNorm

JSAT/src/jsat/linear/SparseVector.java:732–761  ·  view source on GitHub ↗
(double p)

Source from the content-addressed store, hash-verified

730 }
731
732 @Override
733 public double pNorm(double p)
734 {
735 if (p <= 0)
736 throw new IllegalArgumentException("norm must be a positive value, not " + p);
737 double result = 0;
738 if (p == 1)
739 {
740 for (int i = 0; i < used; i++)
741 result += abs(values[i]);
742 }
743 else if (p == 2)
744 {
745 for (int i = 0; i < used; i++)
746 result += values[i] * values[i];
747 result = Math.sqrt(result);
748 }
749 else if (Double.isInfinite(p))
750 {
751 for (int i = 0; i < used; i++)
752 result = Math.max(result, abs(values[i]));
753 }
754 else
755 {
756 for (int i = 0; i < used; i++)
757 result += Math.pow(Math.abs(values[i]), p);
758 result = pow(result, 1 / p);
759 }
760 return result;
761 }
762
763 @Override
764 public SparseVector clone()

Callers

nothing calls this directly

Calls 2

maxMethod · 0.45
powMethod · 0.45

Tested by

no test coverage detected