# Astermind Premium

**Premium Machine Learning Toolkit** - Advanced Extreme Learning Machine (ELM) variants and enterprise features built on top of Astermind Pro and Astermind Elm.

[![npm version](https://img.shields.io/npm/v/@astermind/astermind-premium.svg)](https://www.npmjs.com/package/@astermind/astermind-premium)
[![License](https://img.shields.io/badge/license-Proprietary-red.svg)](LICENSE)

## Overview

Astermind Premium extends [Astermind Pro](https://www.npmjs.com/package/@astermind/astermind-pro) and [Astermind Elm](https://www.npmjs.com/package/@astermind/astermind-elm) with **21 advanced ELM variants** designed for enterprise use cases. Premium includes all features from Pro (RAG, Reranking, Summarization, Information Flow Analysis) plus specialized ELM architectures for:

- **Online/Streaming Learning**: Adaptive and Forgetting Online ELM
- **Hierarchical Classification**: Multi-level decision trees
- **Attention Mechanisms**: Attention-Enhanced ELM
- **Uncertainty Quantification**: Variational ELM
- **Time-Series Analysis**: Time-Series ELM
- **Transfer Learning**: Pre-trained model adaptation
- **Graph Neural Networks**: Graph ELM and Graph Kernel ELM
- **Kernel Methods**: 8 specialized kernel ELM variants
- **Deep Architectures**: Deep Kernel ELM
- **Convolutional & Recurrent**: CNN and RNN-style ELM
- **Fuzzy Logic**: Fuzzy ELM
- **Quantum-Inspired**: Quantum-Inspired ELM
- **Tensor Operations**: Tensor Kernel ELM

## Installation

```bash
npm install @astermind/astermind-premium
```

### Peer Dependencies

Astermind Premium requires:
- `@astermind/astermind-pro` (automatically installed as a dependency)
- `@astermind/astermind-elm` (included via Pro)

## License Setup

Astermind Premium requires a valid license token to use premium features.

### Getting Your License Key

To get started with Astermind Premium, visit our getting started page:

**👉 [Get Your License Key →](https://www.astermind.ai/getting-started)**

The getting started page provides step-by-step instructions for:
- Creating a free trial account
- Obtaining your license token
- Setting up your development environment

### Setting Your License

**Option 1: Environment Variable (Recommended)**
```bash
export ASTERMIND_LICENSE_TOKEN="your-license-token-here"
```

**Option 2: Programmatic Setup**
```javascript
import { setLicenseTokenFromString, initializeLicense } from '@astermind/astermind-premium';

// Initialize license system
initializeLicense();

// Set your license token
await setLicenseTokenFromString('your-license-token-here');
```

**Option 3: Configuration File**
```javascript
// src/config/license-config.ts
export const LICENSE_TOKEN = 'your-license-token-here';
```

### License Validation

Premium requires a valid license token. Invalid or expired tokens will be rejected.

## Quick Start

```javascript
import { 
  AdaptiveOnlineELM,
  HierarchicalELM,
  VariationalELM,
  initializeLicense,
  setLicenseTokenFromString
} from '@astermind/astermind-premium';

// Initialize license
await initializeLicense();
await setLicenseTokenFromString(process.env.ASTERMIND_LICENSE_TOKEN);

// Use Adaptive Online ELM for streaming data
const model = new AdaptiveOnlineELM({
  categories: ['positive', 'negative', 'neutral'],
  initialHiddenUnits: 64
});

// Train on batch data
const X = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
const y = [0, 1, 0];
model.fit(X, y);

// Predict
const predictions = model.predict([1, 2, 3], 3);
console.log(predictions);
```

## Premium ELM Variants

### 1. Adaptive Online ELM
Dynamically adjusts hidden layer size based on performance.

```javascript
import { AdaptiveOnlineELM } from '@astermind/astermind-premium';

const model = new AdaptiveOnlineELM({
  categories: ['class1', 'class2'],
  initialHiddenUnits: 64,
  minHiddenUnits: 32,
  maxHiddenUnits: 256
});

// Batch training
model.fit(X, y);

// Online updates
model.update(newSample, newLabel);
```

### 2. Forgetting Online ELM
Online learning with exponential forgetting of old data.

```javascript
import { ForgettingOnlineELM } from '@astermind/astermind-premium';

const model = new ForgettingOnlineELM({
  categories: ['class1', 'class2'],
  forgettingFactor: 0.95 // Higher = forgets slower
});

model.fit(X, y);
model.update(newSample, newLabel);
```

### 3. Hierarchical ELM
Multi-level classification with hierarchical structure.

```javascript
import { HierarchicalELM } from '@astermind/astermind-premium';

const model = new HierarchicalELM({
  hierarchy: {
    'root': ['animal', 'plant'],
    'animal': ['mammal', 'bird'],
    'mammal': ['dog', 'cat']
  },
  rootCategories: ['root']
});

model.train(X, y.map(label => getHierarchicalPath(label)));
const predictions = model.predict(sample, 3);
// Returns: [{ path: ['root', 'animal', 'mammal', 'dog'], prob: 0.95 }]
```

### 4. Attention-Enhanced ELM
Uses attention mechanisms to focus on important features.

```javascript
import { AttentionEnhancedELM } from '@astermind/astermind-premium';

const model = new AttentionEnhancedELM({
  categories: ['class1', 'class2'],
  attentionUnits: 128
});

model.train(X, y);
const predictions = model.predict(sample, 3);
```

### 5. Variational ELM
Provides uncertainty estimates with predictions.

```javascript
import { VariationalELM } from '@astermind/astermind-premium';

const model = new VariationalELM({
  categories: ['class1', 'class2']
});

model.train(X, y);
const predictions = model.predict(sample, 3, true); // Include uncertainty
// Returns: [{ label: 'class1', prob: 0.9, uncertainty: 0.05, confidence: 0.95 }]
```

### 6. Time-Series ELM
Specialized for sequential/time-series data.

```javascript
import { TimeSeriesELM } from '@astermind/astermind-premium';

const model = new TimeSeriesELM({
  categories: ['trend_up', 'trend_down', 'stable'],
  sequenceLength: 10
});

// Sequences: number[][][] - array of sequences, each sequence is number[][]
const sequences = [
  [[1, 2], [2, 3], [3, 4]], // Sequence 1
  [[5, 6], [6, 7], [7, 8]]  // Sequence 2
];
const labels = [0, 1];

model.train(sequences, labels);
const prediction = model.predict(sequences[0], 3);
```

### 7. Transfer Learning ELM
Adapts pre-trained models to new tasks.

```javascript
import { TransferLearningELM } from '@astermind/astermind-premium';

const model = new TransferLearningELM({
  categories: ['new_class1', 'new_class2'],
  transferRate: 0.3 // How much to adapt from source
});

model.train(X, y);
```

### 8. Graph ELM
Processes graph-structured data.

```javascript
import { GraphELM } from '@astermind/astermind-premium';

const model = new GraphELM({
  categories: ['type1', 'type2']
});

const graphs = [
  {
    nodes: [
      { id: 'n1', features: [1, 2, 3] },
      { id: 'n2', features: [4, 5, 6] }
    ],
    edges: [
      { source: 'n1', target: 'n2' }
    ]
  }
];
const labels = [0];

model.train(graphs, labels);
const prediction = model.predict(graphs[0], 3);
```

### 9. Adaptive Kernel ELM
Automatically selects optimal kernel parameters.

```javascript
import { AdaptiveKernelELM } from '@astermind/astermind-premium';

const model = new AdaptiveKernelELM({
  categories: ['class1', 'class2'],
  kernelType: 'rbf' // 'rbf', 'polynomial', 'sigmoid'
});

model.train(X, y);
```

### 10. Sparse Kernel ELM
Efficient kernel ELM using landmark points.

```javascript
import { SparseKernelELM } from '@astermind/astermind-premium';

const model = new SparseKernelELM({
  categories: ['class1', 'class2'],
  numLandmarks: 50 // Number of landmark points
});

model.train(X, y);
```

### 11. Ensemble Kernel ELM
Combines multiple kernel ELMs for robust predictions.

```javascript
import { EnsembleKernelELM } from '@astermind/astermind-premium';

const model = new EnsembleKernelELM({
  categories: ['class1', 'class2'],
  numModels: 5 // Number of ensemble members
});

model.train(X, y);
const predictions = model.predict(sample, 3);
// Returns: [{ label: 'class1', prob: 0.9, votes: 4 }] // votes = ensemble agreement
```

### 12. Deep Kernel ELM
Multi-layer kernel transformations.

```javascript
import { DeepKernelELM } from '@astermind/astermind-premium';

const model = new DeepKernelELM({
  categories: ['class1', 'class2'],
  numLayers: 3
});

model.train(X, y);
```

### 13. Robust Kernel ELM
Handles outliers and noisy data.

```javascript
import { RobustKernelELM } from '@astermind/astermind-premium';

const model = new RobustKernelELM({
  categories: ['class1', 'class2'],
  outlierThreshold: 0.1
});

model.train(X, y);
const predictions = model.predict(sample, 3);
// Returns: [{ label: 'class1', prob: 0.9, isOutlier: false }]
```

### 14. ELM-KELM Cascade
Cascades standard ELM with Kernel ELM.

```javascript
import { ELMKELMCascade } from '@astermind/astermind-premium';

const model = new ELMKELMCascade({
  categories: ['class1', 'class2']
});

model.train(X, y);
```

### 15. String Kernel ELM
Processes string/text data using string kernels.

```javascript
import { StringKernelELM } from '@astermind/astermind-premium';

const model = new StringKernelELM({
  categories: ['positive', 'negative']
});

const strings = ['hello world', 'good morning', 'bad day'];
const labels = [0, 0, 1];

model.train(strings, labels);
const prediction = model.predict(['hello'], 3);
```

### 16. Convolutional ELM
Image-like data processing with convolutional features.

```javascript
import { ConvolutionalELM } from '@astermind/astermind-premium';

const model = new ConvolutionalELM({
  categories: ['cat', 'dog'],
  filterSize: 3,
  numFilters: 16
});

// Images: number[][][] - array of 2D images
const images = [
  [[1, 2, 3], [4, 5, 6], [7, 8, 9]], // Image 1
  [[9, 8, 7], [6, 5, 4], [3, 2, 1]]  // Image 2
];
const labels = [0, 1];

model.train(images, labels);
const prediction = model.predict(images[0], 3);
```

### 17. Recurrent ELM
Sequential data with hidden state memory.

```javascript
import { RecurrentELM } from '@astermind/astermind-premium';

const model = new RecurrentELM({
  categories: ['class1', 'class2'],
  hiddenSize: 64
});

const sequences = [
  [[1, 2], [2, 3], [3, 4]], // Sequence 1
  [[5, 6], [6, 7], [7, 8]]  // Sequence 2
];
const labels = [0, 1];

model.train(sequences, labels);
const predictions = model.predict(sequences[0], 3);
// Returns: [{ label: 'class1', prob: 0.9, hiddenState: [...] }]
```

### 18. Fuzzy ELM
Fuzzy logic-based classification with membership functions.

```javascript
import { FuzzyELM } from '@astermind/astermind-premium';

const model = new FuzzyELM({
  categories: ['low', 'medium', 'high']
});

model.train(X, y);
const predictions = model.predict(sample, 3);
// Returns: [{ label: 'medium', prob: 0.8, membership: 0.85, confidence: 0.9 }]
```

### 19. Quantum-Inspired ELM
Uses quantum computing principles for feature transformation.

```javascript
import { QuantumInspiredELM } from '@astermind/astermind-premium';

const model = new QuantumInspiredELM({
  categories: ['class1', 'class2'],
  numQubits: 8
});

model.train(X, y);
const predictions = model.predict(sample, 3);
// Returns: [{ label: 'class1', prob: 0.9, quantumState: [...], amplitude: 0.95 }]
```

### 20. Graph Kernel ELM
Graph-structured data using graph kernels.

```javascript
import { GraphKernelELM } from '@astermind/astermind-premium';

const model = new GraphKernelELM({
  categories: ['type1', 'type2']
});

const graphs = [
  {
    nodes: [{ id: 'n1', features: [1, 2] }],
    edges: [{ source: 'n1', target: 'n2' }]
  }
];
const labels = [0];

model.train(graphs, labels);
```

### 21. Tensor Kernel ELM
3D tensor data processing.

```javascript
import { TensorKernelELM } from '@astermind/astermind-premium';

const model = new TensorKernelELM({
  categories: ['class1', 'class2']
});

// Tensors: number[][][] - array of 3D tensors
const tensors = [
  [
    [[1, 2], [3, 4]], // Channel 1
    [[5, 6], [7, 8]]  // Channel 2
  ]
];
const labels = [0];

model.train(tensors, labels);
const prediction = model.predict(tensors[0], 3);
```

## API Reference

### License Management

#### `initializeLicense(): void`
Initializes the license runtime. Called automatically on first use.

#### `setLicenseTokenFromString(token: string): Promise<void>`
Sets the license token from a string. Validates the token.

#### `requireLicense(): void`
Throws an error if no valid license is available. Called automatically by all Premium ELM variants.

#### `checkLicense(): boolean`
Returns `true` if a valid license is available, `false` otherwise.

#### `getLicenseStatus(): LicenseState`
Returns detailed license status information.

### Common ELM Interface

All Premium ELM variants follow a similar interface:

```typescript
interface ELMConfig {
  categories: string[];
  // ... variant-specific options
}

class PremiumELM {
  constructor(config: ELMConfig);
  train(X: any[], y: number[]): void;
  predict(sample: any, topK?: number): Prediction[];
}
```

## Integration with Astermind Pro

Premium includes all features from [Astermind Pro](https://www.npmjs.com/package/@astermind/astermind-pro):

- **RAG (Retrieval-Augmented Generation)**
- **Reranking**
- **Summarization**
- **Information Flow Analysis**
- **All Pro ELM variants**

```javascript
import { 
  RAGPipeline,
  Reranker,
  Summarizer,
  AdaptiveOnlineELM // Premium variant
} from '@astermind/astermind-premium';
```

## Related Packages

- **[Astermind Pro](https://www.npmjs.com/package/@astermind/astermind-pro)** - Advanced ML toolkit with RAG, reranking, and more
- **[Astermind Elm](https://www.npmjs.com/package/@astermind/astermind-elm)** - Core Extreme Learning Machine library
- **[Astermind Synthetic Data](https://www.npmjs.com/package/@astermind/astermind-synthetic-data)** - Synthetic data generation

## License

Proprietary - Requires valid license token from [license.astermind.ai](https://license.astermind.ai)

## Support

- **Documentation**: [docs.astermind.ai](https://docs.astermind.ai)
- **Issues**: [GitHub Issues](https://github.com/astermindai/astermind-premium/issues)
- **Email**: support@astermind.ai
- **Website**: [astermind.ai](https://astermind.ai)

## Changelog

### 1.0.0
- Initial release
- 21 Premium ELM variants
- License validation
- Full integration with Astermind Pro
- Comprehensive test suite

---

**Built with ❤️ by [AsterMind AI](https://astermind.ai)**
