Search in sources :

Example 76 with Pair

use of org.apache.commons.math3.util.Pair in project vcell by virtualcell.

the class PlotImageStats method run.

@Override
public void run() {
    Plot plot = new ColorPlot("Frame mean intensity", "Time", "Mean intensity");
    StringBuilder legendLabels = new StringBuilder();
    for (int i = 0; i < datasets.size(); i++) {
        RandomAccessibleInterval<T> data = datasets.get(i);
        if (data instanceof Dataset) {
            legendLabels.append(((Dataset) data).getName());
            legendLabels.append(": ");
        }
        Pair<double[], double[]> xyPair = (Pair<double[], double[]>) ops.run("imageStatsForPlotting", ImageStatsForPlotting.MEAN, data, mask);
        plot.addPoints(xyPair.getA(), xyPair.getB(), Plot.LINE);
        legendLabels.append("ROI ");
        legendLabels.append(i + 1);
        legendLabels.append("\n");
    }
    plot.addLegend(legendLabels.toString());
    plot.show();
}
Also used : ColorPlot(org.vcell.imagej.common.gui.ColorPlot) Dataset(net.imagej.Dataset) Plot(ij.gui.Plot) ColorPlot(org.vcell.imagej.common.gui.ColorPlot) Pair(net.imglib2.util.Pair)

Example 77 with Pair

use of org.apache.commons.math3.util.Pair in project vcell by virtualcell.

the class PlotROIStats method run.

@Override
public void run() {
    Plot plot = new ColorPlot("ROI Mean Intensity", "Time", "Mean Intensity");
    StringBuilder legendLabels = new StringBuilder();
    for (RandomAccessibleInterval<T> data : datasetROIsMap.keySet()) {
        if (data instanceof Dataset) {
            legendLabels.append(((Dataset) data).getName());
            legendLabels.append(": ");
        }
        List<Overlay> overlays = datasetROIsMap.get(data);
        for (int i = 0; i < overlays.size(); i++) {
            Overlay overlay = overlays.get(i);
            RandomAccessibleInterval<T> cropped = crop(data, overlay);
            Pair<double[], double[]> xyPair = (Pair<double[], double[]>) ops.run("imageStatsForPlotting", ImageStatsForPlotting.MEAN, cropped);
            plot.addPoints(xyPair.getA(), xyPair.getB(), Plot.LINE);
            legendLabels.append("ROI ");
            legendLabels.append(i + 1);
            legendLabels.append("\n");
        }
    }
    plot.addLegend(legendLabels.toString());
    plot.show();
}
Also used : ColorPlot(org.vcell.imagej.common.gui.ColorPlot) Dataset(net.imagej.Dataset) Plot(ij.gui.Plot) ColorPlot(org.vcell.imagej.common.gui.ColorPlot) Overlay(net.imagej.overlay.Overlay) Pair(net.imglib2.util.Pair)

Example 78 with Pair

use of org.apache.commons.math3.util.Pair in project Shuttle by timusus.

the class Aesthetic method resume.

/**
 * Should be called in onResume() of each Activity.
 */
