summaryrefslogtreecommitdiff
path: root/gi/posterior-regularisation/prjava/src/arr/F.java
diff options
context:
space:
mode:
Diffstat (limited to 'gi/posterior-regularisation/prjava/src/arr/F.java')
-rw-r--r--gi/posterior-regularisation/prjava/src/arr/F.java9
1 files changed, 9 insertions, 0 deletions
diff --git a/gi/posterior-regularisation/prjava/src/arr/F.java b/gi/posterior-regularisation/prjava/src/arr/F.java
index 54dadeac..79de5d1a 100644
--- a/gi/posterior-regularisation/prjava/src/arr/F.java
+++ b/gi/posterior-regularisation/prjava/src/arr/F.java
@@ -56,6 +56,7 @@ public class F {
}
public static double l1norm(double a[]){
+ // FIXME: this isn't the l1 norm for a < 0
double norm=0;
for(int i=0;i<a.length;i++){
norm += a[i];
@@ -63,6 +64,14 @@ public class F {
return norm;
}
+ public static double l2norm(double a[]){
+ double norm=0;
+ for(int i=0;i<a.length;i++){
+ norm += a[i]*a[i];
+ }
+ return Math.sqrt(norm);
+ }
+
public static int argmax(double probs[])
{
double m = Double.NEGATIVE_INFINITY;