@Test public void toMutableMap() { int max = 5; List<List<Integer>> l = List.range(1, max + 1).map(n -> List.single(n)); TreeMap<List<Integer>, String> m2 = TreeMap.treeMap(Ord.listOrd(Ord.intOrd), l.zip(l.map(i -> i.toString()))); Map<List<Integer>, String> mm = m2.toMutableMap(); assertEquals(m2.keys(), List.fromIterable(mm.keySet())); }
@Override public Vector get(Particle particle) { Vector velocity = (Vector) particle.getVelocity(); Vector position = (Vector) particle.getPosition(); PSO algorithm = (PSO) AbstractAlgorithm.get(); int ns = (int) nSize.getParameter(); fj.data.List<Particle> neighbours = algorithm .getTopology() .sort( Ord.ord( VectorBasedFunctions.sortByDistance(particle, new EuclideanDistanceMeasure()))) .take(ns); Vector.Builder builder = Vector.newBuilder(); for (int i = 0; i < particle.getDimension(); ++i) { double informationSum = 0.0; double randomSum = 0; for (Particle currentTarget : neighbours) { Vector currentTargetPosition = (Vector) currentTarget.getBestPosition(); double randomComponent = Rand.nextDouble() * (4.1 / ns); informationSum += randomComponent * currentTargetPosition.doubleValueOf(i); randomSum += randomComponent; } double value = inertiaWeight.getParameter() * (velocity.doubleValueOf(i) + randomSum * ((informationSum / (ns * randomSum) - position.doubleValueOf(i)))); builder.add(value); } return builder.build(); }
/** * Invariant functor map over this enumerator. * * @param f The covariant map. * @param g The contra-variant map. * @return An enumerator after the given functions are applied. */ public <B> Enumerator<B> xmap(final F<A, B> f, final F<B, A> g) { final F<Option<A>, Option<B>> of = o -> o.map(f); return enumerator( compose(compose(of, successor), g), compose(compose(of, predecessor), g), max.map(f), min.map(f), order.contramap(g), compose(compose(Function.<Long, Option<A>, Option<B>>compose().f(of), plus), g)); }