/*
 * ARX: Powerful Data Anonymization
 * Copyright 2012 - 2015 Florian Kohlmayer, Fabian Prasser
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.deidentifier.arx.metric.v2;

import org.deidentifier.arx.metric.InformationLoss;

/**
 * This class implements an information loss which can be represented as a
 * decimal number per quasi-identifier. As an aggregate function, the geometric mean
 * is applied. To handle zero values while not violating guarantees required for pruning
 * based on lower bounds, 1d is added to every individual value and 1d is subtracted from the
 * final result.
 *
 * @author Fabian Prasser
 * @author Florian Kohlmayer
 */
public class ILMultiDimensionalGeometricMean extends AbstractILMultiDimensionalReduced {

    /** SVUID. */
    private static final long serialVersionUID = 621501985571033348L;

    /**
     * Creates a new instance.
     *
     * @param values
     * @param weights
     */
    ILMultiDimensionalGeometricMean(final double[] values,
                                    final double[] weights) {
        super(values, weights);
    }

    @Override
    public InformationLoss<double[]> clone() {
        return new ILMultiDimensionalGeometricMean(getValues(),
                                                   getWeights());
    }

    @Override
    protected double getAggregate() {
        double[] values = getValues();
        double[] weights = getWeights();
        double result = 1.0d;
        for (int i = 0; i < values.length; i++) {
            result *= Math.pow((values[i] + 1d) * weights[i], 1.0d / (double) values.length);
        }
        return result - 1d;
    }
}

@@ -1262,17 +1262,21 @@
 duced %7B%0A
+    
 %0A
-
     /** 
@@ -1355,17 +1355,21 @@
 33348L;%0A
+    
 %0A
-
     /**%0A
@@ -1608,33 +1608,37 @@
 weights);%0A    %7D%0A
+    
 %0A
-
     @Override%0A  
@@ -1818,17 +1818,21 @@
 ;%0A    %7D%0A
+    
 %0A
-
     @Ove
@@ -2080,14 +2080,8 @@
 s%5Bi%5D
- + 1d)
  * w
@@ -2089,16 +2089,22 @@
 ights%5Bi%5D
+ + 1d)
 , 1.0d /

fix geometric mean with weights for f***s sake!