private static double computePo( final IScope scope, final IAgentFilter filter, final Map<Object, Integer> categoriesId, final GamaMatrix<Double> fuzzytransitions, final Double distance, final IList<Object> valsInit, final IList<Object> valsObs, final IList<Object> valsSim, final IAddressableContainer<Integer, IAgent, Integer, IAgent> agents, final int nbCat, final int nb, final IList<Double> similarities, final IList<Object> weights) { Map<IAgent, Integer> agsId = new TOrderedHashMap<IAgent, Integer>(); for (int i = 0; i < agents.length(scope); i++) { agsId.put(agents.get(scope, i), i); } for (int i = 0; i < nb; i++) { Object valObs = valsObs.get(i); Object valSim = valsSim.get(i); Object valInit = valsInit.get(i); int valObsId = categoriesId.get(valObs); int valSimId = categoriesId.get(valSim); int valInitId = categoriesId.get(valInit); IAgent agent = agents.get(scope, i); double[] XaXs = computeXaXs( scope, filter, categoriesId, agsId, valObsId, valSimId, valInitId, fuzzytransitions, distance, agent, valsInit, valsObs, valsSim, agents, nbCat); similarities.add(FastMath.min(XaXs[0], XaXs[1])); } double meanSimilarity = 0; double total = 0; for (int i = 0; i < nb; i++) { double weight = weights == null ? 1.0 : Cast.asFloat(scope, weights.get(i)); double val = weight * similarities.get(i); total += weight; meanSimilarity += val; } meanSimilarity /= total; return meanSimilarity; }
private static double computeSimilarity( final IScope scope, final IAgentFilter filter, final Double distance, final IList<Object> vals1, final IList<Object> vals2, final IAddressableContainer<Integer, IAgent, Integer, IAgent> agents, final int nbCat, final int nb, final double[][] crispVector1, final double[][] crispVector2, final boolean[] sim, final double[][] fuzzyVector1, final double[][] fuzzyVector2, final IList<Double> similarities, final IList<Object> weights) { Map<IAgent, Integer> agsId = new TOrderedHashMap<IAgent, Integer>(); for (int i = 0; i < agents.length(scope); i++) { agsId.put(agents.get(scope, i), i); } for (int i = 0; i < nb; i++) { if (sim[i]) { similarities.add(1.0); } else { IAgent agent = agents.get(scope, i); // double sizeNorm = agent.getPerimeter() / 4.0; 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 (int j = 0; j < nbCat; j++) { double max1 = 0.0; double max2 = 0.0; for (IAgent ag : neighbors) { int id = agsId.get(ag); double val1 = crispVector1[id][j] * distancesCoeff.get(ag); double val2 = crispVector2[id][j] * distancesCoeff.get(ag); if (val1 > max1) { max1 = val1; } if (val2 > max2) { max2 = val2; } } fuzzyVector1[i][j] = max1; fuzzyVector2[i][j] = max2; } double s1Max = -1 * Double.MAX_VALUE; double s2Max = -1 * Double.MAX_VALUE; for (int j = 0; j < nbCat; j++) { double s1 = FastMath.min(fuzzyVector1[i][j], crispVector2[i][j]); double s2 = FastMath.min(fuzzyVector2[i][j], crispVector1[i][j]); if (s1 > s1Max) { s1Max = s1; } if (s2 > s2Max) { s2Max = s2; } } similarities.add(FastMath.min(s1Max, s2Max)); } } double meanSimilarity = 0; double total = 0; for (int i = 0; i < nb; i++) { double weight = weights == null ? 1.0 : Cast.asFloat(scope, weights.get(i)); double val = weight * similarities.get(i); total += weight; meanSimilarity += val; } meanSimilarity /= total; return meanSimilarity; }