当前位置: 首页>>代码示例>>Java>>正文


Java DataHandle.getNumRows方法代码示例

本文整理汇总了Java中org.deidentifier.arx.DataHandle.getNumRows方法的典型用法代码示例。如果您正苦于以下问题:Java DataHandle.getNumRows方法的具体用法?Java DataHandle.getNumRows怎么用?Java DataHandle.getNumRows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.deidentifier.arx.DataHandle的用法示例。


在下文中一共展示了DataHandle.getNumRows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toArray

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Returns an array representation of the subset, in which all rows that are not part of the
 * subset have been suppressed. This method does *not* preserve the order of tuples from the
 * input handle.
 * 
 * @param handle
 * @param subset
 * @return
 */
public String[][] toArray(DataHandle handle, DataHandle subset) {
    List<String[]> list = new ArrayList<String[]>();
    Iterator<String[]> iter = subset.iterator();
    iter.next(); // Skip header
    for (; iter.hasNext();) {
        list.add(iter.next());
    }
    
    String[] suppressed = new String[handle.getNumColumns()];
    Arrays.fill(suppressed, "*"); // TODO
    for (int i = 0; i < handle.getNumRows() - subset.getNumRows(); i++) {
        list.add(suppressed);
    }
    
    return list.toArray(new String[list.size()][]);
}
 
开发者ID:arx-deidentifier,项目名称:risk-benchmark,代码行数:26,代码来源:DataConverter.java

示例2: getInputFrequencies

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Returns the frequencies of values in input data for all rows with transformation level >= level
 * @param transformations
 * @param column
 * @param level
 * @return
 */
