@Deprecated
 @operator(
     value = "neighbors_of",
     content_type = IType.AGENT,
     category = {IOperatorCategory.SPATIAL, IOperatorCategory.SP_QUERIES})
 /* TODO, expected_content_type = { IType.FLOAT, IType.INT } */
 @doc(
     deprecated = "Use 'neighbours_of(topology, agent, distance)' instead",
     usages =
         @usage(
             value =
                 "a list, containing all the agents of the same species than the key of the pair argument (if it is an agent) located at a distance inferior or equal to the right member (float) of the pair (right-hand operand) to the left member (agent, geometry or point) considering the left-hand operand topology.",
             examples = {
               @example(
                   value = "topology(self) neighbors_of self::10",
                   equals =
                       "all the agents located at a distance lower or equal to 10 to the agent applying the operator considering its topology.",
                   test = false)
             }))
 public static IList neighbours_of(final IScope scope, final ITopology t, final GamaPair pair) {
   if (pair == null) {
     return GamaListFactory.EMPTY_LIST;
   }
   Object agent = pair.key;
   return Spatial.Queries._neighbours(
       scope,
       agent instanceof IAgent
           ? In.list(scope, ((IAgent) agent).getPopulation())
           : Different.with(),
       agent,
       pair.value,
       t);
   // TODO We could compute a filter based on the population if it is an agent
 }
Example #2
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);
  }
Example #3
0
  @operator(
      value = {"fuzzy_kappa"},
      content_type = IType.FLOAT,
      category = {IOperatorCategory.MAP_COMPARAISON},
      concept = {})
  @doc(
      value =
          "fuzzy kappa indicator for 2 map comparisons: fuzzy_kappa(agents_list,list_vals1,list_vals2, output_similarity_per_agents,categories,fuzzy_categories_matrix, fuzzy_distance, weights). Reference: Visser, H., and T. de Nijs, 2006. The map comparison kit, Environmental Modelling & Software, 21",
      examples = {
        @example(
            value =
                "fuzzy_kappa([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,1,0],[0,0,1]], 2, [1.0,3.0,2.0,2.0,4.0])",
            isExecutable = false)
      })
  public static double fuzzyKappa(
      final IScope scope,
      final IAddressableContainer<Integer, IAgent, Integer, IAgent> agents,
      final IList<Object> vals1,
      final IList<Object> vals2,
      final IList<Double> similarities,
      final List<Object> categories,
      final GamaMatrix<Double> fuzzycategories,
      final Double distance,
      final IList<Object> weights) {
    if (agents == null) {
      return 1;
    }
    int nb = agents.length(scope);
    if (nb < 1) {
      return 1;
    }
    int nbCat = categories.size();
    similarities.clear();
    boolean[] sim = new boolean[nb];
    double[][] crispVector1 = new double[nb][nbCat];
    double[][] crispVector2 = new double[nb][nbCat];
    double[][] fuzzyVector1 = new double[nb][nbCat];
    double[][] fuzzyVector2 = new double[nb][nbCat];
    double[] X = new double[nbCat];
    double[] Y = new double[nbCat];
    Map<Object, Integer> categoriesId = new TOrderedHashMap<Object, Integer>();
    for (int i = 0; i < nbCat; i++) {
      categoriesId.put(categories.get(i), i);
    }
    IAgentFilter filter = In.list(scope, agents);

    computeXYCrispVector(
        scope,
        categoriesId,
        categories,
        vals1,
        vals2,
        fuzzycategories,
        nbCat,
        nb,
        crispVector1,
        crispVector2,
        X,
        Y,
        sim,
        weights);
    double meanSimilarity =
        computeSimilarity(
            scope,
            filter,
            distance,
            vals1,
            vals2,
            agents,
            nbCat,
            nb,
            crispVector1,
            crispVector2,
            sim,
            fuzzyVector1,
            fuzzyVector2,
            similarities,
            weights);

    List<Double> rings = new ArrayList<Double>();
    Map<Double, Integer> ringsPn = new TOrderedHashMap<Double, Integer>();
    int nbRings = buildRings(scope, filter, distance, rings, ringsPn, agents);
    double similarityExpected = computeExpectedSim(nbCat, X, Y, nbRings, rings, ringsPn);
    if (similarityExpected == 1) {
      return 1;
    }
    return (meanSimilarity - similarityExpected) / (1 - similarityExpected);
  }