Example usage for org.apache.commons.lang ArrayUtils toObject

List of usage examples for org.apache.commons.lang ArrayUtils toObject

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils toObject.

Prototype

public static Boolean[] toObject(boolean[] array) 

Source Link

Document

Converts an array of primitive booleans to objects.

Usage

From source file:org.dkpro.tc.ml.report.util.ScatterplotRenderer.java

private double getMax(double[] values) {
    return Collections.max(Arrays.asList(ArrayUtils.toObject(values)));
}

From source file:org.drugis.addis.util.convertors.NetworkMetaAnalysisConverter.java

private static ConsistencyResults convertConsistencyResults(NetworkMetaAnalysis ma) {
    ConsistencyResults results = new ConsistencyResults();
    ConsistencyWrapper model = ma.getConsistencyModel();
    if (model.isApproved()) {
        results.setMcmcSettings(convertMCMCSettings(model));
        convertParameterSummaries(ma, model, results.getSummary());
        results.setRelativeEffectsQuantileSummary(convertRelativeEffectQuantileSummaries(ma, model));
        RelativeEffectsSummary relativeEffectSummary = new RelativeEffectsSummary();
        List<Double> list = relativeEffectSummary.getCovariance();
        double[][] matrix = model.getRelativeEffectsSummary().getCovarianceMatrix();
        for (int row = 0; row < matrix.length; ++row) {
            for (int col = row; col < matrix.length; ++col) {
                list.add(matrix[row][col]);
            }/*  w w  w  .  j  a  v a 2  s  .c o  m*/
        }
        List<Double> meanVector = Arrays
                .asList(ArrayUtils.toObject(model.getRelativeEffectsSummary().getMeanVector()));
        relativeEffectSummary.getMeans().addAll(meanVector);
        results.setRelativeEffectsSummary(relativeEffectSummary);

        RankProbabilitySummary rankProbabilities = model.getRankProbabilities();
        int rankProababilitySize = rankProbabilities.getTreatments().size();
        for (int row = 0; row < rankProababilitySize; ++row) {
            for (int col = 0; col < rankProababilitySize; ++col) {
                results.getRankProbabilitySummary()
                        .add(rankProbabilities.getValue(rankProbabilities.getTreatments().get(col), row + 1));
            }
        }
        return results;
    }
    return null;
}

From source file:org.drugis.addis.util.jaxb.NetworkMetaAnalysisConverter.java

private static ConsistencyResults convertConsistencyResults(NetworkMetaAnalysis ma) {
    ConsistencyResults results = new ConsistencyResults();
    ConsistencyWrapper<TreatmentDefinition> model = ma.getConsistencyModel();
    if (model.isApproved()) {
        results.setMcmcSettings(convertMCMCSettings(model));
        convertParameterSummaries(ma, model, results.getSummary());
        results.setRelativeEffectsQuantileSummary(convertRelativeEffectQuantileSummaries(ma, model));
        RelativeEffectsSummary relativeEffectSummary = new RelativeEffectsSummary();
        List<Double> list = relativeEffectSummary.getCovariance();
        double[][] matrix = model.getRelativeEffectsSummary().getCovarianceMatrix();
        for (int row = 0; row < matrix.length; ++row) {
            for (int col = row; col < matrix.length; ++col) {
                list.add(matrix[row][col]);
            }/*from   w  w w  .j av  a 2 s  .co m*/
        }
        List<Double> meanVector = Arrays
                .asList(ArrayUtils.toObject(model.getRelativeEffectsSummary().getMeanVector()));
        relativeEffectSummary.getMeans().addAll(meanVector);
        results.setRelativeEffectsSummary(relativeEffectSummary);

        RankProbabilitySummary rankProbabilities = model.getRankProbabilities();
        int rankProababilitySize = rankProbabilities.getTreatments().size();
        for (int row = 0; row < rankProababilitySize; ++row) {
            for (int col = 0; col < rankProababilitySize; ++col) {
                results.getRankProbabilitySummary()
                        .add(rankProbabilities.getValue(rankProbabilities.getTreatments().get(col), row + 1));
            }
        }
        return results;
    }
    return null;
}

From source file:org.eclipse.january.dataset.OutlierCorrectnessTest.java

@Before
public void setUp() throws Exception {
    Random.seed(2468);//w w w  . ja v  a  2s  .c  o m
    dataNormal = Random.randn(1.0, 1.0, new int[] { 6 });
    dataNormal.sort(null);
    dataOneToFour = DatasetFactory
            .createFromList(Arrays.asList(ArrayUtils.toObject(new double[] { 1, 2, 3, 4 })));
    System.out.println("Normal data " + dataNormal.toString(true));
    System.out.println("data 1-4 " + dataOneToFour.toString(true));
}

From source file:org.eclipse.triquetrum.scisoft.analysis.rpc.flattening.FlatteningTestAbstract.java

