示例#1
0
 @Override
 public boolean hasAspect(final String n) {
   return aspects.containsKey(n);
 }
示例#2
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);
            }
          }
        }
      }
    }
  }
示例#3
0
 @Override
 public boolean hasVar(final String name) {
   return variables.containsKey(name);
 }
示例#4
0
  @operator(
      value = {"fuzzy_kappa_sim"},
      content_type = IType.FLOAT,
      category = {IOperatorCategory.MAP_COMPARAISON},
      concept = {IConcept.MAP})
  @doc(
      value =
          "fuzzy kappa simulation indicator for 2 map comparisons: fuzzy_kappa_sim(agents_list,list_vals1,list_vals2, output_similarity_per_agents,fuzzy_transitions_matrix, fuzzy_distance, weights). Reference: Jasper van Vliet, Alex Hagen-Zanker, Jelle Hurkens, Hedwig van Delden, A fuzzy set approach to assess the predictive accuracy of land use simulations, Ecological Modelling, 24 July 2013, Pages 32-42, ISSN 0304-3800, ",
      examples = {
        @example(
            value =
                "fuzzy_kappa_sim([ag1, ag2, ag3, ag4, ag5], [cat1,cat1,cat2,cat3,cat2],[cat2,cat1,cat2,cat1,cat2], similarity_per_agents,[cat1,cat2,cat3],[[1,0,0,0,0,0,0,0,0],[0,1,0,0,0,0,0,0,0],[0,0,1,0,0,0,0,0,0],[0,0,0,1,0,0,0,0,0],[0,0,0,0,1,0,0,0,0],[0,0,0,0,0,1,0,0,0],[0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,1]], 2,[1.0,3.0,2.0,2.0,4.0])",
            isExecutable = false)
      })
  public static double fuzzyKappaSimulation(
      final IScope scope,
      final IAddressableContainer<Integer, IAgent, Integer, IAgent> agents,
      final IList<Object> valsInit,
      final IList<Object> valsObs,
      final IList<Object> valsSim,
      final IList<Double> similarities,
      final List<Object> categories,
      final GamaMatrix<Double> fuzzytransitions,
      final Double distance,
      final IList<Object> weights) {
    if (agents == null) {
      return 1;
    }
    int nb = agents.length(scope);
    if (nb < 1) {
      return 1;
    }
    similarities.clear();
    int nbCat = categories.size();
    double[] nbObs = new double[nbCat];
    double[] nbSim = new double[nbCat];
    double[] nbInit = new double[nbCat];
    double[][] nbInitObs = new double[nbCat][nbCat];
    double[][] nbInitSim = new double[nbCat][nbCat];
    Map<Object, Integer> categoriesId = new TOrderedHashMap<Object, Integer>();

    Map<List<Integer>, Map<Double, Double>> XaPerTransition =
        new TOrderedHashMap<List<Integer>, Map<Double, Double>>();
    Map<List<Integer>, Map<Double, Double>> XsPerTransition =
        new TOrderedHashMap<List<Integer>, Map<Double, Double>>();
    Set<Double> Xvals = new HashSet<Double>();
    for (int i = 0; i < nbCat; i++) {
      categoriesId.put(categories.get(i), i);
    }

    for (int i = 0; i < nbCat; i++) {
      nbInit[i] = 0;
      nbObs[i] = 0;
      nbSim[i] = 0;
      for (int j = 0; j < nbCat; j++) {
        nbInitObs[i][j] = 0;
        nbInitSim[i][j] = 0;
      }
    }
    IAgentFilter filter = In.list(scope, agents);
    double total = 0;
    for (int i = 0; i < nb; i++) {
      double weight = weights == null ? 1.0 : Cast.asFloat(scope, weights.get(i));
      total += weight;

      int idCatInit = categoriesId.get(valsInit.get(i));
      int idCatObs = categoriesId.get(valsObs.get(i));
      int idCatSim = categoriesId.get(valsSim.get(i));
      nbInit[idCatInit] += weight;
      nbSim[idCatSim] += weight;
      nbObs[idCatObs] += weight;
      nbInitObs[idCatInit][idCatObs] += weight;
      nbInitSim[idCatInit][idCatSim] += weight;
    }
    double po =
        computePo(
            scope,
            filter,
            categoriesId,
            fuzzytransitions,
            distance,
            valsInit,
            valsObs,
            valsSim,
            agents,
            nbCat,
            nb,
            similarities,
            weights);
    double pe = 0;
    computeXaXsTransitions(
        scope,
        filter,
        fuzzytransitions,
        distance,
        agents,
        nbCat,
        XaPerTransition,
        XsPerTransition,
        Xvals);
    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<Integer>();
          ca.add(i);
          ca.add(j);
          ca.add(k);
          Map<Double, Double> pmuXa = XaPerTransition.get(ca);
          Map<Double, Double> pmuXs = XsPerTransition.get(ca);
          double emu = 0;
          for (Double xval : Xvals) {
            double XaVal = pmuXa == null || !pmuXa.containsKey(xval) ? 0 : pmuXa.get(xval);
            double XsVal = pmuXs == null || !pmuXs.containsKey(xval) ? 0 : pmuXs.get(xval);
            double proba = xval * XaVal * XsVal;
            emu += proba;
          }

          double poas = nbInit[i] == 0 ? 0 : nbInitObs[i][j] / nbInit[i] * nbInitSim[i][k] / total;
          pe += emu * poas;
        }
      }
    }
    if (pe == 1) {
      return 1;
    }
    return (po - pe) / (1 - pe);
  }