Cultural { public static double distance(double[] var,double[] v1,double[] v2){ Asserts.validate(v1.length == CULTURAL_DIM, "Invalid vector length: v1" ); Asserts.validate(v2.length == CULTURAL_DIM, "Invalid vector length: v2" ); Asserts.validate(var.length == CULTURAL_DIM, "Invalid vector length: var"); Asserts.assertGreaterThanZero(var); double sum = 0; for(int i=0;i<CULTURAL_DIM;i++){ sum += Math.pow(v1[i]-v2[i], 2)/(CULTURAL_DIM*var[i]); } return sum; }  static double[] culturalVectorHelper(double powerDistance, double uncertainlyAvoidance, double individualismVsCollectivism, double mascVsFem, double confusianDynamism); static double distance(double[] var,double[] v1,double[] v2); static final int CULTURAL_DIM; }
@Test public void test1(){ double[] var = new double[]{3,7,5,9,6}; double[] v1 = new double[]{8,3,7,2,5}; double[] v2 = new double[]{9,8,4,6,1}; double res = Cultural.distance(var, v1, v2); Asserts.assertEquals(res, 2.02984126984127); }
@Test public void test2(){ double[] var = new double[]{64,3,49,92,18}; double[] v1 = new double[]{8,-32,7,0,-45}; double[] v2 = new double[]{97,-78,41,-4,-78}; double res = Cultural.distance(var, v1, v2); Asserts.assertEquals(res, 182.67294162230109); }
@Test public void test3(){ double[] var = new double[]{421.36,188.94,749.22,654.247,481.177}; double[] v1 = new double[]{248.124,-321.574,788.14,0.001,-459.298}; double[] v2 = new double[]{97.145,-78.658,417.0004,-4.02,-7865.3594}; double res = Cultural.distance(var, v1, v2); Asserts.assertEquals(res, 22908.21461937366358); }