import { OpenAssistantTool } from '@openassistant/utils'; import { z } from 'zod'; import { LocalMoranResult } from '@geoda/lisa'; import { GetGeometries, GetValues } from '../types'; export type LisaFunctionArgs = z.ZodObject<{ method: z.ZodEnum<['localMoran', 'localGeary', 'localG', 'localGStar', 'quantileLisa']>; weightsID: z.ZodOptional; variableName: z.ZodString; multiVariableNames: z.ZodOptional>; biVariableNames: z.ZodOptional>; permutation: z.ZodOptional; significanceThreshold: z.ZodOptional; datasetName: z.ZodString; k?: z.ZodOptional; quantile?: z.ZodOptional; mapBounds?: z.ZodOptional>; }>; export type LisaLlmResult = { success: boolean; globalMoranI?: number; clusterColorAndLabels?: Array<{ value: number; label: string; color: string; numberOfObservations: number; }>; error?: string; instructions?: string; datasetName?: string; }; export type LisaAdditionalData = Partial & { datasetName: string; originalDatasetName: string; significanceThreshold: number; }; export type LisaFunctionContext = { getValues: GetValues; getGeometries?: GetGeometries; }; /** * ## lisa Tool * * This tool applies Local Indicators of Spatial Association (LISA) statistics to identify local clusters and spatial outliers. * It helps detect areas where similar values cluster together or where outliers exist in the spatial distribution. * * ### LISA Methods * * The LISA method can be one of the following types: * - **localMoran**: Local Moran's I statistic for detecting clusters and outliers * - **localGeary**: Local Geary's C statistic for detecting spatial heterogeneity * - **localG**: Local Getis-Ord G statistic for detecting hot and cold spots * - **localGStar**: Local Getis-Ord G* statistic (includes the observation itself) * - **quantileLisa**: Quantile-based LISA analysis * * ### Parameters * - `datasetName`: Name of the dataset containing the variable * - `variableName`: Name of the numerical variable to analyze * - `method`: LISA method to use (see above) * - `weightsID`: ID of spatial weights matrix (optional, will use cached weights if available) * - `permutation`: Number of permutations for significance testing (default: 999) * - `significanceThreshold`: Significance threshold for filtering results (default: 0.05) * - `k`: Number of quantiles for quantile LISA (required for quantileLisa method) * - `quantile`: Quantile value for quantile LISA (required for quantileLisa method) * * **Example user prompts:** * - "Are young population clustering over the zipcode areas?" * - "Can you perform a local Moran's I analysis on the population data?" * - "What are the local clusters in the population data?" * - "How many significant clusters are there in the population data?" * * ### Example * ```typescript * import { lisa } from "@openassistant/geoda"; * import { convertToVercelAiTool } from "@openassistant/utils"; * * const lisaTool = { * ...lisa, * context: { * getValues: async (datasetName: string, variableName: string) => { * // Implementation to retrieve values from your data source * return [100, 200, 150, 300, 250, 180, 220, 190, 280, 210]; * }, * }, * }; * * const result = await generateText({ * model: openai('gpt-4.1', { apiKey: key }), * prompt: 'Can you perform a local Moran analysis on the population data?', * tools: { lisa: convertToVercelAiTool(lisaTool) }, * }); * ``` * * :::note * The LISA tool should always be used with the spatialWeights tool. The LLM models know how to use the spatialWeights tool for the LISA analysis. * ::: */ export declare const lisa: OpenAssistantTool; export type LisaTool = typeof lisa;