public void resume(@NonNull final AppCompatActivity activity) {
    if (instance == null) {
        return;
    }
    instance.context = activity;
    if (instance.subs != null) {
        instance.subs.clear();
    }
    instance.subs = new CompositeDisposable();
    instance.subs.add(instance.colorPrimary().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(@io.reactivex.annotations.NonNull Integer color) {
            Util.setTaskDescriptionColor(activity, color);
        }
    }, onErrorLogAndRethrow()));
    instance.subs.add(instance.activityTheme().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(@io.reactivex.annotations.NonNull Integer themeId) {
            if (getLastActivityTheme(activity) == themeId) {
                return;
            }
            instance.lastActivityThemes.put(activity.getClass().getName(), themeId);
            activity.recreate();
        }
    }, onErrorLogAndRethrow()));
    instance.subs.add(Observable.combineLatest(instance.colorStatusBar(), instance.lightStatusBarMode(), new BiFunction<Integer, Integer, Pair<Integer, Integer>>() {

        @Override
        public Pair<Integer, Integer> apply(Integer integer, Integer integer2) {
            return Pair.create(integer, integer2);
        }
    }).compose(Rx.<Pair<Integer, Integer>>distinctToMainThread()).subscribe(new Consumer<Pair<Integer, Integer>>() {

        @Override
        public void accept(@io.reactivex.annotations.NonNull Pair<Integer, Integer> result) {
            instance.invalidateStatusBar(activity);
        }
    }, onErrorLogAndRethrow()));
    instance.subs.add(instance.colorNavigationBar().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(@io.reactivex.annotations.NonNull Integer color) {
            setNavBarColorCompat(activity, color);
        }
    }, onErrorLogAndRethrow()));
    instance.subs.add(instance.colorWindowBackground().compose(Rx.<Integer>distinctToMainThread()).subscribe(new Consumer<Integer>() {

        @Override
        public void accept(@io.reactivex.annotations.NonNull Integer color) {
            activity.getWindow().setBackgroundDrawable(new ColorDrawable(color));
        }
    }, onErrorLogAndRethrow()));
    if (MaterialDialogsUtil.shouldSupport()) {
        instance.subs.add(MaterialDialogsUtil.observe(instance));
    }
}
Also used : Consumer(io.reactivex.functions.Consumer) ColorDrawable(android.graphics.drawable.ColorDrawable) BiFunction(io.reactivex.functions.BiFunction) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Pair(android.support.v4.util.Pair)

Example 79 with Pair

use of org.apache.commons.math3.util.Pair in project Shuttle by timusus.

the class BitmapPaletteProcessor method processBitmap.

/**
 * Processes a builder of a media notification and calculates the appropriate colors that should
 * be used.
 *
 * @param bitmap
 *
 * returns a {@link Pair} of integers. The first is the background colour, second is foreground colour.
 */
public Pair<Integer, Integer> processBitmap(Bitmap bitmap) {
    int backgroundColor = 0;
    // we want all colors, red / white / black ones too!;
    Palette.Builder paletteBuilder = Palette.from(bitmap).clearFilters();
    Palette palette = paletteBuilder.generate();
    backgroundColor = findBackgroundColorAndFilter(palette);
    if (mFilteredBackgroundHsl != null) {
        paletteBuilder.addFilter((rgb, hsl) -> {
            // at least 10 degrees hue difference
            float diff = Math.abs(hsl[0] - mFilteredBackgroundHsl[0]);
            return diff > 10 && diff < 350;
        });
    }
    paletteBuilder.addFilter(mBlackWhiteFilter);
    palette = paletteBuilder.generate();
    int foregroundColor = selectForegroundColor(backgroundColor, palette);
    return new Pair<>(backgroundColor, foregroundColor);
}
Also used : Palette(android.support.v7.graphics.Palette) Pair(android.support.v4.util.Pair)

Example 80 with Pair

use of org.apache.commons.math3.util.Pair in project drools by kiegroup.

the class GroupByTest method testDecomposedGroupByKeyAnd2Accumulates.

