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

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

Introduction

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

Prototype

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

Source Link

Document

Converts an array of object Booleans to primitives.

Usage

From source file:mil.jpeojtrs.sca.util.PrimitiveArrayUtils.java

public static double[] convertToDoubleArray(final Object array) {
    if (array == null) {
        return null;
    }//from  w  w  w .  ja  v  a 2  s . c  o m
    if (array instanceof double[]) {
        return (double[]) array;
    }
    if (array instanceof Double[]) {
        return ArrayUtils.toPrimitive((Double[]) array);
    }
    final double[] newArray = new double[Array.getLength(array)];
    for (int i = 0; i < newArray.length; i++) {
        final Number val = (Number) Array.get(array, i);
        newArray[i] = val.doubleValue();
    }
    return newArray;
}

From source file:gda.device.scannable.DummyMultiElementScannable.java

@Override
public void rawAsynchronousMoveTo(Object position) {

    Double[] target = ScannableUtils.objectToArray(position);

    if (target.length == currentPosition.length) {
        currentPosition = ArrayUtils.toPrimitive(target);
    } else {//w  w  w .  ja va  2  s .  c o m
        // throw error
    }
}

From source file:lu.lippmann.cdb.weka.SilhouetteUtil.java

/**
 * //from w w w.j a v a  2s  .co  m
 * @param sils
 * @return
 */
public static JPanel buildSilhouettePanel(final Instances ds, final WekaClusteringResult result) {

    final Map<Integer, List<Double>> sils = computeSilhouette(ds, result);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    final JFreeChart chart = ChartFactory.createBarChart("Silhouette", "Category", "Value", dataset,
            PlotOrientation.HORIZONTAL, true, true, false);

    int nbClass = sils.keySet().size();

    int id = 0;
    double minValue = 0;

    int counter[][] = new int[nbClass][4];
    for (int i = 0; i < nbClass; i++) {

        final double[] tree = ArrayUtils.toPrimitive(sils.get(i).toArray(new Double[0]));

        for (double val : tree) {
            if (val > 0.75) {
                dataset.addValue(val, "Cluster " + i + " ++", "" + id);
                counter[i][0]++;
            } else if (val > 0.50) {
                dataset.addValue(val, "Cluster " + i + " +", "" + id);
                counter[i][1]++;
            } else if (val > 0.25) {
                dataset.addValue(val, "Cluster " + i + " =", "" + id);
                counter[i][2]++;
            } else {
                dataset.addValue(val, "Cluster " + i + " -", "" + id);
                counter[i][3]++;
            }
            if (val < minValue) {
                minValue = val;
            }
            id++;
        }

    }

    final CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
    categoryplot.setBackgroundPaint(Color.WHITE);
    categoryplot.getDomainAxis().setVisible(false);
    categoryplot.setDomainGridlinesVisible(false);
    categoryplot.setRangeGridlinesVisible(false);
    categoryplot.getRangeAxis().setRange(minValue, 1.0);

    //Add line markers
    ValueMarker target = new ValueMarker(0.75);
    target.setPaint(Color.BLACK);
    target.setLabel("  ++");
    target.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    target.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    categoryplot.addRangeMarker(target);

    target = new ValueMarker(0.5);
    target.setPaint(Color.BLACK);
    target.setLabel("  +");
    target.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    target.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    categoryplot.addRangeMarker(target);

    target = new ValueMarker(0.25);
    target.setPaint(Color.BLACK);
    target.setLabel("  =");
    target.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    target.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    categoryplot.addRangeMarker(target);

    target = new ValueMarker(0);
    target.setPaint(Color.BLACK);
    target.setLabel("  -");
    target.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    target.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    categoryplot.addRangeMarker(target);

    //Remove visual effects on bar
    final BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
    barrenderer.setBarPainter(new StandardBarPainter());

    //set bar colors
    int p = 0;
    final int max = ColorHelper.COLORBREWER_SEQUENTIAL_PALETTES.size();

    for (int i = 0; i < nbClass; i++) {
        final Color[] color = new ArrayList<Color[]>(ColorHelper.COLORBREWER_SEQUENTIAL_PALETTES.values())
                .get((max - i) % max);
        final int nbColors = color.length;
        for (int k = 0; k < counter[i].length; k++) {
            if (counter[i][k] > 0)
                barrenderer.setSeriesPaint(p++, color[(nbColors - k - 3) % nbColors]);
        }
    }

    //remove blank line between bars
    barrenderer.setItemMargin(-dataset.getRowCount());

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setPreferredSize(new Dimension(1200, 900));
    chartPanel.setBorder(new TitledBorder("Silhouette plot"));
    chartPanel.setBackground(Color.WHITE);
    chart.setTitle("");
    return chartPanel;

}

