Exemplo n.º 1
0
    def fit_from_w(self,
                   w,
                   attr,
                   n_regions,
                   method="flow",
                   solver="cbc",
                   metric="euclidean"):
        """
        Alternative API for :meth:`fit_from_scipy_sparse_matrix`.

        Parameters
        ----------
        w : libpysal.weights.W
            W object representing the areas' contiguity relation.
        attr : :class:`numpy.ndarray`
            See the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        n_regions : int
            See the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        method : str
            See the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        solver : str
            See the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        metric : str or function, default: "euclidean"
            See the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        """
        adj = scipy_sparse_matrix_from_w(w)
        self.fit_from_scipy_sparse_matrix(
            adj, attr, n_regions, method=method, solver=solver, metric=metric)
Exemplo n.º 2
0
    def fit_from_w(self,
                   w,
                   attr,
                   n_regions,
                   initial_labels=None,
                   objective_func=ObjectiveFunctionPairwise()):
        """
        Alternative API for :meth:`fit_from_scipy_sparse_matrix`.

        Parameters
        ----------
        w : :class:`libpysal.weights.weights.W`
            W object representing the contiguity relation.
        attr : :class:`numpy.ndarray`
            Refer to the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        n_regions : `int`
            Refer to the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        initial_labels : :class:`numpy.ndarray` or None, default: None
            Refer to the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        objective_func : :class:`region.ObjectiveFunction`, default: ObjectiveFunctionPairwise()
            Refer to the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        """
        adj = scipy_sparse_matrix_from_w(w)
        self.fit_from_scipy_sparse_matrix(
            adj,
            attr,
            n_regions,
            initial_labels,
            objective_func=objective_func)
Exemplo n.º 3
0
    def fit_from_w(self, w, attr, spatially_extensive_attr, threshold,
                   solver="cbc", metric="euclidean"):
        """
        Alternative API for :meth:`fit_from_scipy_sparse_matrix:.

        Parameters
        ----------
        w : libpysal.weights.W
            W object representing the areas' contiguity relation.
        attr : :class:`numpy.ndarray`
            See the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        spatially_extensive_attr : :class:`numpy.ndarray`
            See the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        threshold : numbers.Real or :class:`numpy.ndarray`
            Refer to the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        solver : {"cbc", "cplex", "glpk", "gurobi"}, default: "cbc"
            Refer to the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        metric : str or function, default: "euclidean"
            Refer to the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        """
        adj = scipy_sparse_matrix_from_w(w)
        self.fit_from_scipy_sparse_matrix(adj, attr, spatially_extensive_attr,
                                          threshold=threshold, solver=solver,
                                          metric=metric)
Exemplo n.º 4
0
    def fit_from_w(self,
                   w,
                   attr,
                   spatially_extensive_attr,
                   threshold,
                   max_it=10,
                   objective_func=ObjectiveFunctionPairwise()):
        """
        Alternative API for :meth:`fit_from_scipy_sparse_matrix:.

        Parameters
        ----------
        w : :class:`libpysal.weights.weights.W`
            W object representing the contiguity relation.
        attr : :class:`numpy.ndarray`
            Each element specifies an area's attribute which is used for
            calculating the objective function.
        spatially_extensive_attr : :class:`numpy.ndarray`
            Each element specifies an area's spatially extensive attribute
            which is used to ensure that the sum of spatially extensive
            attributes in each region adds up to a threshold defined by the
            `threshold` argument.
        threshold : numbers.Real or :class:`numpy.ndarray`
            Refer to the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        max_it : int, default: 10
            Refer to the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        objective_func : :class:`region.ObjectiveFunction`, default: ObjectiveFunctionPairwise()
            Refer to the corresponding argument in
            :meth:`fit_from_scipy_sparse_matrix`.
        """
        adj = scipy_sparse_matrix_from_w(w)
        self.fit_from_scipy_sparse_matrix(adj,
                                          attr,
                                          spatially_extensive_attr,
                                          threshold,
                                          max_it=max_it,
                                          objective_func=objective_func)
Exemplo n.º 5
0
 def fit_from_w(self,
                w,
                attr,
                n_regions,
                initial_labels=None,
                cooling_factor=0.85,
                objective_func=ObjectiveFunctionPairwise()):
     """
     Parameters
     ----------
     w : :class:`libpysal.weights.weights.W`
         Refer to the corresponding argument in :meth:`AZP.fit_from_w`.
     attr : :class:`numpy.ndarray`
         Refer to the corresponding argument in
         :meth:`fit_from_scipy_sparse_matrix`.
     n_regions : `int`
         Refer to the corresponding argument in
         :meth:`fit_from_scipy_sparse_matrix`.
     initial_labels : :class:`numpy.ndarray` or None, default: None
         Refer to the corresponding argument in
         :meth:`fit_from_scipy_sparse_matrix`.
     cooling_factor : float, default: 0.85
         Refer to the corresponding argument in
         :meth:`fit_from_scipy_sparse_matrix`.
     objective_func : :class:`region.ObjectiveFunction`, default: ObjectiveFunctionPairwise()
         Refer to the corresponding argument in
         :meth:`fit_from_scipy_sparse_matrix`.
     """
     adj = scipy_sparse_matrix_from_w(w)
     self.fit_from_scipy_sparse_matrix(
         adj,
         attr,
         n_regions,
         initial_labels,
         cooling_factor=cooling_factor,
         objective_func=objective_func)