> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fincept.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Calculate Cross Entropy

> Calculates the cross entropy between two probability distributions P and Q, measuring the average number of bits needed to identify an event from P when using a coding scheme optimized for Q. Cross entropy is fundamental in machine learning loss functions and information theory.

**Use Cases:**
- Evaluate prediction model performance
- Optimize classification models for trading signals
- Compare forecast accuracy
- Information-theoretic model selection
- Assess encoding efficiency

**Formula:** H(P,Q) = -Σ p(x) log(q(x))

**Note:** Cross entropy = Shannon entropy + KL divergence

**Credits:** 5 credits per request (Pro Tier) [Tier: ENTERPRISE, Credits: 10]



## OpenAPI

````yaml api-specs/physics.json post /quantlib/physics/entropy/cross
openapi: 3.1.0
info:
  title: FinceptQuantLib API - Physics Module
  description: >-
    Physics and Information Theory module for FinceptQuantLib API. Includes
    Shannon/Renyi/Tsallis entropy, KL/JS divergence, mutual information,
    transfer entropy, Fisher information, Boltzmann distribution, Ising model,
    maximum entropy, thermodynamics (free energy, Carnot cycle, van der Waals
    equation), and Maxwell relations. **Pro Tier required. 5 credits per
    request.**
  version: 3.0.0
  contact:
    name: Fincept API Support
    url: https://fincept.in
servers:
  - url: https://api.fincept.in
    description: Fincept API Production Server
security:
  - APIKeyHeader: []
tags:
  - name: quantlib-physics
    description: Physics and Information Theory module for FinceptQuantLib API
    x-displayName: Physics
paths:
  /quantlib/physics/entropy/cross:
    post:
      tags:
        - quantlib-physics
      summary: Calculate Cross Entropy
      description: >-
        Calculates the cross entropy between two probability distributions P and
        Q, measuring the average number of bits needed to identify an event from
        P when using a coding scheme optimized for Q. Cross entropy is
        fundamental in machine learning loss functions and information theory.


        **Use Cases:**

        - Evaluate prediction model performance

        - Optimize classification models for trading signals

        - Compare forecast accuracy

        - Information-theoretic model selection

        - Assess encoding efficiency


        **Formula:** H(P,Q) = -Σ p(x) log(q(x))


        **Note:** Cross entropy = Shannon entropy + KL divergence


        **Credits:** 5 credits per request (Pro Tier) [Tier: ENTERPRISE,
        Credits: 10]
      operationId: cross_entropy
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - p
                - q
              properties:
                p:
                  type: array
                  items:
                    type: number
                  description: True probability distribution (must sum to 1)
                  example:
                    - 0.4
                    - 0.3
                    - 0.2
                    - 0.1
                q:
                  type: array
                  items:
                    type: number
                  description: Predicted/estimated probability distribution (must sum to 1)
                  example:
                    - 0.35
                    - 0.35
                    - 0.2
                    - 0.1
                base:
                  type: number
                  description: Logarithm base for entropy calculation
                  default: 2.718281828459045
                  example: 2.718281828459045
            examples:
              model_evaluation:
                summary: Evaluate model predictions
                value:
                  p:
                    - 0
                    - 1
                    - 0
                    - 0
                  q:
                    - 0.1
                    - 0.7
                    - 0.15
                    - 0.05
                  base: 2.718281828459045
              forecast_accuracy:
                summary: Compare forecast to actual
                value:
                  p:
                    - 0.5
                    - 0.3
                    - 0.15
                    - 0.05
                  q:
                    - 0.45
                    - 0.35
                    - 0.15
                    - 0.05
                  base: 2
      responses:
        '200':
          description: Cross entropy calculated successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      cross_entropy:
                        type: number
                        description: >-
                          Cross entropy value (minimum equals Shannon entropy of
                          P)
                        example: 1.3254
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '402':
          $ref: '#/components/responses/InsufficientCreditsError'
        '422':
          $ref: '#/components/responses/ValidationError'
components:
  responses:
    UnauthorizedError:
      description: Authentication information is missing or invalid
      content:
        application/json:
          schema:
            type: object
            properties:
              detail:
                type: string
                example: Invalid API key
    InsufficientCreditsError:
      description: Insufficient API credits
      content:
        application/json:
          schema:
            type: object
            properties:
              detail:
                type: string
                example: Insufficient credits. This endpoint requires 5 credits.
    ValidationError:
      description: Request validation error
      content:
        application/json:
          schema:
            type: object
            properties:
              detail:
                type: array
                items:
                  type: object
                  properties:
                    loc:
                      type: array
                      items:
                        type: string
                    msg:
                      type: string
                    type:
                      type: string
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: X-API-Key
      description: >-
        API key for authentication. Get your key at
        https://api.fincept.in/auth/register

````