From source file:com.opengamma.analytics.math.curve.DoublesCurveNelsonSiegelTest.java

@Test
/**// www  .  j a va 2  s .  co  m
 * Tests the parameters sensitivity with a finite difference comparison.
 */
public void yValueParameterSensitivity() {
    final int nbPoint = 10;
    final double timeMax = 9.0;
    final double bump = 0.00001;
    final Double[] sensitivityComputed0 = CURVE_NS.getYValueParameterSensitivity(0.0);
    final double[] sensitivityExpected0 = new double[] { 1.0, 1.0, 0.0, 0.0 };
    assertArrayEquals("DoublesCurveNelsonSiegel: parameter sensitivity", sensitivityExpected0,
            ArrayUtils.toPrimitive(sensitivityComputed0), TOLERANCE_SENSITIVITY);
    final double[][] parametersBumped = new double[4][];
    final DoublesCurveNelsonSiegel[] curveBumped = new DoublesCurveNelsonSiegel[4];
    for (int loopp = 0; loopp < 4; loopp++) {
        parametersBumped[loopp] = PARAMETERS.clone();
        parametersBumped[loopp][loopp] += bump;
        curveBumped[loopp] = new DoublesCurveNelsonSiegel(CURVE_NAME, parametersBumped[loopp]);
    }
    for (int loopt = 1; loopt <= nbPoint; loopt++) {
        // Implementation note: start at 1 to avoid 0 (treated tested separately)
        final double t = loopt * timeMax / nbPoint;
        final double valueComputed = CURVE_NS.getYValue(t);
        final Double[] sensitivityComputed = CURVE_NS.getYValueParameterSensitivity(t);
        final double[] sensitivityExpected = new double[4];
        for (int loopp = 0; loopp < 4; loopp++) {
            final double valueBumped = curveBumped[loopp].getYValue(t);
            sensitivityExpected[loopp] = (valueBumped - valueComputed) / bump;
        }
        assertArrayEquals("DoublesCurveNelsonSiegel: parameter sensitivity " + loopt, sensitivityExpected,
                ArrayUtils.toPrimitive(sensitivityComputed), TOLERANCE_SENSITIVITY);
    }
}

From source file:com.opengamma.analytics.financial.model.interestrate.curve.YieldCurve.java

@Override
public double[] getInterestRateParameterSensitivity(final double t) {
    return ArrayUtils.toPrimitive(_curve.getYValueParameterSensitivity(t));
}

From source file:adwords.axis.v201309.accountmanagement.GetAccountChanges.java