@Test
public void testPrimitiveArrays() {
    int[] ints = { 1, 5, -7 };
    flattenAndUnflatten(ints);/*from w  w  w  .j  a va 2 s .co m*/
    flattenAndUnflatten(ArrayUtils.toObject(ints), ints);

    double[] doubles = { 1.4, 12.6, 0 };
    flattenAndUnflatten(doubles);
    flattenAndUnflatten(ArrayUtils.toObject(doubles), doubles);

    boolean[] booleans = { true, false, false, true };
    flattenAndUnflatten(booleans);
    flattenAndUnflatten(ArrayUtils.toObject(booleans), booleans);

    double[][] doubles2d = { { 1, 5, -7 }, { 1.4, 12.6, 0 } };
    flattenAndUnflatten(doubles2d, new double[][] { doubles2d[0], doubles2d[1] });
    flattenAndUnflatten(new double[][] { doubles2d[0], doubles2d[1] });
}

From source file:org.eclipse.triquetrum.scisoft.analysis.rpc.flattening.helpers.PrimitiveArrayHelper.java

@Override
public Object flatten(Object obj, IRootFlattener rootFlattener) {
    if (obj instanceof int[]) {
        return ArrayUtils.toObject((int[]) obj);
    } else if (obj instanceof boolean[]) {
        return ArrayUtils.toObject((boolean[]) obj);
    } else if (obj instanceof double[]) {
        return ArrayUtils.toObject((double[]) obj);
    }//from  w w w .ja v a2s  .  c o m
    throw new AssertionError();
}

From source file:org.eclipse.wb.internal.core.model.property.editor.IntegerArrayPropertyEditor.java

@Override
public String getText(Property property) throws Exception {
    Object value = property.getValue();
    if (value instanceof int[]) {
        int[] array = (int[]) value;
        return StringUtils.join(ArrayUtils.toObject(array), ' ');
    }/*w ww  .ja v a 2  s .  c  o m*/
    return null;
}

From source file:org.eclipse.wb.internal.xwt.model.widgets.SashFormInfo.java

/**
 * Sets the "weights" attribute.//  w w  w.  java 2s .c o m
 */
private void setWeights(int[] weights) throws Exception {
    String weightsString = StringUtils.join(ArrayUtils.toObject(weights), ", ");
    getCreationSupport().getElement().setAttribute("weights", weightsString);
}

From source file:org.epochx.ge.model.epox.EvenParity.java

/**
 * Calculates the fitness score for the given program. The fitness of a
 * program for the even-parity problem is calculated by evaluating it
 * using each of the possible sets of input values. There are
 * <code>2^noInputBits</code> possible sets of inputs. The fitness of the
 * program is the quantity of those input sequences that the program
 * returned an incorrect response for. That is, a fitness value of
 * <code>0.0</code> indicates the program responded correctly for every
 * possible set of input values.//from w  w w.j a  v a2s . c o m
 * 
 * @param p {@inheritDoc}
 * @return the calculated fitness for the given program.
 */
@Override
public double getFitness(final CandidateProgram p) {
    final GECandidateProgram program = (GECandidateProgram) p;

    double score = 0;

    // Evaluate all possible inputValues.
    for (final boolean[] vars : inputValues) {
        // Convert to object array.
        final Boolean[] objVars = ArrayUtils.toObject(vars);

        Boolean result = null;
        try {
            result = (Boolean) interpreter.eval(program.getSourceCode(), argNames, objVars);
        } catch (final MalformedProgramException e) {
            // Assign worst possible fitness and stop evaluating.
            score = 0;
            break;
        }

        // Increment score for a correct response.
        if ((result != null) && (result == isEvenNoTrue(vars))) {
            score++;
        } else if (!program.isValid()) {
            score = 0;
            break;
        }
    }

    return inputValues.length - score;
}

From source file:org.epochx.ge.model.epox.Majority.java

/**
 * Calculates the fitness score for the given program. The fitness of a
 * program for the majority problem is calculated by evaluating it
 * using each of the possible sets of input values. There are
 * <code>2^noInputBits</code> possible sets of inputs. The fitness of the
 * program is the quantity of those input sequences that the program
 * returned an incorrect response for. That is, a fitness value of
 * <code>0.0</code> indicates the program responded correctly for every
 * possible set of input values.//from   w  ww.  j av a 2s. c o  m
 * 
 * @param p {@inheritDoc}
 * @return the calculated fitness for the given program.
 */
@Override
public double getFitness(final CandidateProgram p) {
    final GECandidateProgram program = (GECandidateProgram) p;

    double score = 0;

    // Evaluate all possible inputValues.
    for (final boolean[] vars : inputValues) {
        // Convert to object array.
        final Boolean[] objVars = ArrayUtils.toObject(vars);

        Boolean result = null;
        try {
            result = (Boolean) interpreter.eval(program.getSourceCode(), argNames, objVars);
        } catch (final MalformedProgramException e) {
            // Assign worst possible fitness and stop evaluating.
            score = 0;
            break;
        }

        if ((result != null) && (result == majorityTrue(vars))) {
            score++;
        }
    }

    return inputValues.length - score;
}