# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class SpectralParams(BaseModel):
    """
    Parameters for Spectral clustering algorithm.
    """ # noqa: E501
    n_clusters: Optional[Annotated[int, Field(strict=True, ge=2)]] = Field(default=8, description="Number of clusters to form")
    eigen_solver: Optional[StrictStr] = Field(default=None, description="The eigenvalue decomposition strategy ('arpack', 'lobpcg', 'amg', or None)")
    n_components: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field(default=None, description="Number of eigenvectors to use for spectral embedding")
    random_state: Optional[StrictInt] = Field(default=42, description="Random seed for reproducibility")
    n_init: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field(default=10, description="Number of times k-means will run with different centroid seeds")
    gamma: Optional[Union[StrictFloat, StrictInt]] = Field(default=1.0, description="Kernel coefficient for rbf, poly, sigmoid, laplacian and chi2 kernels")
    affinity: Optional[StrictStr] = Field(default='rbf', description="How to construct the affinity matrix ('nearest_neighbors', 'rbf', 'precomputed', 'precomputed_nearest_neighbors')")
    n_neighbors: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field(default=10, description="Number of neighbors to use when constructing the affinity matrix using nearest neighbors")
    eigen_tol: Optional[Union[Annotated[float, Field(strict=True, ge=0.0)], Annotated[int, Field(strict=True, ge=0)]]] = Field(default=0.0, description="Stopping criterion for eigendecomposition")
    assign_labels: Optional[StrictStr] = Field(default='kmeans', description="Strategy to assign labels in the embedding space ('kmeans' or 'discretize')")
    degree: Optional[Union[StrictFloat, StrictInt]] = Field(default=3, description="Degree of the polynomial kernel. Ignored by other kernels")
    coef0: Optional[Union[StrictFloat, StrictInt]] = Field(default=1, description="Zero coefficient for polynomial and sigmoid kernels")
    kernel_params: Optional[Dict[str, Any]] = Field(default=None, description="Parameters for the kernel function")
    n_jobs: Optional[StrictInt] = Field(default=1, description="Number of parallel jobs to run (-1 means using all processors)")
    verbose: Optional[StrictBool] = Field(default=False, description="Verbosity mode")
    __properties: ClassVar[List[str]] = ["n_clusters", "eigen_solver", "n_components", "random_state", "n_init", "gamma", "affinity", "n_neighbors", "eigen_tol", "assign_labels", "degree", "coef0", "kernel_params", "n_jobs", "verbose"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of SpectralParams from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of SpectralParams from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "n_clusters": obj.get("n_clusters") if obj.get("n_clusters") is not None else 8,
            "eigen_solver": obj.get("eigen_solver"),
            "n_components": obj.get("n_components"),
            "random_state": obj.get("random_state") if obj.get("random_state") is not None else 42,
            "n_init": obj.get("n_init") if obj.get("n_init") is not None else 10,
            "gamma": obj.get("gamma") if obj.get("gamma") is not None else 1.0,
            "affinity": obj.get("affinity") if obj.get("affinity") is not None else 'rbf',
            "n_neighbors": obj.get("n_neighbors") if obj.get("n_neighbors") is not None else 10,
            "eigen_tol": obj.get("eigen_tol") if obj.get("eigen_tol") is not None else 0.0,
            "assign_labels": obj.get("assign_labels") if obj.get("assign_labels") is not None else 'kmeans',
            "degree": obj.get("degree") if obj.get("degree") is not None else 3,
            "coef0": obj.get("coef0") if obj.get("coef0") is not None else 1,
            "kernel_params": obj.get("kernel_params"),
            "n_jobs": obj.get("n_jobs") if obj.get("n_jobs") is not None else 1,
            "verbose": obj.get("verbose") if obj.get("verbose") is not None else False
        })
        return _obj