public static void runExample(AdWordsServices adWordsServices, AdWordsSession session) throws Exception {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);

    // Get the CustomerSyncService.
    CustomerSyncServiceInterface customerSyncService = adWordsServices.get(session,
            CustomerSyncServiceInterface.class);

    // Get a list of all campaign IDs.
    List<Long> campaignIds = new ArrayList<Long>();
    Selector selector = new SelectorBuilder().fields("Id").build();
    CampaignPage campaigns = campaignService.get(selector);
    if (campaigns.getEntries() != null) {
        for (Campaign campaign : campaigns.getEntries()) {
            campaignIds.add(campaign.getId());
        }//from   w w w .  j a  va 2s  .c om
    }

    // Create date time range for the past 24 hours.
    DateTimeRange dateTimeRange = new DateTimeRange();
    dateTimeRange.setMin(new SimpleDateFormat("yyyyMMdd HHmmss")
            .format(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24)));
    dateTimeRange.setMax(new SimpleDateFormat("yyyyMMdd HHmmss").format(new Date()));

    // Create selector.
    CustomerSyncSelector customerSyncSelector = new CustomerSyncSelector();
    customerSyncSelector.setDateTimeRange(dateTimeRange);
    customerSyncSelector.setCampaignIds(ArrayUtils.toPrimitive(campaignIds.toArray(new Long[] {})));

    // Get all account changes for campaign.
    CustomerChangeData accountChanges = customerSyncService.get(customerSyncSelector);

    // Display changes.
    if (accountChanges != null && accountChanges.getChangedCampaigns() != null) {
        System.out.println("Most recent change: " + accountChanges.getLastChangeTimestamp() + "\n");
        for (CampaignChangeData campaignChanges : accountChanges.getChangedCampaigns()) {
            System.out.println("Campaign with id \"" + campaignChanges.getCampaignId() + "\" was changed: ");
            System.out.println("\tCampaign changed status: " + campaignChanges.getCampaignChangeStatus());
            if (campaignChanges.getCampaignChangeStatus() != ChangeStatus.NEW) {
                System.out.println(
                        "\tAdded ad extensions: " + getFormattedList(campaignChanges.getAddedAdExtensions()));
                System.out.println("\tAdded campaign criteria: "
                        + getFormattedList(campaignChanges.getAddedCampaignCriteria()));
                System.out.println(
                        "\tAdded campaign targeting: " + campaignChanges.getCampaignTargetingChanged());
                System.out.println("\tDeleted ad extensions: "
                        + getFormattedList(campaignChanges.getDeletedAdExtensions()));
                System.out.println("\tDeleted campaign criteria: "
                        + getFormattedList(campaignChanges.getDeletedCampaignCriteria()));

                if (campaignChanges.getChangedAdGroups() != null) {
                    for (AdGroupChangeData adGroupChanges : campaignChanges.getChangedAdGroups()) {
                        System.out.println(
                                "\tAd goup with id \"" + adGroupChanges.getAdGroupId() + "\" was changed: ");
                        System.out.println(
                                "\t\tAd goup changed status: " + adGroupChanges.getAdGroupChangeStatus());
                        if (adGroupChanges.getAdGroupChangeStatus() != ChangeStatus.NEW) {
                            System.out.println(
                                    "\t\tAds changed: " + getFormattedList(adGroupChanges.getChangedAds()));
                            System.out.println("\t\tCriteria changed: "
                                    + getFormattedList(adGroupChanges.getChangedCriteria()));
                            System.out.println("\t\tCriteria deleted: "
                                    + getFormattedList(adGroupChanges.getDeletedCriteria()));
                        }
                    }
                }
            }
            System.out.println("");
        }
    } else {
        System.out.println("No account changes were found.");
    }
}

From source file:adwords.axis.v201406.accountmanagement.GetAccountChanges.java

public static void runExample(AdWordsServices adWordsServices, AdWordsSession session) throws Exception {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);

    // Get the CustomerSyncService.
    CustomerSyncServiceInterface customerSyncService = adWordsServices.get(session,
            CustomerSyncServiceInterface.class);

    // Get a list of all campaign IDs.
    List<Long> campaignIds = new ArrayList<Long>();
    Selector selector = new SelectorBuilder().fields("Id").build();
    CampaignPage campaigns = campaignService.get(selector);
    if (campaigns.getEntries() != null) {
        for (Campaign campaign : campaigns.getEntries()) {
            campaignIds.add(campaign.getId());
        }// w w  w  .  ja v a  2s .c o  m
    }

    // Create date time range for the past 24 hours.
    DateTimeRange dateTimeRange = new DateTimeRange();
    dateTimeRange.setMin(new SimpleDateFormat("yyyyMMdd HHmmss")
            .format(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24)));
    dateTimeRange.setMax(new SimpleDateFormat("yyyyMMdd HHmmss").format(new Date()));

    // Create selector.
    CustomerSyncSelector customerSyncSelector = new CustomerSyncSelector();
    customerSyncSelector.setDateTimeRange(dateTimeRange);
    customerSyncSelector.setCampaignIds(ArrayUtils.toPrimitive(campaignIds.toArray(new Long[] {})));

    // Get all account changes for campaign.
    CustomerChangeData accountChanges = customerSyncService.get(customerSyncSelector);

    // Display changes.
    if (accountChanges != null && accountChanges.getChangedCampaigns() != null) {
        System.out.println("Most recent change: " + accountChanges.getLastChangeTimestamp() + "\n");
        for (CampaignChangeData campaignChanges : accountChanges.getChangedCampaigns()) {
            System.out.println("Campaign with id \"" + campaignChanges.getCampaignId() + "\" was changed: ");
            System.out.println("\tCampaign changed status: " + campaignChanges.getCampaignChangeStatus());
            if (campaignChanges.getCampaignChangeStatus() != ChangeStatus.NEW) {
                System.out.println(
                        "\tAdded ad extensions: " + getFormattedList(campaignChanges.getAddedAdExtensions()));
                System.out.println("\tAdded campaign criteria: "
                        + getFormattedList(campaignChanges.getAddedCampaignCriteria()));
                System.out.println(
                        "\tAdded campaign targeting: " + campaignChanges.getCampaignTargetingChanged());
                System.out.println("\tRemoved ad extensions: "
                        + getFormattedList(campaignChanges.getRemovedAdExtensions()));
                System.out.println("\tRemoved campaign criteria: "
                        + getFormattedList(campaignChanges.getRemovedCampaignCriteria()));

                if (campaignChanges.getChangedAdGroups() != null) {
                    for (AdGroupChangeData adGroupChanges : campaignChanges.getChangedAdGroups()) {
                        System.out.println(
                                "\tAd goup with id \"" + adGroupChanges.getAdGroupId() + "\" was changed: ");
                        System.out.println(
                                "\t\tAd goup changed status: " + adGroupChanges.getAdGroupChangeStatus());
                        if (adGroupChanges.getAdGroupChangeStatus() != ChangeStatus.NEW) {
                            System.out.println(
                                    "\t\tAds changed: " + getFormattedList(adGroupChanges.getChangedAds()));
                            System.out.println("\t\tCriteria changed: "
                                    + getFormattedList(adGroupChanges.getChangedCriteria()));
                            System.out.println("\t\tCriteria removed: "
                                    + getFormattedList(adGroupChanges.getRemovedCriteria()));
                        }
                    }
                }
            }
            System.out.println("");
        }
    } else {
        System.out.println("No account changes were found.");
    }
}

