Search in sources :

Example 91 with Pair

use of org.apache.commons.math3.util.Pair in project druid by druid-io.

the class BenchmarkColumnValueGenerator method initDistribution.

private void initDistribution() {
    BenchmarkColumnSchema.ValueDistribution distributionType = schema.getDistributionType();
    ValueType type = schema.getType();
    List<Object> enumeratedValues = schema.getEnumeratedValues();
    List<Double> enumeratedProbabilities = schema.getEnumeratedProbabilities();
    List<Pair<Object, Double>> probabilities = new ArrayList<>();
    switch(distributionType) {
        case SEQUENTIAL:
            // not random, just cycle through numbers from start to end, or cycle through enumerated values if provided
            distribution = new SequentialDistribution(schema.getStartInt(), schema.getEndInt(), schema.getEnumeratedValues());
            break;
        case UNIFORM:
            distribution = new UniformRealDistribution(schema.getStartDouble(), schema.getEndDouble());
            break;
        case DISCRETE_UNIFORM:
            if (enumeratedValues == null) {
                enumeratedValues = new ArrayList<>();
                for (int i = schema.getStartInt(); i < schema.getEndInt(); i++) {
                    Object val = convertType(i, type);
                    enumeratedValues.add(val);
                }
            }
            // give them all equal probability, the library will normalize probabilities to sum to 1.0
            for (int i = 0; i < enumeratedValues.size(); i++) {
                probabilities.add(new Pair<>(enumeratedValues.get(i), 0.1));
            }
            distribution = new EnumeratedTreeDistribution<>(probabilities);
            break;
        case NORMAL:
            distribution = new NormalDistribution(schema.getMean(), schema.getStandardDeviation());
            break;
        case ROUNDED_NORMAL:
            NormalDistribution normalDist = new NormalDistribution(schema.getMean(), schema.getStandardDeviation());
            distribution = new RealRoundingDistribution(normalDist);
            break;
        case ZIPF:
            int cardinality;
            if (enumeratedValues == null) {
                Integer startInt = schema.getStartInt();
                cardinality = schema.getEndInt() - startInt;
                ZipfDistribution zipf = new ZipfDistribution(cardinality, schema.getZipfExponent());
                for (int i = 0; i < cardinality; i++) {
                    probabilities.add(new Pair<>((Object) (i + startInt), zipf.probability(i)));
                }
            } else {
                cardinality = enumeratedValues.size();
                ZipfDistribution zipf = new ZipfDistribution(enumeratedValues.size(), schema.getZipfExponent());
                for (int i = 0; i < cardinality; i++) {
                    probabilities.add(new Pair<>(enumeratedValues.get(i), zipf.probability(i)));
                }
            }
            distribution = new EnumeratedTreeDistribution<>(probabilities);
            break;
        case ENUMERATED:
            for (int i = 0; i < enumeratedValues.size(); i++) {
                probabilities.add(new Pair<>(enumeratedValues.get(i), enumeratedProbabilities.get(i)));
            }
            distribution = new EnumeratedTreeDistribution<>(probabilities);
            break;
        default:
            throw new UnsupportedOperationException("Unknown distribution type: " + distributionType);
    }
    if (distribution instanceof AbstractIntegerDistribution) {
        ((AbstractIntegerDistribution) distribution).reseedRandomGenerator(seed);
    } else if (distribution instanceof AbstractRealDistribution) {
        ((AbstractRealDistribution) distribution).reseedRandomGenerator(seed);
    } else if (distribution instanceof EnumeratedDistribution) {
        ((EnumeratedDistribution) distribution).reseedRandomGenerator(seed);
    }
}
Also used : ValueType(io.druid.segment.column.ValueType) ArrayList(java.util.ArrayList) UniformRealDistribution(org.apache.commons.math3.distribution.UniformRealDistribution) EnumeratedDistribution(org.apache.commons.math3.distribution.EnumeratedDistribution) AbstractIntegerDistribution(org.apache.commons.math3.distribution.AbstractIntegerDistribution) AbstractRealDistribution(org.apache.commons.math3.distribution.AbstractRealDistribution) NormalDistribution(org.apache.commons.math3.distribution.NormalDistribution) ZipfDistribution(org.apache.commons.math3.distribution.ZipfDistribution) Pair(org.apache.commons.math3.util.Pair)