@Test
public void testDecomposedGroupByKeyAnd2Accumulates() throws Exception {
    // DROOLS-6031
    final Global<List> var_results = D.globalOf(List.class, "defaultpkg", "results");
    final Variable<Pair<String, String>> var_$key = (Variable) D.declarationOf(Pair.class);
    final Variable<Pair> var_$accumulate = D.declarationOf(Pair.class);
    final Variable<Person> var_$p = D.declarationOf(Person.class);
    final Variable<Person> var_$p2 = D.declarationOf(Person.class);
    final Variable<String> var_$subkeyA = D.declarationOf(String.class);
    final Variable<String> var_$subkeyB = D.declarationOf(String.class);
    final Variable<List> var_$accresult = D.declarationOf(List.class);
    final Variable<List> var_$accresult2 = D.declarationOf(List.class);
    final Rule rule1 = PatternDSL.rule("R1").build(D.groupBy(// Patterns
    D.and(D.pattern(var_$p), D.pattern(var_$p2).bind(var_$accumulate, var_$p, Pair::create)), // Grouping Function
    var_$p, var_$key, person -> Pair.create(person.getName().substring(0, 1), person.getName().substring(1, 2)), D.accFunction(CollectListAccumulateFunction::new, var_$accumulate).as(var_$accresult), D.accFunction(CollectListAccumulateFunction::new, var_$accumulate).as(var_$accresult2)), // Bindings
    D.pattern(var_$key).bind(var_$subkeyA, Pair::getKey).bind(var_$subkeyB, Pair::getValue), D.pattern(var_$accresult), // Consequence
    D.on(var_$subkeyA, var_$subkeyB, var_$accresult, var_results).execute(($a, $b, $accresult, results) -> {
        results.add($a);
        results.add($b);
        results.add($accresult);
    }));
    final Model model = new ModelImpl().addRule(rule1).addGlobal(var_results);
    final KieSession ksession = KieBaseBuilder.createKieBaseFromModel(model).newKieSession();
    final List<Object> results = new ArrayList<>();
    ksession.setGlobal("results", results);
    ksession.insert("A");
    ksession.insert("test");
    ksession.insert(new Person("Mark", 42));
    assertThat(ksession.fireAllRules()).isEqualTo(1);
    Assertions.assertThat(results.size()).isEqualTo(3);
    Assertions.assertThat(results.get(0)).isEqualTo("M");
    Assertions.assertThat(results.get(1)).isEqualTo("a");
}
Also used : Arrays(java.util.Arrays) InternalFactHandle(org.drools.core.common.InternalFactHandle) Accumulator(org.drools.core.spi.Accumulator) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Global(org.drools.model.Global) RuleEventListener(org.kie.internal.event.rule.RuleEventListener) DSL(org.drools.model.DSL) Child(org.drools.modelcompiler.domain.Child) Match(org.kie.api.runtime.rule.Match) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Declaration(org.drools.core.rule.Declaration) Assertions(org.assertj.core.api.Assertions) KieSession(org.kie.api.runtime.KieSession) Parent(org.drools.modelcompiler.domain.Parent) Set(java.util.Set) Index(org.drools.model.Index) ConsequenceBuilder(org.drools.model.consequences.ConsequenceBuilder) EvaluationUtil(org.drools.modelcompiler.util.EvaluationUtil) Objects(java.util.Objects) List(java.util.List) Tuple(org.drools.core.spi.Tuple) CountAccumulateFunction(org.drools.core.base.accumulators.CountAccumulateFunction) Person(org.drools.modelcompiler.domain.Person) DSL.from(org.drools.model.DSL.from) ModelImpl(org.drools.model.impl.ModelImpl) HashMap(java.util.HashMap) PatternDSL(org.drools.model.PatternDSL) ArrayList(java.util.ArrayList) Function1(org.drools.model.functions.Function1) CollectListAccumulateFunction(org.drools.core.base.accumulators.CollectListAccumulateFunction) RuleEventManager(org.kie.internal.event.rule.RuleEventManager) KieBase(org.kie.api.KieBase) LinkedHashSet(java.util.LinkedHashSet) Model(org.drools.model.Model) IntegerMaxAccumulateFunction(org.drools.core.base.accumulators.IntegerMaxAccumulateFunction) ReteEvaluator(org.drools.core.common.ReteEvaluator) ViewItem(org.drools.model.view.ViewItem) Pair(org.apache.commons.math3.util.Pair) Variable(org.drools.model.Variable) D(org.drools.modelcompiler.dsl.pattern.D) IntegerSumAccumulateFunction(org.drools.core.base.accumulators.IntegerSumAccumulateFunction) ToIntFunction(java.util.function.ToIntFunction) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) GroupKey(org.drools.model.functions.accumulate.GroupKey) FactHandle(org.kie.api.runtime.rule.FactHandle) KieBaseBuilder(org.drools.modelcompiler.builder.KieBaseBuilder) Assert.assertNull(org.junit.Assert.assertNull) Ignore(org.junit.Ignore) Rule(org.drools.model.Rule) ExprViewItem(org.drools.model.view.ExprViewItem) RuleTerminalNodeLeftTuple(org.drools.core.reteoo.RuleTerminalNodeLeftTuple) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Variable(org.drools.model.Variable) ArrayList(java.util.ArrayList) Model(org.drools.model.Model) List(java.util.List) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Rule(org.drools.model.Rule) ModelImpl(org.drools.model.impl.ModelImpl) Person(org.drools.modelcompiler.domain.Person) Pair(org.apache.commons.math3.util.Pair) Test(org.junit.Test)

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