Example #1
0
  private static double[] computeXaXs(
      final IScope scope,
      final IAgentFilter filter,
      final Map<Object, Integer> categoriesId,
      final Map<IAgent, Integer> agsId,
      final int valObsId,
      final int valSimId,
      final int valInitId,
      final GamaMatrix<Double> fuzzytransitions,
      final Double distance,
      final IAgent agent,
      final IList<Object> valsInit,
      final IList<Object> valsObs,
      final IList<Object> valsSim,
      final IContainer.Addressable<Integer, IAgent> agents,
      final int nbCat) {
    double xa = 0.0;
    double xs = 0.0;
    double[] XaXs = new double[2];
    double sizeNorm = FastMath.sqrt(agent.getEnvelope().getArea());
    List<IAgent> neighbors =
        distance == 0 || filter == null
            ? new ArrayList<IAgent>()
            : new ArrayList<IAgent>(
                scope.getTopology().getNeighborsOf(scope, agent, distance, filter));

    Map<IAgent, Double> distancesCoeff = new TOrderedHashMap<IAgent, Double>();
    distancesCoeff.put(agent, 1.0);
    for (IAgent ag : neighbors) {
      double euclidDist = agent.getLocation().euclidianDistanceTo(ag.getLocation());
      distancesCoeff.put(ag, 1 / (1.0 + euclidDist / sizeNorm));
    }
    for (IAgent ag : distancesCoeff.keySet()) {
      int id = agsId.get(ag);
      Object valI = valsInit.get(id);
      Object valO = valsObs.get(id);
      Object valS = valsSim.get(id);
      int valOId = categoriesId.get(valO);
      int valSId = categoriesId.get(valS);
      int valIId = categoriesId.get(valI);
      double dist = distancesCoeff.get(ag);
      double valxatmp =
          fuzzyTransition(scope, fuzzytransitions, nbCat, valInitId, valSimId, valIId, valOId)
              * dist;
      double valxstmp =
          fuzzyTransition(scope, fuzzytransitions, nbCat, valInitId, valObsId, valIId, valSId)
              * dist;

      if (valxatmp > xa) {
        xa = valxatmp;
      }
      if (valxstmp > xs) {
        xs = valxstmp;
      }
    }

    XaXs[0] = xa;
    XaXs[1] = xs;
    return XaXs;
  }
 @Override
 public List<String> getAspectNames() {
   return new ArrayList<String>(aspects.keySet());
 }
 @Override
 public Collection<String> getMicroSpeciesNames() {
   return microSpecies.keySet();
 }
Example #4
0
  private static void computeXaXsTransitions(
      final IScope scope,
      final IAgentFilter filter,
      final GamaMatrix<Double> fuzzytransitions,
      final Double distance,
      final IContainer<Integer, IAgent> agents,
      final int nbCat,
      final Map<List<Integer>, Map<Double, Double>> XaPerTransition,
      final Map<List<Integer>, Map<Double, Double>> XsPerTransition,
      final Set<Double> Xvals) {

    IList<ILocation> locs = GamaListFactory.create(Types.POINT);
    for (IAgent ag : agents.iterable(scope)) {
      locs.add(ag.getLocation());
    }
    ILocation centralLoc = (ILocation) Stats.getMean(scope, locs);
    if (filter != null) {
      IAgent centralAg = scope.getTopology().getAgentClosestTo(scope, centralLoc, filter);
      List<IAgent> neighbors =
          distance == 0
              ? new ArrayList<IAgent>()
              : new ArrayList<IAgent>(
                  scope.getTopology().getNeighborsOf(scope, centralAg, distance, filter));
      double sizeNorm = FastMath.sqrt(centralAg.getEnvelope().getArea());

      Map<IAgent, Double> distancesCoeff = new TOrderedHashMap<IAgent, Double>();
      distancesCoeff.put(centralAg, 1.0);
      for (IAgent ag : neighbors) {
        double euclidDist = centralAg.getLocation().euclidianDistanceTo(ag.getLocation());
        double dist = 1 / (1.0 + euclidDist / sizeNorm);
        distancesCoeff.put(ag, dist);
      }

      for (int i = 0; i < nbCat; i++) {
        for (int j = 0; j < nbCat; j++) {
          for (int k = 0; k < nbCat; k++) {
            List<Integer> ca = new ArrayList();
            ca.add(i);
            ca.add(j);
            ca.add(k);
            double xa = 0;
            double xs = 0;
            for (IAgent ag : distancesCoeff.keySet()) {
              double dist = distancesCoeff.get(ag);
              double xatmp = fuzzyTransition(scope, fuzzytransitions, nbCat, i, k, i, j) * dist;
              double xstmp = fuzzyTransition(scope, fuzzytransitions, nbCat, i, j, i, k) * dist;
              if (xatmp > xa) {
                xa = xatmp;
              }
              if (xstmp > xs) {
                xs = xstmp;
              }
            }
            if (xa > 0) {

              Map<Double, Double> mapxa = XaPerTransition.get(ca);
              if (mapxa == null) {
                mapxa = new TOrderedHashMap<Double, Double>();
                mapxa.put(xa, 1.0);
                XaPerTransition.put(ca, mapxa);
              } else {
                if (mapxa.containsKey(xa)) {
                  mapxa.put(xa, mapxa.get(xa) + 1.0);
                } else {
                  mapxa.put(xa, 1.0);
                }
              }
              Xvals.add(xa);
            }
            if (xs > 0) {
              Map<Double, Double> mapxs = XsPerTransition.get(ca);
              if (mapxs == null) {
                mapxs = new TOrderedHashMap<Double, Double>();
                mapxs.put(xs, 1.0);
                XsPerTransition.put(ca, mapxs);
              } else {
                if (mapxs.containsKey(xa)) {
                  mapxs.put(xs, mapxs.get(xs) + 1.0);
                } else {
                  mapxs.put(xs, 1.0);
                }
              }
              Xvals.add(xs);
            }
          }
        }
      }
    }
  }