private Map<String, Double> getInputFrequencies( int[] transformations, int column, int level) {
    DataHandle input = getInput();
    Map<String, Double> result = new HashMap<String, Double>();
    for (int row = 0; row < input.getNumRows(); row++) {
        if (transformations[row] >= level) {
            String value = input.getValue(row, column);
            Double count = result.get(value);
            result.put(value, count != null ? count + 1d : 1d);
        }

        // Check
        checkInterrupt();
    }
    return result;
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:23,代码来源:QualityModelColumnOrientedNonUniformEntropy.java

示例3: getOutputFrequencies

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Returns the frequencies of values in input data on the target level in output for all rows with transformation level >= level
 * @param transformations
 * @param generalizationFunctions
 * @param column
 * @param level
 * @param target
 * @return
 */
private Map<String, Double> getOutputFrequencies(int[] transformations,
                                                 Map<String, String>[] generalizationFunctions,
                                                 int column, 
                                                 int level, 
                                                 int target) {
    Map<String, Double> result = new HashMap<String, Double>();
    DataHandle input = getInput();
    for (int row = 0; row < input.getNumRows(); row++) {
        if (transformations[row] >= level) {
            String value = generalizationFunctions[target].get(input.getValue(row, column));
            Double count = result.get(value);
            result.put(value, count != null ? count + 1d : 1d);
        }

        // Check
        checkInterrupt();
    }
    return result;
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:29,代码来源:QualityModelColumnOrientedNonUniformEntropy.java

示例4: getQualityStatistics

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Returns data quality according to various models. This is a special variant of 
 * the method supporting arbitrary user-defined outputs.
 * 
 * @param output
 * @return
 */
public StatisticsQuality getQualityStatistics(DataHandle output) {

    // Reset stop flag
    interrupt.value = false;
    progress.value = 0;

    // Prepare
    DataHandleInternal input = this.handle.getAssociatedInput();
    ARXConfiguration config = this.handle.getConfiguration();
    
    // Very basic check        
    if (output.getNumRows() != input.getNumRows() ||
        output.getNumColumns() != input.getNumColumns()) {
        throw new IllegalArgumentException("Input and output do not match");
    }

    // Build and return
    return new StatisticsQuality(input.getHandle(), output, config, interrupt, progress);
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:27,代码来源:StatisticsBuilder.java

示例5: getGroupify

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Returns a groupified version of the dataset
 * 
 * @param handle
 * @param indices
 * @return
 */
private Groupify<TupleWrapper> getGroupify(DataHandle handle, int[] indices) {
    
    // Prepare
    int capacity = handle.getNumRows() / 10;
    capacity = capacity > 10 ? capacity : 10;
    Groupify<TupleWrapper> groupify = new Groupify<TupleWrapper>(capacity);
    int numRows = handle.getNumRows();
    for (int row = 0; row < numRows; row++) {
        TupleWrapper tuple = new TupleWrapper(handle, indices, row);
        groupify.add(tuple);
        checkInterrupt();
    }
    
    return groupify;
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:23,代码来源:StatisticsQuality.java

示例6: updateLabels

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Updates both labels
 */
private void updateLabels() {

    if (model == null || model.getInputConfig() == null || model.getInputConfig().getInput() == null) {
        return;
    }

    DataHandle handle = model.getInputConfig().getInput().getHandle();
    long sampleSize = handle.getNumRows();
    long populationSize = (long)model.getRiskModel().getPopulationSize();
    double fraction = (double)sampleSize / (double)populationSize;
    text.setText(SWTUtil.getPrettyString(fraction));
    text.setToolTipText(String.valueOf(fraction));
    text2.setText(SWTUtil.getPrettyString(populationSize));
    text2.setToolTipText(String.valueOf(populationSize));
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:19,代码来源:ViewPopulationModel.java

示例7: testMicroaggregationAdult

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Test microaggregation arithmetic mean with larger dataset
 * @throws IOException
 */
@Test
public void testMicroaggregationAdult() throws IOException {
    Data data = getDataObject("./data/adult.csv");
    
    data.getDefinition().setAttributeType("age", MicroAggregationFunction.createArithmeticMean());
    data.getDefinition().setDataType("age", DataType.INTEGER);
    
    final ARXAnonymizer anonymizer = new ARXAnonymizer();
    final ARXConfiguration config = ARXConfiguration.create();
    config.addPrivacyModel(new KAnonymity(5));
    config.setMaxOutliers(1d);
    config.setQualityModel(Metric.createLossMetric(AggregateFunction.RANK));
    
    ARXResult result = anonymizer.anonymize(data, config);
    DataHandle exptectedOutput = Data.create("./data/adult_age_microaggregated.csv", StandardCharsets.UTF_8, ';').getHandle();
    
    DataHandle output = result.getOutput();
    for (int i = 0; i < output.getNumRows(); i++) {
        for (int j = 0; j < output.getNumColumns(); j++) {
            assertEquals(exptectedOutput.getValue(i, j), output.getValue(i, j));
        }
    }
    
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:29,代码来源:TestMicroaggregation.java

示例8: getSuppressed

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Returns the number of suppressed tuples
 * 
 * @param output
 * @return
 */
private static int getSuppressed(DataHandle output) {
    int count = 0;
    for (int i = 0; i < output.getNumRows(); i++) {
        if (output.isOutlier(i)) {
            count++;
        }
    }
    return count;
}
 
开发者ID:arx-deidentifier,项目名称:risk-benchmark,代码行数:16,代码来源:BenchmarkExperiment3.java

示例9: computeUpperBounds

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Computes the upper bounds
 * @param dataset
 * @throws IOException
 */
private void computeUpperBounds(BenchmarkDataset dataset) throws IOException {
    // Prepare
    Data data = BenchmarkSetup.getData(dataset);
    DataDefinition definition = data.getDefinition();
    DataHandle inputHandle = data.getHandle();

    // Convert to completely suppressed output data
    DataConverter converter = new DataConverter();
    String[][] input = converter.toArray(inputHandle);
    String[][] output = new String[inputHandle.getNumRows()][inputHandle.getNumColumns()];
    for (int i = 0; i < inputHandle.getNumRows(); i++) {
        Arrays.fill(output[i], "*");
    }
    Map<String, String[][]> hierarchies = converter.toMap(definition);
    String[] header = converter.getHeader(inputHandle);
    int[] transformation = new int[definition.getQuasiIdentifyingAttributes().size()];
    for (String attr : definition.getQuasiIdentifyingAttributes()) {
        int maxLevel = definition.getHierarchy(attr)[0].length - 1;
        transformation[inputHandle.getColumnIndexOf(attr)] = maxLevel;
    }

    // Compute metrics
    double outputLoss = new UtilityMeasureLoss<Double>(header, hierarchies, AggregateFunction.GEOMETRIC_MEAN).evaluate(output).getUtility();
    double outputEntropy = new UtilityMeasureNonUniformEntropyWithLowerBoundNormalized<Double>(header, input, hierarchies).evaluate(output, transformation).getUtility();

    // Store results
    if (!upper.containsKey(dataset)) {
        upper.put(dataset, new HashMap<BenchmarkUtilityMeasure, Double>());
    }
    upper.get(dataset).put(BenchmarkUtilityMeasure.LOSS, outputLoss);
    upper.get(dataset).put(BenchmarkUtilityMeasure.ENTROPY, outputEntropy);
}
 
开发者ID:arx-deidentifier,项目名称:risk-benchmark,代码行数:38,代码来源:BenchmarkMetadataUtility.java

示例10: getNumbersFromNumericColumn

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Parses numbers from a numeric column
 * @param handle
 * @param column
 * @return
 */
private double[] getNumbersFromNumericColumn(DataHandle handle, int column) {
    
    try {
        
        // Prepare
        String attribute = handle.getAttributeName(column);
        double[] result = new double[handle.getNumRows()];
        
        // Parse numbers
        if (handle.getDataType(attribute) instanceof DataTypeWithRatioScale) {

            QualityConfigurationValueParser<?> parser = QualityConfigurationValueParser.create(handle.getDataType(attribute));
            for (int row = 0; row < handle.getNumRows(); row++) {
                String value = handle.getValue(row, column);
                if (handle.isOutlier(row) || super.isSuppressed(column, value)) {
                    result[row] = Double.NaN;
                } else {
                    result[row] = parser.getDouble(value);
                }
                
                // Check
                checkInterrupt();
            }
            
            // Return
            return result;
        } else {
            
            // Return
            return null;
        }
    } catch (Exception e) {
        
        // Fail silently
        return null;
    }
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:44,代码来源:QualityModelColumnOrientedMSE.java

示例11: getNumbersFromNumericColumn

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Parses numbers from a numeric input column
 * @param input
 * @param column
 * @return
 */
private double[] getNumbersFromNumericColumn(DataHandle input, int column) {
    
    try {
        
        // Prepare
        String attribute = input.getAttributeName(column);
        double[] result = new double[input.getNumRows() * 2];
        
        // Parse numbers
        if (input.getDataType(attribute) instanceof DataTypeWithRatioScale) {

            QualityConfigurationValueParser<?> parser = QualityConfigurationValueParser.create(input.getDataType(attribute));
            for (int row = 0; row < input.getNumRows(); row++) {
                double number = parser.getDouble(input.getValue(row, column));
                result[row * 2] = number;
                result[row * 2 + 1] = number;
                
                // Check
                checkInterrupt();
            }
            
            // Return
            return result;
        } else {
            
            // Return
            return null;
        }
    } catch (Exception e) {
        
        // Fail silently
        return null;
    }
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:41,代码来源:QualityModelRowOrientedSSE.java

示例12: main

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Entry point.
 * 
 * @param args
 *            the arguments
 */
public static void main(String[] args) throws IOException {

    // Define data
    DefaultData data = Data.create();
    data.add("age", "gender", "zipcode");
    data.add("34", "male", "81667");
    data.add("45", "female", "81675");
    data.add("66", "male", "81925");
    data.add("70", "female", "81931");
    data.add("34", "female", "81931");
    data.add("70", "male", "81931");
    data.add("45", "male", "81931");

    // Obtain a handle
    DataHandle inHandle = data.getHandle();

    // Read the encoded data
    inHandle.getNumRows();
    inHandle.getNumColumns();
    inHandle.getAttributeName(0);
    inHandle.getValue(0, 0);

    // Define hierarchy. Only excerpts for readability
    DefaultHierarchy zipcode = Hierarchy.create();
    zipcode.add("81667", "8166*", "816**", "81***", "8****", "*****");
    zipcode.add("81675", "8167*", "816**", "81***", "8****", "*****");
    zipcode.add("81925", "8192*", "819**", "81***", "8****", "*****");
    zipcode.add("81931", "8193*", "819**", "81***", "8****", "*****");

    // Create a data definition
    data.getDefinition()
        .setAttributeType("age", AttributeType.IDENTIFYING_ATTRIBUTE);
    data.getDefinition()
        .setAttributeType("gender", AttributeType.INSENSITIVE_ATTRIBUTE);
    data.getDefinition().setAttributeType("zipcode", zipcode);

    data.getDefinition().setDataType("zipcode", DataType.DECIMAL);

    // Create an instance of the anonymizer
    ARXAnonymizer anonymizer = new ARXAnonymizer();
    ARXConfiguration config = ARXConfiguration.create();
    config.addPrivacyModel(new KAnonymity(2));
    config.setMaxOutliers(0d);

    // Now anonymize the data utilizing the pre-encoded data
    ARXResult result = anonymizer.anonymize(data, config);

    // Obtain a handle for the transformed data
    DataHandle outHandle = result.getOutput(false);

    // Sort the data. This operation is implicitly performed on both
    // representations of the dataset.
    outHandle.sort(false, 2);

    // Print info
    printResult(result, data);

    // Process results
    System.out.println(" - Transformed data:");
    Iterator<String[]> transformed = result.getOutput(false).iterator();
    while (transformed.hasNext()) {
        System.out.print("   ");
        System.out.println(Arrays.toString(transformed.next()));
    }
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:72,代码来源:Example4.java

示例13: getRangeFromNumericColumn

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
/**
 * Tries to parse numbers from output when there is a numeric input column
 * @param inputNumbers
 * @param output
 * @param column
 * @return
 */
private double[] getRangeFromNumericColumn(double[] inputNumbers,
                                           DataHandle output,
                                           int column) {
    
    try {
        
        // Prepare
        String attribute = output.getAttributeName(column);
        double[] result = new double[output.getNumRows() * 2];
        double[] minmax = getMinMax(inputNumbers);
        double minimum = minmax[0];
        double maximum = minmax[1];
        
        // Create a sample of the data
        List<String> sample = new ArrayList<>();
        for (int row = 0; row < output.getNumRows() && sample.size() < 50; row++) {
            if (!output.isOutlier(row)) {
                sample.add(output.getValue(row, column));
            }
        }
        
        // Create parsers
        QualityConfigurationValueParser<?> valueParser = QualityConfigurationValueParser.create(output.getDataType(attribute));
        QualityConfigurationRangeParser rangeParser = QualityConfigurationRangeParser.getParser(valueParser, sample);
        
        // Parse
        for (int row = 0; row < output.getNumRows(); row++) {
            
            // Parse
            double[] range;
            if (output.isOutlier(row)) {
                range = new double[]{minimum, maximum};
            } else {
                String value = output.getValue(row, column);
                if (isSuppressed(column, value)) {
                    range = new double[]{minimum, maximum};    
                } else {
                    range = rangeParser.getRange(valueParser, value, minimum, maximum);
                }
            }
            
            result[row * 2] = range[0];
            result[row * 2 + 1] = range[1];
            
            // Check
            checkInterrupt();
        }
        
        // Return
        return result;
        
    } catch (Exception e) {
        
        // Fail silently
        return null;
    }
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:65,代码来源:QualityModelRowOrientedSSE.java

示例14: evaluate

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
@Override
public QualityMeasureRowOriented evaluate() {
    
    // Prepare
    int[] indices = getIndices();
    DataHandle output = getOutput();
    QualityDomainShare[] shares = getDomainShares();
    double min = 0d;
    double result = 0d;
    double max = 0d;

    // Progress
    setSteps(output.getNumRows());
    
    try {
        for (int row = 0; row < output.getNumRows(); row++) {
            double rowMin = 1d;
            double rowResult = 1d;
            double rowMax = 1d;
            for (int i = 0; i < indices.length; i++) {
                int column = indices[i];
                rowResult *= shares[i].getShare(output.getValue(row, column), 0) * shares[i].getDomainSize();
                rowMin *= 1d;
                rowMax *= shares[i].getDomainSize();
            }
            min += rowMin;
            result += rowResult;
            max += rowMax;

            // Progress
            setStepPerformed();
        }

        // Progress
        setStepsDone();
        
        return new QualityMeasureRowOriented(min, result, max);
        
    } catch (Exception e) {

        // Progress
        setStepsDone();
        
        // Silently catch exceptions
        return new QualityMeasureRowOriented(Double.NaN, Double.NaN, Double.NaN);
    }
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:48,代码来源:QualityModelRowOrientedAmbiguity.java

示例15: evaluate

import org.deidentifier.arx.DataHandle; //导入方法依赖的package包/类
@Override
public QualityMeasureColumnOriented evaluate() {
    
    // Prepare
    int[] indices = getIndices();
    DataHandle output = getOutput();
    String[][][] hierarchies = getHierarchies();
    Map<String, Double>[] precisions = getPrecisions(hierarchies);
    double[] result = new double[indices.length];
    double[] min = new double[indices.length];
    double[] max = new double[indices.length];

    // Progress
    setSteps(result.length);
    
    // For each column
    for (int i = 0; i < result.length; i++) {
        
        // Map
        int column = indices[i];
        
        // For each row
        for (int row = 0; row < output.getNumRows(); row++) {
            
            try {
                double precision = 1d;
                if (!isSuppressed(output, indices, row)) {
                    Double temp = precisions[i].get(output.getValue(row, column));
                    precision = temp != null ? temp : 1d;
                }
                result[i] += precision;
            } catch (Exception e) {
                // Silently catch exceptions
                result[i] = Double.NaN;
            }
            
            // Check
            checkInterrupt();
        }

        // Progress
        setStepPerformed();
    }

    // For each column
    for (int i = 0; i < result.length; i++) {
        result[i] /= (double)output.getNumRows();
        min[i] = 0d;
        max[i] = 1d;
    }

    // Progress
    setStepsDone();
    
    // Return
    return new QualityMeasureColumnOriented(output, indices, min, result, max);
}
 
开发者ID:arx-deidentifier,项目名称:arx,代码行数:58,代码来源:QualityModelColumnOrientedPrecision.java


注:本文中的org.deidentifier.arx.DataHandle.getNumRows方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。