@dniskav/neuron 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -1
- package/dist/index.d.mts +118 -1
- package/dist/index.d.ts +118 -1
- package/dist/index.js +755 -0
- package/dist/index.mjs +749 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
A minimal, dependency-free neural network library built from scratch in TypeScript. Designed for learning and experimentation — every line of math is readable.
|
|
5
5
|
|
|
6
|
-
Each class is a building block for the next: from a single neuron to a full Transformer with causal attention.
|
|
6
|
+
Each class is a building block for the next: from a single neuron to a full Transformer with causal attention. Includes classical ML, unsupervised learning, generative models, embeddings, and autograd — all in pure TypeScript, zero dependencies.
|
|
7
7
|
|
|
8
8
|
```mermaid
|
|
9
9
|
graph TD
|
|
@@ -126,6 +126,17 @@ graph TD
|
|
|
126
126
|
|--------|-------------|
|
|
127
127
|
| `Value` | Scalar autograd node. Builds a computational graph and propagates gradients with `.backward()`. Inspired by micrograd. |
|
|
128
128
|
|
|
129
|
+
### Embeddings
|
|
130
|
+
|
|
131
|
+
| Export | Description |
|
|
132
|
+
|--------|-------------|
|
|
133
|
+
| `Word2Vec` | Learns word embeddings via Skip-gram or CBOW. Full-softmax, cosine similarity, analogies (`king - man + woman ≈ queen`). |
|
|
134
|
+
| `TSNE` | t-SNE dimensionality reduction. Binary-search perplexity, Student-t kernel, KL gradient, early exaggeration. |
|
|
135
|
+
| `PositionalEncoding` | Sinusoidal positional encoding (Vaswani et al.). Static — no parameters, generalizes to unseen lengths. |
|
|
136
|
+
| `LearnedPositionalEncoding` | Trainable positional encoding. Xavier-initialized, learnable up to a fixed `maxSeqLen`. |
|
|
137
|
+
| `ContrastiveLearning` | SimCLR-style self-supervised learning. NT-Xent loss, encoder + projection head, temperature τ. |
|
|
138
|
+
| `Augmenter` | Data augmentation helpers for contrastive pairs: Gaussian noise, feature dropout, `makePair()`. |
|
|
139
|
+
|
|
129
140
|
### Activations & math
|
|
130
141
|
|
|
131
142
|
| Export | Description |
|
|
@@ -396,6 +407,79 @@ const { mu, logVar } = vae.encode(image); // encode → distribution params
|
|
|
396
407
|
const z = vae.reparametrize(mu, logVar); // sample z ~ N(μ, σ²)
|
|
397
408
|
```
|
|
398
409
|
|
|
410
|
+
### Word2Vec — aprende embeddings de palabras
|
|
411
|
+
|
|
412
|
+
```ts
|
|
413
|
+
import { Word2Vec } from "@dniskav/neuron";
|
|
414
|
+
|
|
415
|
+
const w2v = new Word2Vec(64, { model: 'skipgram', windowSize: 2 });
|
|
416
|
+
|
|
417
|
+
const corpus = [
|
|
418
|
+
["the", "king", "rules", "the", "kingdom"],
|
|
419
|
+
["the", "queen", "rules", "the", "land"],
|
|
420
|
+
["man", "and", "woman", "are", "human"],
|
|
421
|
+
];
|
|
422
|
+
|
|
423
|
+
w2v.buildVocab(corpus);
|
|
424
|
+
w2v.train(corpus, 0.05, 200);
|
|
425
|
+
|
|
426
|
+
console.log(w2v.similarity("king", "queen")); // high
|
|
427
|
+
console.log(w2v.mostSimilar("king", 3));
|
|
428
|
+
// [{ word: 'queen', score: 0.91 }, ...]
|
|
429
|
+
|
|
430
|
+
// Vector arithmetic: king - man + woman ≈ queen
|
|
431
|
+
console.log(w2v.analogy("king", "man", "woman", 1));
|
|
432
|
+
// [{ word: 'queen', score: 0.87 }]
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
### t-SNE — visualiza embeddings en 2D
|
|
436
|
+
|
|
437
|
+
```ts
|
|
438
|
+
import { TSNE } from "@dniskav/neuron";
|
|
439
|
+
|
|
440
|
+
// Reduce 128-dim embeddings → 2D for plotting
|
|
441
|
+
const tsne = new TSNE({ perplexity: 30, nIter: 1000, seed: 42 });
|
|
442
|
+
const points2D = tsne.fitTransform(embeddings128D); // [n][2]
|
|
443
|
+
|
|
444
|
+
console.log(tsne.kl()); // KL divergence — lower is better
|
|
445
|
+
// Plot points2D with any charting library
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### PositionalEncoding — orden sin parámetros
|
|
449
|
+
|
|
450
|
+
```ts
|
|
451
|
+
import { PositionalEncoding, LearnedPositionalEncoding } from "@dniskav/neuron";
|
|
452
|
+
|
|
453
|
+
// Sinusoidal — deterministic, no training needed
|
|
454
|
+
const pe = PositionalEncoding.encodeSequence(512, 128); // [512][128]
|
|
455
|
+
const withPos = PositionalEncoding.apply(tokenEmbeddings); // add PE to embeddings
|
|
456
|
+
|
|
457
|
+
// Learned — trainable, fixed maxSeqLen
|
|
458
|
+
const lpe = new LearnedPositionalEncoding(512, 128);
|
|
459
|
+
const withLearnedPos = lpe.apply(tokenEmbeddings);
|
|
460
|
+
lpe.update(gradients, 0.001); // update during backprop
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
### ContrastiveLearning — representaciones sin etiquetas
|
|
464
|
+
|
|
465
|
+
```ts
|
|
466
|
+
import { ContrastiveLearning, Augmenter } from "@dniskav/neuron";
|
|
467
|
+
|
|
468
|
+
// Encoder: 128 → [256, 128] → 64 latent, projection head: 64 → 32
|
|
469
|
+
const cl = new ContrastiveLearning(128, [256, 128], 64, { temperature: 0.5 });
|
|
470
|
+
|
|
471
|
+
// Create positive pairs from unlabeled data (two augmented views per sample)
|
|
472
|
+
const pairs = unlabeledData.map(x => Augmenter.makePair(x));
|
|
473
|
+
|
|
474
|
+
for (let step = 0; step < 1000; step++) {
|
|
475
|
+
const loss = cl.trainStep(pairs, 0.001);
|
|
476
|
+
if (step % 100 === 0) console.log(`step ${step}: ${loss.toFixed(4)}`);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// Use encoder for downstream tasks (classification, clustering, etc.)
|
|
480
|
+
const representation = cl.encode(newSample); // 64-dim vector
|
|
481
|
+
```
|
|
482
|
+
|
|
399
483
|
### Value / Tape — automatic differentiation
|
|
400
484
|
|
|
401
485
|
```ts
|
|
@@ -596,6 +680,9 @@ If you are an AI agent or LLM working with this codebase, read [AGENTS.md](AGENT
|
|
|
596
680
|
|
|
597
681
|
## Changelog
|
|
598
682
|
|
|
683
|
+
### v0.3.1
|
|
684
|
+
- **New — Embeddings:** `Word2Vec` (Skip-gram + CBOW, full-softmax, cosine similarity, analogies), `TSNE` (binary-search perplexity, Student-t kernel, KL gradient, early exaggeration, seeded PRNG), `PositionalEncoding` (sinusoidal, Vaswani et al.), `LearnedPositionalEncoding` (trainable), `ContrastiveLearning` (NT-Xent, SimCLR encoder + projection head), `Augmenter` (noise, feature dropout, `makePair`)
|
|
685
|
+
|
|
599
686
|
### v0.3.0
|
|
600
687
|
- **New — Classical ML:** `Perceptron`, `LinearRegression` (normal equation + GD), `LogisticRegression`, `SoftmaxRegression`, `GaussianNaiveBayes`, `DecisionTree` (CART, Gini/MSE)
|
|
601
688
|
- **New — Unsupervised:** `KMeans` (K-Means++ init), `PCA` (power iteration + Hotelling deflation), `SOM` (Kohonen map), `HopfieldNetwork` (Hebbian storage + energy), `Autoencoder`
|
package/dist/index.d.mts
CHANGED
|
@@ -893,6 +893,123 @@ declare class TCN {
|
|
|
893
893
|
train(sequence: number[][], targets: number[][], lr: number): number;
|
|
894
894
|
}
|
|
895
895
|
|
|
896
|
+
type Word2VecModel = 'skipgram' | 'cbow';
|
|
897
|
+
interface Word2VecOptions {
|
|
898
|
+
/** Size of the sliding context window on each side of the center word. Default 2. */
|
|
899
|
+
windowSize?: number;
|
|
900
|
+
/** Training architecture. Default 'skipgram'. */
|
|
901
|
+
model?: Word2VecModel;
|
|
902
|
+
/** Ignore words with corpus frequency below this threshold. Default 1. */
|
|
903
|
+
minCount?: number;
|
|
904
|
+
}
|
|
905
|
+
declare class Word2Vec {
|
|
906
|
+
/** Learned word vectors, shape [vocabSize][embeddingDim]. */
|
|
907
|
+
embeddings: number[][];
|
|
908
|
+
/** Maps each vocabulary word to its integer index. */
|
|
909
|
+
vocab: Map<string, number>;
|
|
910
|
+
vocabSize: number;
|
|
911
|
+
embeddingDim: number;
|
|
912
|
+
private _indexToWord;
|
|
913
|
+
private _W2;
|
|
914
|
+
private _windowSize;
|
|
915
|
+
private _model;
|
|
916
|
+
private _minCount;
|
|
917
|
+
private _trained;
|
|
918
|
+
constructor(embeddingDim?: number, options?: Word2VecOptions);
|
|
919
|
+
buildVocab(sentences: string[][]): void;
|
|
920
|
+
static tokenize(text: string): string[];
|
|
921
|
+
train(sentences: string[][], lr?: number, epochs?: number): number[];
|
|
922
|
+
getEmbedding(word: string): number[];
|
|
923
|
+
similarity(word1: string, word2: string): number;
|
|
924
|
+
mostSimilar(word: string, topK?: number): {
|
|
925
|
+
word: string;
|
|
926
|
+
score: number;
|
|
927
|
+
}[];
|
|
928
|
+
analogy(positive1: string, negative: string, positive2: string, topK?: number): {
|
|
929
|
+
word: string;
|
|
930
|
+
score: number;
|
|
931
|
+
}[];
|
|
932
|
+
private _skipgramStep;
|
|
933
|
+
private _cbowStep;
|
|
934
|
+
private _hiddenToScores;
|
|
935
|
+
private _nearestByVector;
|
|
936
|
+
private _cosine;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
interface TSNEOptions {
|
|
940
|
+
/** Dimensionality of the output embedding. Default 2. */
|
|
941
|
+
nComponents?: number;
|
|
942
|
+
/**
|
|
943
|
+
* Perplexity — loosely controls the effective number of neighbors considered
|
|
944
|
+
* for each point. Typical values: 5–50. Default 30.
|
|
945
|
+
* Must be less than the number of data points.
|
|
946
|
+
*/
|
|
947
|
+
perplexity?: number;
|
|
948
|
+
/** Learning rate for gradient descent. Default 200. */
|
|
949
|
+
lr?: number;
|
|
950
|
+
/** Number of gradient-descent iterations. Default 1000. */
|
|
951
|
+
nIter?: number;
|
|
952
|
+
/**
|
|
953
|
+
* Seed for the pseudo-random number generator.
|
|
954
|
+
* Set to any integer for reproducible results. Default uses Math.random.
|
|
955
|
+
*/
|
|
956
|
+
seed?: number;
|
|
957
|
+
}
|
|
958
|
+
declare class TSNE {
|
|
959
|
+
/** Result of the embedding, shape [n][nComponents]. Available after fit(). */
|
|
960
|
+
embedding: number[][];
|
|
961
|
+
private readonly _nComponents;
|
|
962
|
+
private readonly _perplexity;
|
|
963
|
+
private readonly _lr;
|
|
964
|
+
private readonly _nIter;
|
|
965
|
+
private readonly _seed;
|
|
966
|
+
private _klDivergence;
|
|
967
|
+
private _P;
|
|
968
|
+
constructor(options?: TSNEOptions);
|
|
969
|
+
fit(X: number[][]): void;
|
|
970
|
+
fitTransform(X: number[][]): number[][];
|
|
971
|
+
kl(): number;
|
|
972
|
+
private _computePcond;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
declare class PositionalEncoding {
|
|
976
|
+
static encode(pos: number, dModel: number): number[];
|
|
977
|
+
static encodeSequence(seqLen: number, dModel: number): number[][];
|
|
978
|
+
static apply(embeddings: number[][], seqLen?: number): number[][];
|
|
979
|
+
}
|
|
980
|
+
declare class LearnedPositionalEncoding {
|
|
981
|
+
readonly maxSeqLen: number;
|
|
982
|
+
readonly dModel: number;
|
|
983
|
+
weights: number[][];
|
|
984
|
+
constructor(maxSeqLen: number, dModel: number);
|
|
985
|
+
getEncoding(pos: number): number[];
|
|
986
|
+
apply(embeddings: number[][], seqLen?: number): number[][];
|
|
987
|
+
update(dWeights: number[][], lr: number): void;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
declare class Augmenter {
|
|
991
|
+
static addNoise(x: number[], sigma?: number): number[];
|
|
992
|
+
static dropoutFeatures(x: number[], rate?: number): number[];
|
|
993
|
+
static augment(x: number[], noiseStd?: number, dropRate?: number): number[];
|
|
994
|
+
static makePair(x: number[]): [number[], number[]];
|
|
995
|
+
}
|
|
996
|
+
declare class ContrastiveLearning {
|
|
997
|
+
encoder: NetworkN;
|
|
998
|
+
projectionHead: NetworkN;
|
|
999
|
+
temperature: number;
|
|
1000
|
+
constructor(inputSize: number, encoderHidden: number[], projectionDim: number, options?: {
|
|
1001
|
+
temperature?: number;
|
|
1002
|
+
encoderOptions?: NetworkNOptions;
|
|
1003
|
+
});
|
|
1004
|
+
encode(x: number[]): number[];
|
|
1005
|
+
project(x: number[]): number[];
|
|
1006
|
+
static cosineSimilarity(a: number[], b: number[]): number;
|
|
1007
|
+
computeLoss(pairs: [number[], number[]][]): number;
|
|
1008
|
+
trainStep(pairs: [number[], number[]][], lr: number): number;
|
|
1009
|
+
private _forwardProjections;
|
|
1010
|
+
private _ntXentLoss;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
896
1013
|
declare class GAN {
|
|
897
1014
|
readonly generator: NetworkN;
|
|
898
1015
|
readonly discriminator: NetworkN;
|
|
@@ -1062,4 +1179,4 @@ declare class DataAugmentation {
|
|
|
1062
1179
|
};
|
|
1063
1180
|
}
|
|
1064
1181
|
|
|
1065
|
-
export { type Activation, Adam, AttentionHead, Autoencoder, BatchNorm, BiasVector, CausalConv1D, ClipOptimizer, ClippedOptimizerFactory, Conv1D, Conv2D, DataAugmentation, DataLoader, type DataPair, DecisionTree, Dropout, EarlyStopping, EmbeddingMatrix, Flatten, GAN, GRULayer, GaussianNaiveBayes, HopfieldNetwork, KMeans, type KMeansOptions, LRScheduler, LSTMLayer, Layer, LayerNorm, LinearRegression, LogisticRegression, LossPlotter, MaxPool2D, ModelSaver, Momentum, MultiHeadAttention, Network, NetworkLSTM, type NetworkLSTMOptions, NetworkN, type NetworkNOptions, NetworkTransformer, type NetworkTransformerOptions, NetworkTransformerRL, type NetworkTransformerRLOptions, Neuron, NeuronN, type Optimizer, type OptimizerFactory, PCA, Perceptron, RNN, SGD, SOM, type SOMOptions, Seq2Seq, type Serializable, SoftmaxRegression, TCN, type TrainDataset, type TrainMetrics, type TrainableNetwork, type TrainableNetworkWithWeights, Trainer, type TrainerOptions, TransformerBlock, type TransformerBlockOptions, VAE, Value, WeightInspector, WeightMatrix, type WeightStats, accuracy, auc, classificationReport, confusionMatrix, crossEntropy, crossEntropyDelta, crossEntropyDeltaRaw, defaultOptimizer, elu, f1Score, leakyRelu, linear, mae, makeElu, makeLeakyRelu, matMul, mse, mseDelta, perplexity, precision, printConfusionMatrix, r2Score, recall, relu, rmse, rocCurve, sigmoid, softmax, softmaxBackward, tanh, transpose, validate2DArray, validateArray, validateArrayMinLength, validateNumber };
|
|
1182
|
+
export { type Activation, Adam, AttentionHead, Augmenter, Autoencoder, BatchNorm, BiasVector, CausalConv1D, ClipOptimizer, ClippedOptimizerFactory, ContrastiveLearning, Conv1D, Conv2D, DataAugmentation, DataLoader, type DataPair, DecisionTree, Dropout, EarlyStopping, EmbeddingMatrix, Flatten, GAN, GRULayer, GaussianNaiveBayes, HopfieldNetwork, KMeans, type KMeansOptions, LRScheduler, LSTMLayer, Layer, LayerNorm, LearnedPositionalEncoding, LinearRegression, LogisticRegression, LossPlotter, MaxPool2D, ModelSaver, Momentum, MultiHeadAttention, Network, NetworkLSTM, type NetworkLSTMOptions, NetworkN, type NetworkNOptions, NetworkTransformer, type NetworkTransformerOptions, NetworkTransformerRL, type NetworkTransformerRLOptions, Neuron, NeuronN, type Optimizer, type OptimizerFactory, PCA, Perceptron, PositionalEncoding, RNN, SGD, SOM, type SOMOptions, Seq2Seq, type Serializable, SoftmaxRegression, TCN, TSNE, type TSNEOptions, type TrainDataset, type TrainMetrics, type TrainableNetwork, type TrainableNetworkWithWeights, Trainer, type TrainerOptions, TransformerBlock, type TransformerBlockOptions, VAE, Value, WeightInspector, WeightMatrix, type WeightStats, Word2Vec, type Word2VecModel, type Word2VecOptions, accuracy, auc, classificationReport, confusionMatrix, crossEntropy, crossEntropyDelta, crossEntropyDeltaRaw, defaultOptimizer, elu, f1Score, leakyRelu, linear, mae, makeElu, makeLeakyRelu, matMul, mse, mseDelta, perplexity, precision, printConfusionMatrix, r2Score, recall, relu, rmse, rocCurve, sigmoid, softmax, softmaxBackward, tanh, transpose, validate2DArray, validateArray, validateArrayMinLength, validateNumber };
|
package/dist/index.d.ts
CHANGED
|
@@ -893,6 +893,123 @@ declare class TCN {
|
|
|
893
893
|
train(sequence: number[][], targets: number[][], lr: number): number;
|
|
894
894
|
}
|
|
895
895
|
|
|
896
|
+
type Word2VecModel = 'skipgram' | 'cbow';
|
|
897
|
+
interface Word2VecOptions {
|
|
898
|
+
/** Size of the sliding context window on each side of the center word. Default 2. */
|
|
899
|
+
windowSize?: number;
|
|
900
|
+
/** Training architecture. Default 'skipgram'. */
|
|
901
|
+
model?: Word2VecModel;
|
|
902
|
+
/** Ignore words with corpus frequency below this threshold. Default 1. */
|
|
903
|
+
minCount?: number;
|
|
904
|
+
}
|
|
905
|
+
declare class Word2Vec {
|
|
906
|
+
/** Learned word vectors, shape [vocabSize][embeddingDim]. */
|
|
907
|
+
embeddings: number[][];
|
|
908
|
+
/** Maps each vocabulary word to its integer index. */
|
|
909
|
+
vocab: Map<string, number>;
|
|
910
|
+
vocabSize: number;
|
|
911
|
+
embeddingDim: number;
|
|
912
|
+
private _indexToWord;
|
|
913
|
+
private _W2;
|
|
914
|
+
private _windowSize;
|
|
915
|
+
private _model;
|
|
916
|
+
private _minCount;
|
|
917
|
+
private _trained;
|
|
918
|
+
constructor(embeddingDim?: number, options?: Word2VecOptions);
|
|
919
|
+
buildVocab(sentences: string[][]): void;
|
|
920
|
+
static tokenize(text: string): string[];
|
|
921
|
+
train(sentences: string[][], lr?: number, epochs?: number): number[];
|
|
922
|
+
getEmbedding(word: string): number[];
|
|
923
|
+
similarity(word1: string, word2: string): number;
|
|
924
|
+
mostSimilar(word: string, topK?: number): {
|
|
925
|
+
word: string;
|
|
926
|
+
score: number;
|
|
927
|
+
}[];
|
|
928
|
+
analogy(positive1: string, negative: string, positive2: string, topK?: number): {
|
|
929
|
+
word: string;
|
|
930
|
+
score: number;
|
|
931
|
+
}[];
|
|
932
|
+
private _skipgramStep;
|
|
933
|
+
private _cbowStep;
|
|
934
|
+
private _hiddenToScores;
|
|
935
|
+
private _nearestByVector;
|
|
936
|
+
private _cosine;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
interface TSNEOptions {
|
|
940
|
+
/** Dimensionality of the output embedding. Default 2. */
|
|
941
|
+
nComponents?: number;
|
|
942
|
+
/**
|
|
943
|
+
* Perplexity — loosely controls the effective number of neighbors considered
|
|
944
|
+
* for each point. Typical values: 5–50. Default 30.
|
|
945
|
+
* Must be less than the number of data points.
|
|
946
|
+
*/
|
|
947
|
+
perplexity?: number;
|
|
948
|
+
/** Learning rate for gradient descent. Default 200. */
|
|
949
|
+
lr?: number;
|
|
950
|
+
/** Number of gradient-descent iterations. Default 1000. */
|
|
951
|
+
nIter?: number;
|
|
952
|
+
/**
|
|
953
|
+
* Seed for the pseudo-random number generator.
|
|
954
|
+
* Set to any integer for reproducible results. Default uses Math.random.
|
|
955
|
+
*/
|
|
956
|
+
seed?: number;
|
|
957
|
+
}
|
|
958
|
+
declare class TSNE {
|
|
959
|
+
/** Result of the embedding, shape [n][nComponents]. Available after fit(). */
|
|
960
|
+
embedding: number[][];
|
|
961
|
+
private readonly _nComponents;
|
|
962
|
+
private readonly _perplexity;
|
|
963
|
+
private readonly _lr;
|
|
964
|
+
private readonly _nIter;
|
|
965
|
+
private readonly _seed;
|
|
966
|
+
private _klDivergence;
|
|
967
|
+
private _P;
|
|
968
|
+
constructor(options?: TSNEOptions);
|
|
969
|
+
fit(X: number[][]): void;
|
|
970
|
+
fitTransform(X: number[][]): number[][];
|
|
971
|
+
kl(): number;
|
|
972
|
+
private _computePcond;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
declare class PositionalEncoding {
|
|
976
|
+
static encode(pos: number, dModel: number): number[];
|
|
977
|
+
static encodeSequence(seqLen: number, dModel: number): number[][];
|
|
978
|
+
static apply(embeddings: number[][], seqLen?: number): number[][];
|
|
979
|
+
}
|
|
980
|
+
declare class LearnedPositionalEncoding {
|
|
981
|
+
readonly maxSeqLen: number;
|
|
982
|
+
readonly dModel: number;
|
|
983
|
+
weights: number[][];
|
|
984
|
+
constructor(maxSeqLen: number, dModel: number);
|
|
985
|
+
getEncoding(pos: number): number[];
|
|
986
|
+
apply(embeddings: number[][], seqLen?: number): number[][];
|
|
987
|
+
update(dWeights: number[][], lr: number): void;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
declare class Augmenter {
|
|
991
|
+
static addNoise(x: number[], sigma?: number): number[];
|
|
992
|
+
static dropoutFeatures(x: number[], rate?: number): number[];
|
|
993
|
+
static augment(x: number[], noiseStd?: number, dropRate?: number): number[];
|
|
994
|
+
static makePair(x: number[]): [number[], number[]];
|
|
995
|
+
}
|
|
996
|
+
declare class ContrastiveLearning {
|
|
997
|
+
encoder: NetworkN;
|
|
998
|
+
projectionHead: NetworkN;
|
|
999
|
+
temperature: number;
|
|
1000
|
+
constructor(inputSize: number, encoderHidden: number[], projectionDim: number, options?: {
|
|
1001
|
+
temperature?: number;
|
|
1002
|
+
encoderOptions?: NetworkNOptions;
|
|
1003
|
+
});
|
|
1004
|
+
encode(x: number[]): number[];
|
|
1005
|
+
project(x: number[]): number[];
|
|
1006
|
+
static cosineSimilarity(a: number[], b: number[]): number;
|
|
1007
|
+
computeLoss(pairs: [number[], number[]][]): number;
|
|
1008
|
+
trainStep(pairs: [number[], number[]][], lr: number): number;
|
|
1009
|
+
private _forwardProjections;
|
|
1010
|
+
private _ntXentLoss;
|
|
1011
|
+
}
|
|
1012
|
+
|
|
896
1013
|
declare class GAN {
|
|
897
1014
|
readonly generator: NetworkN;
|
|
898
1015
|
readonly discriminator: NetworkN;
|
|
@@ -1062,4 +1179,4 @@ declare class DataAugmentation {
|
|
|
1062
1179
|
};
|
|
1063
1180
|
}
|
|
1064
1181
|
|
|
1065
|
-
export { type Activation, Adam, AttentionHead, Autoencoder, BatchNorm, BiasVector, CausalConv1D, ClipOptimizer, ClippedOptimizerFactory, Conv1D, Conv2D, DataAugmentation, DataLoader, type DataPair, DecisionTree, Dropout, EarlyStopping, EmbeddingMatrix, Flatten, GAN, GRULayer, GaussianNaiveBayes, HopfieldNetwork, KMeans, type KMeansOptions, LRScheduler, LSTMLayer, Layer, LayerNorm, LinearRegression, LogisticRegression, LossPlotter, MaxPool2D, ModelSaver, Momentum, MultiHeadAttention, Network, NetworkLSTM, type NetworkLSTMOptions, NetworkN, type NetworkNOptions, NetworkTransformer, type NetworkTransformerOptions, NetworkTransformerRL, type NetworkTransformerRLOptions, Neuron, NeuronN, type Optimizer, type OptimizerFactory, PCA, Perceptron, RNN, SGD, SOM, type SOMOptions, Seq2Seq, type Serializable, SoftmaxRegression, TCN, type TrainDataset, type TrainMetrics, type TrainableNetwork, type TrainableNetworkWithWeights, Trainer, type TrainerOptions, TransformerBlock, type TransformerBlockOptions, VAE, Value, WeightInspector, WeightMatrix, type WeightStats, accuracy, auc, classificationReport, confusionMatrix, crossEntropy, crossEntropyDelta, crossEntropyDeltaRaw, defaultOptimizer, elu, f1Score, leakyRelu, linear, mae, makeElu, makeLeakyRelu, matMul, mse, mseDelta, perplexity, precision, printConfusionMatrix, r2Score, recall, relu, rmse, rocCurve, sigmoid, softmax, softmaxBackward, tanh, transpose, validate2DArray, validateArray, validateArrayMinLength, validateNumber };
|
|
1182
|
+
export { type Activation, Adam, AttentionHead, Augmenter, Autoencoder, BatchNorm, BiasVector, CausalConv1D, ClipOptimizer, ClippedOptimizerFactory, ContrastiveLearning, Conv1D, Conv2D, DataAugmentation, DataLoader, type DataPair, DecisionTree, Dropout, EarlyStopping, EmbeddingMatrix, Flatten, GAN, GRULayer, GaussianNaiveBayes, HopfieldNetwork, KMeans, type KMeansOptions, LRScheduler, LSTMLayer, Layer, LayerNorm, LearnedPositionalEncoding, LinearRegression, LogisticRegression, LossPlotter, MaxPool2D, ModelSaver, Momentum, MultiHeadAttention, Network, NetworkLSTM, type NetworkLSTMOptions, NetworkN, type NetworkNOptions, NetworkTransformer, type NetworkTransformerOptions, NetworkTransformerRL, type NetworkTransformerRLOptions, Neuron, NeuronN, type Optimizer, type OptimizerFactory, PCA, Perceptron, PositionalEncoding, RNN, SGD, SOM, type SOMOptions, Seq2Seq, type Serializable, SoftmaxRegression, TCN, TSNE, type TSNEOptions, type TrainDataset, type TrainMetrics, type TrainableNetwork, type TrainableNetworkWithWeights, Trainer, type TrainerOptions, TransformerBlock, type TransformerBlockOptions, VAE, Value, WeightInspector, WeightMatrix, type WeightStats, Word2Vec, type Word2VecModel, type Word2VecOptions, accuracy, auc, classificationReport, confusionMatrix, crossEntropy, crossEntropyDelta, crossEntropyDeltaRaw, defaultOptimizer, elu, f1Score, leakyRelu, linear, mae, makeElu, makeLeakyRelu, matMul, mse, mseDelta, perplexity, precision, printConfusionMatrix, r2Score, recall, relu, rmse, rocCurve, sigmoid, softmax, softmaxBackward, tanh, transpose, validate2DArray, validateArray, validateArrayMinLength, validateNumber };
|