package edu.ncsu.snap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Util {

	public Map<Integer, Integer> makeSparse(int[] d, int n){
		Map<Integer, Integer> res = new HashMap<Integer, Integer>();
		
		for(int i = 0; i < d.length; i++){
			if(d[i] != -1){
				res.put(i, d[i]);
			}
		}
		return res;
	}

	public List<Integer> diff(List<Integer> f1, List<Integer> f2, int D) {
		List<Integer> res = new ArrayList<Integer>();

		for (int i = 0; i < D; i++) {
			res.add(Math.abs(f1.get(i) - f2.get(i)));
		}

		return res;
	}

	// Inner product
	public static double inp(Map<Integer,Integer> phi, double theta[])
	{
		double res = 0;
		for (Map.Entry<Integer,Integer> entry : phi.entrySet()) {
			res += entry.getValue() * theta[entry.getKey()];
		}
		return res;
	}
	
}

@@ -124,16 +124,159 @@
 Map;%0D%0A%0D%0A
+//Computes similarity metrics between edges and nodes based on the corresponding features%0D%0A//and implements common data preprocessing methods%0D%0A
 public c
@@ -349,16 +349,75 @@
 nt n)%7B%0D%0A
+%09%09//Data preprocessing to convert an array into a hashmap%0D%0A
 %09%09Map%3CIn
@@ -585,24 +585,24 @@
 res;%0D%0A%09%7D%0D%0A%0D%0A
-
 %09public List
@@ -662,16 +662,104 @@
 t D) %7B%0D%0A
+%09%09//Computes similarity values between the nodes and edges with the passed feature set%0D%0A
 %09%09List%3CI

Update Util.java