/**
 * Bias Detection and Monitoring
 * Monitors AI model outputs for bias and fairness metrics
 * Vorion Security Platform
 */
import { EventEmitter } from 'events';
import { BiasDetectionResult, BiasAlert } from './types';
/**
 * Bias detection configuration
 */
export interface BiasDetectionConfig {
    enabled: boolean;
    alertThresholds: BiasThresholds;
    monitoringFrequency: 'realtime' | 'hourly' | 'daily' | 'weekly';
    protectedAttributes: string[];
    minimumSampleSize: number;
    significanceLevel: number;
    customMetrics: CustomMetricDefinition[];
    alertRecipients: string[];
    retentionDays: number;
}
/**
 * Bias thresholds for alerting
 */
export interface BiasThresholds {
    demographicParity: number;
    equalOpportunity: number;
    responseConsistency: number;
    representationGap: number;
    overallScore: number;
}
/**
 * Custom metric definition
 */
export interface CustomMetricDefinition {
    id: string;
    name: string;
    calculate: (samples: BiasSample[]) => number;
    threshold: number;
    higherIsBetter: boolean;
}
/**
 * Sample for bias analysis
 */
export interface BiasSample {
    id: string;
    modelId: string;
    timestamp: Date;
    input: string;
    output: string;
    attributes: Record<string, string>;
    outcome?: 'positive' | 'negative' | 'neutral';
    confidence?: number;
    userId?: string;
    metadata?: Record<string, unknown>;
}
/**
 * Bias sample storage interface
 */
export interface BiasSampleStorage {
    save(sample: BiasSample): Promise<void>;
    getSamples(modelId: string, startDate: Date, endDate: Date, limit?: number): Promise<BiasSample[]>;
    getSamplesByAttribute(modelId: string, attribute: string, value: string, startDate: Date, endDate: Date): Promise<BiasSample[]>;
    deleteOlderThan(date: Date): Promise<number>;
}
/**
 * In-memory bias sample storage
 */
export declare class InMemoryBiasSampleStorage implements BiasSampleStorage {
    private samples;
    save(sample: BiasSample): Promise<void>;
    getSamples(modelId: string, startDate: Date, endDate: Date, limit?: number): Promise<BiasSample[]>;
    getSamplesByAttribute(modelId: string, attribute: string, value: string, startDate: Date, endDate: Date): Promise<BiasSample[]>;
    deleteOlderThan(date: Date): Promise<number>;
}
/**
 * Bias alert storage interface
 */
export interface BiasAlertStorage {
    save(alert: BiasAlert): Promise<void>;
    get(alertId: string): Promise<BiasAlert | null>;
    getUnacknowledged(modelId?: string): Promise<BiasAlert[]>;
    acknowledge(alertId: string): Promise<void>;
    resolve(alertId: string, resolution: string): Promise<void>;
    list(modelId?: string, limit?: number): Promise<BiasAlert[]>;
}
/**
 * In-memory bias alert storage
 */
export declare class InMemoryBiasAlertStorage implements BiasAlertStorage {
    private alerts;
    save(alert: BiasAlert): Promise<void>;
    get(alertId: string): Promise<BiasAlert | null>;
    getUnacknowledged(modelId?: string): Promise<BiasAlert[]>;
    acknowledge(alertId: string): Promise<void>;
    resolve(alertId: string, resolution: string): Promise<void>;
    list(modelId?: string, limit?: number): Promise<BiasAlert[]>;
}
/**
 * Bias Detection System
 * Monitors and analyzes AI model outputs for bias
 */
export declare class BiasDetector extends EventEmitter {
    private config;
    private sampleStorage;
    private alertStorage;
    private analysisCache;
    constructor(config?: Partial<BiasDetectionConfig>, sampleStorage?: BiasSampleStorage, alertStorage?: BiasAlertStorage);
    /**
     * Record a sample for bias analysis
     */
    recordSample(sample: Omit<BiasSample, 'id'>): Promise<BiasSample>;
    /**
     * Perform bias analysis for a model
     */
    analyzeModel(modelId: string, period: {
        start: Date;
        end: Date;
    }): Promise<BiasDetectionResult>;
    /**
     * Calculate demographic parity metric
     */
    private calculateDemographicParity;
    /**
     * Calculate equal opportunity metric
     */
    private calculateEqualOpportunity;
    /**
     * Calculate response consistency metric
     */
    private calculateResponseConsistency;
    /**
     * Calculate representation gap metric
     */
    private calculateRepresentationGap;
    /**
     * Group samples by attribute value
     */
    private groupSamplesByAttribute;
    /**
     * Calculate variation in responses (0 = identical, 1 = completely different)
     */
    private calculateResponseVariation;
    /**
     * Calculate cross-group similarity (0 = different, 1 = similar)
     */
    private calculateCrossGroupSimilarity;
    /**
     * Generate alerts based on metrics
     */
    private generateAlerts;
    /**
     * Get alert severity based on score vs threshold
     */
    private getSeverity;
    /**
     * Calculate overall bias score
     */
    private calculateOverallScore;
    /**
     * Generate recommendations based on bias analysis
     */
    private generateRecommendations;
    /**
     * Check for bias in realtime
     */
    private checkForBiasRealtime;
    /**
     * Create result for disabled analysis
     */
    private createDisabledResult;
    /**
     * Create result for insufficient data
     */
    private createInsufficientDataResult;
    /**
     * Get alerts for a model
     */
    getAlerts(modelId?: string, limit?: number): Promise<BiasAlert[]>;
    /**
     * Get unacknowledged alerts
     */
    getUnacknowledgedAlerts(modelId?: string): Promise<BiasAlert[]>;
    /**
     * Acknowledge an alert
     */
    acknowledgeAlert(alertId: string): Promise<void>;
    /**
     * Resolve an alert
     */
    resolveAlert(alertId: string, resolution: string): Promise<void>;
    /**
     * Clean up old samples
     */
    cleanup(): Promise<number>;
    /**
     * Update configuration
     */
    updateConfig(updates: Partial<BiasDetectionConfig>): void;
    /**
     * Get current configuration
     */
    getConfig(): BiasDetectionConfig;
    /**
     * Get cached analysis result
     */
    getCachedAnalysis(modelId: string, period: {
        start: Date;
        end: Date;
    }): BiasDetectionResult | null;
    /**
     * Add a custom metric
     */
    addCustomMetric(metric: CustomMetricDefinition): void;
    /**
     * Remove a custom metric
     */
    removeCustomMetric(metricId: string): boolean;
}
export default BiasDetector;
//# sourceMappingURL=bias-detection.d.ts.map