Example 92 with Pair

use of org.apache.commons.math3.util.Pair in project android-topeka by googlesamples.

the class SignInFragment method performSignInWithTransition.

private void performSignInWithTransition(View v) {
    final Activity activity = getActivity();
    if (v == null || ApiLevelHelper.isLowerThan(Build.VERSION_CODES.LOLLIPOP)) {
        // Don't run a transition if the passed view is null
        CategorySelectionActivity.start(activity, mPlayer);
        activity.finish();
        return;
    }
    if (ApiLevelHelper.isAtLeast(Build.VERSION_CODES.LOLLIPOP)) {
        activity.getWindow().getSharedElementExitTransition().addListener(new TransitionListenerAdapter() {

            @Override
            public void onTransitionEnd(Transition transition) {
                activity.finish();
            }
        });
        final Pair[] pairs = TransitionHelper.createSafeTransitionParticipants(activity, true, new Pair<>(v, activity.getString(R.string.transition_avatar)));
        @SuppressWarnings("unchecked") ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, pairs);
        CategorySelectionActivity.start(activity, mPlayer, activityOptions);
    }
}
Also used : Transition(android.transition.Transition) CategorySelectionActivity(com.google.samples.apps.topeka.activity.CategorySelectionActivity) Activity(android.app.Activity) TransitionListenerAdapter(com.google.samples.apps.topeka.widget.TransitionListenerAdapter) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat) Pair(android.support.v4.util.Pair)

Example 93 with Pair

use of org.apache.commons.math3.util.Pair in project android-topeka by googlesamples.

the class TransitionHelper method createSafeTransitionParticipants.

/**
     * Create the transition participants required during a activity transition while
     * avoiding glitches with the system UI.
     *
     * @param activity The activity used as start for the transition.
     * @param includeStatusBar If false, the status bar will not be added as the transition
     * participant.
     * @return All transition participants.
     */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Pair<View, String>[] createSafeTransitionParticipants(@NonNull Activity activity, boolean includeStatusBar, @Nullable Pair... otherParticipants) {
    // Avoid system UI glitches as described here:
    // https://plus.google.com/+AlexLockwood/posts/RPtwZ5nNebb
    View decor = activity.getWindow().getDecorView();
    View statusBar = null;
    if (includeStatusBar) {
        statusBar = decor.findViewById(android.R.id.statusBarBackground);
    }
    View navBar = decor.findViewById(android.R.id.navigationBarBackground);
    // Create pair of transition participants.
    List<Pair> participants = new ArrayList<>(3);
    addNonNullViewToTransitionParticipants(statusBar, participants);
    addNonNullViewToTransitionParticipants(navBar, participants);
    // only add transition participants if there's at least one none-null element
    if (otherParticipants != null && !(otherParticipants.length == 1 && otherParticipants[0] == null)) {
        participants.addAll(Arrays.asList(otherParticipants));
    }
    //noinspection unchecked
    return participants.toArray(new Pair[participants.size()]);
}
Also used : ArrayList(java.util.ArrayList) View(android.view.View) Pair(android.support.v4.util.Pair) TargetApi(android.annotation.TargetApi)

Example 94 with Pair

use of org.apache.commons.math3.util.Pair in project android by owncloud.

the class FileDataStorageManager method getAvailableOfflineFilesFromEveryAccount.

/**
     * Get a collection with all the files set by the user as available offline, from all the accounts
     * in the device.
     *
     * This is the only method working with a NULL account in {@link #mAccount}. Not something to do often.
     *
     * @return      List with all the files set by the user as available offline.
     */
