Skip to main content

MELBA 0.2.0

MELBA (Mathematical Economics Learning-Based Algorithm) is a Python library for business-data regression and formula-based economic mathematics. Version 0.2.0 combines the original Regression Engine with a separate Economic Mathematics Engine.

This source tree prepares version 0.2.0. Until that version is published, installing from PyPI will still install the latest published version.

Features

Regression Engine

  • Familiar estimator API: MELBA.fit(X, y), predict(X), and evaluate(X, y).
  • Numeric NumPy arrays and Pandas DataFrame/Series inputs.
  • Standardized features, optional quadratic and pairwise feature expansion, Huber loss, L2 regularization, and full-batch gradient descent.
  • Evaluation metrics: MAE, MSE, RMSE, and R-squared.
  • Reproducible initialization through random_state.

The model uses established regression techniques. MELBA makes no claim of algorithmic novelty or scientific superiority.

Economic Mathematics Engine

Import functions from melba.economics:

  • DemandFunction and SupplyFunction for linear demand and supply.
  • CostFunction, RevenueFunction, and ProfitFunction for total cost, revenue, and profit.
  • PolynomialFunction and analytical derivatives for marginal cost, marginal revenue, and marginal profit.
  • Bounded profit optimization that checks stationary candidates and interval boundaries.
  • Point price elasticity with elastic, inelastic, or unitary elastic interpretation.

The economic functions use parameters supplied by the caller. They are separate from the regression optimizer and do not infer causal relationships.

Installation

After MELBA 0.2.0 is published to PyPI:

python -m pip install --upgrade melba

To install this source checkout before publication:

python -m pip install .

Matplotlib is optional and only needed for plotting in the notebook. For tests and plotting:

python -m pip install ".[plot,test]"

Quick Start

The example below uses synthetic demonstration values. It trains a regression model, predicts sales, and passes the prediction into the economic functions.

import numpy as np
from melba import MELBA
from melba.economics import (
    CostFunction,
    DemandFunction,
    Elasticity,
    ProfitFunction,
    RevenueFunction,
    SupplyFunction,
)

# Synthetic demonstration data: promotion budget in thousands -> units sold.
X_train = np.array([[0], [10], [20], [30], [40], [50]], dtype=float)
y_train = np.array([50, 70, 90, 110, 130, 150], dtype=float)

model = MELBA(
    quadratic_terms=False,
    epochs=1000,
    random_state=42,
    l2_penalty=0.0,
)
model.fit(X_train, y_train)

predicted_sales = float(model.predict([[25]])[0])
evaluation = model.evaluate(X_train, y_train)

if predicted_sales < 0:
    raise ValueError("Predicted sales are outside the non-negative quantity domain.")

# Illustrative currency values per product unit.
price_per_unit = 10_000.0
revenue = RevenueFunction().calculate(price_per_unit, predicted_sales)
total_cost = CostFunction(
    fixed_cost=100_000.0,
    variable_cost=6_000.0,
).calculate(predicted_sales)
profit = ProfitFunction().calculate(revenue, total_cost)

# Separate illustrative supply and demand curves.
demand = DemandFunction(a=1_000.0, b=0.05)
supply = SupplyFunction(c=20.0, d=0.02)
demand_quantity = demand.calculate(price_per_unit)
supply_quantity = supply.calculate(price_per_unit)
elasticity = Elasticity.price_demand(demand, price=price_per_unit)

print("Predicted sales:", predicted_sales)
print("Evaluation:", evaluation)
print("Revenue / cost / profit:", revenue, total_cost, profit)
print("Demand / supply:", demand_quantity, supply_quantity)
print("Price elasticity:", elasticity.elasticity, elasticity.category)

All data and currency values are synthetic and illustrative; they are not company observations or evidence of real-world accuracy. The demand and supply curves are separate from the fitted regression. Predictions are not constrained to non-negative values, so check the quantity domain before using predictions in economic calculations.

Main Formulas

For price P and quantity Q, the linear functions use:

  • Demand: Qd(P) = a - bP
  • Supply: Qs(P) = c + dP
  • Total cost: TC(Q) = FC + vQ
  • Total revenue: TR(P, Q) = P × Q
  • Profit: π(Q) = TR(Q) - TC(Q)
  • Marginal values: MC(Q) = TC′(Q), MR(Q) = TR′(Q), and MP(Q) = π′(Q)
  • Point price elasticity: E(P) = (dQ/dP) × (P/Q)

For polynomial cost, revenue, or profit functions, MELBA calculates derivatives analytically. Profit optimization searches a finite quantity interval, evaluates real stationary points in that interval, and compares them with both endpoints. A zero first derivative alone is not treated as proof of a maximum.

The regression objective uses Huber loss on standardized targets with an L2 penalty on non-intercept coefficients. See the algorithm guide and Economic Mathematics guide for assumptions and details.

Google Colab

Open the self-contained synthetic walkthrough in Google Colab. The notebook bundles a source snapshot so its regression and economics examples can run without a local repository checkout. Notebook results describe only the generated demonstration data.

Examples and Tests

Run examples from a source checkout:

python examples/basic_usage.py
python examples/business_sales.py
python examples/economic_functions.py

Run the unit test suite:

python -m pytest

Limitations

  • Inputs must be finite numeric data; MELBA does not encode categories or impute missing values.
  • The default quadratic feature expansion creates O(p²) terms for p input columns, so large feature sets can require substantial memory and computation.
  • Evaluation scores describe only the supplied sample. Use a held-out dataset to assess predictive performance.
  • The estimator does not provide causal estimates, time-series handling, feature selection, uncertainty intervals, or non-negative prediction constraints.
  • Economic parameters and units are supplied by the caller. The cost function is linear unless a polynomial is provided.
  • Profit optimization is bounded by the finite interval passed to the function; it does not claim an optimum outside those bounds.
  • Elasticity describes the supplied mathematical demand function and does not establish a causal price effect.

MELBA is an inspectable learning and calculation tool, not a validated domain model for making business decisions. See the framework guide, algorithm guide, and Economic Mathematics guide.

Metadata

Release files for melba 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for melba 0.2.0
File Size Uploaded Provenance Actions
melba-0.2.0.tar.gz 41.1 kB Without provenance Details for melba-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for melba 0.2.0
File Interpreter ABI Platform Actions
melba-0.2.0-py3-none-any.whl Python 3 none any Details for melba-0.2.0-py3-none-any.whl

Total release size: 61.5 kB

Release files / melba-0.2.0.tar.gz

Download URL melba-0.2.0.tar.gz
Size 41.1 kB
Tags Source
SHA-256 checksum
How to use checksums
06e152dcfaeb995ed17c7296d356aa5f789a3f33d3d1a66142f17d4ab96528bb
BLAKE2b-256 checksum
How to use checksums
b7b2e7da3fe13724b67a23b48de128d7da273823fc5e06e6734fe61bdad4aca2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / melba-0.2.0-py3-none-any.whl

Download URL melba-0.2.0-py3-none-any.whl
Size 20.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f8baeec21c92dc7e6593fcf7c3adab3cb60f07af198ca6d74d9525b756784d1
BLAKE2b-256 checksum
How to use checksums
ce2d2906fbd3d653fd5d59f1cd747d562fb0e8785afae5ba3d6b706e0571ca2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for melba 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page