From source file:dk.dma.ais.store.FileExport.java

/** {@inheritDoc} */
@Override/*from  www. j a v  a2 s.  co  m*/
protected void run(Injector injector) throws Exception {
    AisStoreQueryBuilder b;
    if (!mmsis.isEmpty()) {
        b = AisStoreQueryBuilder.forMmsi(ArrayUtils.toPrimitive(mmsis.toArray(new Integer[0])));
        b.setFetchSize(fetchSize);
    } else if (area != null) {
        BoundingBox bbox = findBoundingBox(area);
        b = AisStoreQueryBuilder.forArea(bbox);
        b.setFetchSize(fetchSize);
    } else {
        b = AisStoreQueryBuilder.forTime();
        b.setFetchSize(fetchSize);
    }

    b.setInterval(DateTimeUtil.toInterval(interval));

    if (dryrun) {
        System.out.println(b);
        return;
    }

    CassandraConnection conn = CassandraConnection.create(keyspace, seeds);
    conn.startAsync();

    AisStoreQueryResult result = conn.execute(b);
    Iterable<AisPacket> iterableResult = result;

    if (filter != null) {
        iterableResult = Iterables.filter(iterableResult, AisPacketFilters.parseExpressionFilter(filter));
    }

    OutputStreamSink<AisPacket> sink = AisPacketOutputSinks.getOutputSink(outputFormat, columns, separator);

    FileOutputStream fos;
    if (filePath != null) {
        fos = new FileOutputStream(new File(filePath));
    } else {
        fos = new FileOutputStream(FileDescriptor.out);
    }

    sink.closeWhenFooterWritten();
    sink.writeAll(iterableResult, fos);
    conn.stopAsync();
}

From source file:com.rapidminer.operator.learner.tree.SelectionCreator.java

/**
 * Creates an example index start selection for each numerical attribute, or if there is none,
 * only one./*w  ww. ja  v  a  2  s  . co m*/
 *
 * @return a map containing for each numerical attribute an example index array such that the
 *         associated attribute values are in ascending order.
 */