public List<Pair<OCFile, String>> getAvailableOfflineFilesFromEveryAccount() {
    List<Pair<OCFile, String>> result = new ArrayList<>();
    Cursor cursorOnKeptInSync = null;
    try {
        // query for any favorite file in any OC account
        cursorOnKeptInSync = getContentResolver().query(ProviderTableMeta.CONTENT_URI, null, ProviderTableMeta.FILE_KEEP_IN_SYNC + " = ?", new String[] { String.valueOf(OCFile.AvailableOfflineStatus.AVAILABLE_OFFLINE.getValue()) }, // do NOT get also AVAILABLE_OFFLINE_PARENT: only those SET BY THE USER (files or folders)
        null);
        if (cursorOnKeptInSync != null && cursorOnKeptInSync.moveToFirst()) {
            OCFile file;
            String accountName;
            do {
                file = createFileInstance(cursorOnKeptInSync);
                accountName = cursorOnKeptInSync.getString(cursorOnKeptInSync.getColumnIndex(ProviderTableMeta.FILE_ACCOUNT_OWNER));
                result.add(new Pair<>(file, accountName));
            } while (cursorOnKeptInSync.moveToNext());
        }
    } catch (Exception e) {
        Log_OC.e(TAG, "Exception retrieving all the available offline files", e);
    } finally {
        if (cursorOnKeptInSync != null) {
            cursorOnKeptInSync.close();
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) RemoteException(android.os.RemoteException) IOException(java.io.IOException) OperationApplicationException(android.content.OperationApplicationException) Pair(android.support.v4.util.Pair)

Example 95 with Pair

use of org.apache.commons.math3.util.Pair in project android by owncloud.

the class FileObserverService method startObservation.

/**
     * Read from the local database the list of files that must to be kept
     * synchronized and starts observers to monitor local changes on them.
     * 
     * Updates the list of currently observed files if called multiple times.
     */
private void startObservation() {
    Log_OC.d(TAG, "Loading all available offline files from database to start watching them");
    FileDataStorageManager fds = new FileDataStorageManager(// this is dangerous - handle with care
    null, getContentResolver());
    List<Pair<OCFile, String>> availableOfflineFiles = fds.getAvailableOfflineFilesFromEveryAccount();
    OCFile file;
    String accountName;
    Account account;
    for (Pair<OCFile, String> pair : availableOfflineFiles) {
        file = pair.first;
        accountName = pair.second;
        account = new Account(accountName, MainApp.getAccountType());
        if (!AccountUtils.exists(account, this)) {
            continue;
        }
        addObservedFile(file, account);
    }
    // watch for instant uploads
    updateInstantUploadsObservers();
// service does not stopSelf() ; that way it tries to be alive forever
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) Account(android.accounts.Account) FileDataStorageManager(com.owncloud.android.datamodel.FileDataStorageManager) Pair(android.support.v4.util.Pair)

Aggregations

Pair (android.support.v4.util.Pair)79 ArrayList (java.util.ArrayList)56 Pair (org.apache.commons.math3.util.Pair)38 List (java.util.List)30 View (android.view.View)28 Collectors (java.util.stream.Collectors)20 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)19 Intent (android.content.Intent)18 Arrays (java.util.Arrays)17 Map (java.util.Map)17 IntStream (java.util.stream.IntStream)17 MaxEval (org.apache.commons.math3.optim.MaxEval)17 HashMap (java.util.HashMap)16 TextView (android.widget.TextView)15 ObjectiveFunction (org.apache.commons.math3.optim.nonlinear.scalar.ObjectiveFunction)15 InitialGuess (org.apache.commons.math3.optim.InitialGuess)14 PointValuePair (org.apache.commons.math3.optim.PointValuePair)14 MultivariateOptimizer (org.apache.commons.math3.optim.nonlinear.scalar.MultivariateOptimizer)14 java.util (java.util)13 Collections (java.util.Collections)13