public Map<Integer, int[]> getStartSelection() {
    Map<Integer, int[]> selection = new HashMap<>();
    if (columnTable.getNumberOfRegularNumericalAttributes() == 0) {
        selection.put(0, createFullArray(columnTable.getNumberOfExamples()));
    } else {
        Integer[] bigSelectionArray = createFullBigArray(columnTable.getNumberOfExamples());
        for (int j = columnTable.getNumberOfRegularNominalAttributes(); j < columnTable
                .getTotalNumberOfRegularAttributes(); j++) {
            final double[] attributeColumn = columnTable.getNumericalAttributeColumn(j);
            Integer[] startSelection = Arrays.copyOf(bigSelectionArray, bigSelectionArray.length);
            Arrays.sort(startSelection, new Comparator<Integer>() {

                @Override
                public int compare(Integer a, Integer b) {
                    return Double.compare(attributeColumn[a], attributeColumn[b]);
                }
            });
            selection.put(j, ArrayUtils.toPrimitive(startSelection));
        }
    }
    return selection;
}

From source file:adwords.axis.v201502.accountmanagement.GetAccountChanges.java

public static void runExample(AdWordsServices adWordsServices, AdWordsSession session) throws Exception {
    // Get the CampaignService.
    CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);

    // Get the CustomerSyncService.
    CustomerSyncServiceInterface customerSyncService = adWordsServices.get(session,
            CustomerSyncServiceInterface.class);

    // Get a list of all campaign IDs.
    List<Long> campaignIds = new ArrayList<Long>();
    Selector selector = new SelectorBuilder().fields(CampaignField.Id).build();
    CampaignPage campaigns = campaignService.get(selector);
    if (campaigns.getEntries() != null) {
        for (Campaign campaign : campaigns.getEntries()) {
            campaignIds.add(campaign.getId());
        }// w w w . java2s . c  o m
    }

    // Create date time range for the past 24 hours.
    DateTimeRange dateTimeRange = new DateTimeRange();
    dateTimeRange.setMin(new SimpleDateFormat("yyyyMMdd HHmmss")
            .format(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24)));
    dateTimeRange.setMax(new SimpleDateFormat("yyyyMMdd HHmmss").format(new Date()));

    // Create selector.
    CustomerSyncSelector customerSyncSelector = new CustomerSyncSelector();
    customerSyncSelector.setDateTimeRange(dateTimeRange);
    customerSyncSelector.setCampaignIds(ArrayUtils.toPrimitive(campaignIds.toArray(new Long[] {})));

    // Get all account changes for campaign.
    CustomerChangeData accountChanges = customerSyncService.get(customerSyncSelector);

    // Display changes.
    if (accountChanges != null && accountChanges.getChangedCampaigns() != null) {
        System.out.println("Most recent change: " + accountChanges.getLastChangeTimestamp() + "\n");
        for (CampaignChangeData campaignChanges : accountChanges.getChangedCampaigns()) {
            System.out.println("Campaign with id \"" + campaignChanges.getCampaignId() + "\" was changed: ");
            System.out.println("\tCampaign changed status: " + campaignChanges.getCampaignChangeStatus());
            if (campaignChanges.getCampaignChangeStatus() != ChangeStatus.NEW) {
                System.out.println(
                        "\tAdded ad extensions: " + getFormattedList(campaignChanges.getAddedAdExtensions()));
                System.out.println("\tAdded campaign criteria: "
                        + getFormattedList(campaignChanges.getAddedCampaignCriteria()));
                System.out.println("\tRemoved ad extensions: "
                        + getFormattedList(campaignChanges.getRemovedAdExtensions()));
                System.out.println("\tRemoved campaign criteria: "
                        + getFormattedList(campaignChanges.getRemovedCampaignCriteria()));

                if (campaignChanges.getChangedAdGroups() != null) {
                    for (AdGroupChangeData adGroupChanges : campaignChanges.getChangedAdGroups()) {
                        System.out.println(
                                "\tAd goup with id \"" + adGroupChanges.getAdGroupId() + "\" was changed: ");
                        System.out.println(
                                "\t\tAd goup changed status: " + adGroupChanges.getAdGroupChangeStatus());
                        if (adGroupChanges.getAdGroupChangeStatus() != ChangeStatus.NEW) {
                            System.out.println(
                                    "\t\tAds changed: " + getFormattedList(adGroupChanges.getChangedAds()));
                            System.out.println("\t\tCriteria changed: "
                                    + getFormattedList(adGroupChanges.getChangedCriteria()));
                            System.out.println("\t\tCriteria removed: "
                                    + getFormattedList(adGroupChanges.getRemovedCriteria()));
                        }
                    }
                }
            }
            System.out.println("");
        }
    } else {
        System.out.println("No account changes were found.");
    }
}