Skip to content

Commit

Permalink
replace single-letter type variable names with more descriptive ones
Browse files Browse the repository at this point in the history
  • Loading branch information
douira committed Feb 21, 2025
1 parent d36fc88 commit a36c63a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.util.Locale;

public abstract class Average1DEstimator<C> extends Estimator<C, Average1DEstimator.Value<C>, Average1DEstimator.ValueBatch<C>, Void, Long, Average1DEstimator.Average<C>> {
public abstract class Average1DEstimator<Category> extends Estimator<Category, Average1DEstimator.Value<Category>, Average1DEstimator.ValueBatch<Category>, Void, Long, Average1DEstimator.Average<Category>> {
private final float newDataRatio;
private final long initialEstimate;

Expand Down Expand Up @@ -39,7 +39,7 @@ public float getAverage() {
}

@Override
protected ValueBatch<C> createNewDataBatch() {
protected ValueBatch<Category> createNewDataBatch() {
return new ValueBatch<>();
}

Expand Down Expand Up @@ -79,11 +79,11 @@ public String toString() {
}

@Override
protected Average<C> createNewModel() {
protected Average<Category> createNewModel() {
return new Average<>(this.newDataRatio, this.initialEstimate);
}

public Long predict(C category) {
public Long predict(Category category) {
return super.predict(category, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
/**
* This generic model learning class that can be used to estimate values based on a set of data points. It performs batch-wise model updates. The actual data aggregation and model updates are delegated to the implementing classes. The estimator stores multiple models in a map, one for each category.
*
* @param <C> The type of the category key
* @param <D> A data point contains a category and one piece of data
* @param <B> A data batch contains multiple data points
* @param <I> The input to the model
* @param <O> The output of the model
* @param <M> The model that is used to predict values
* @param <Category> The type of the category key
* @param <Point> A data point contains a category and one piece of data
* @param <Batch> A data batch contains multiple data points
* @param <Input> The input to the model
* @param <Output> The output of the model
* @param <Model> The model that is used to predict values
*/
public abstract class Estimator<
C,
D extends Estimator.DataPoint<C>,
B extends Estimator.DataBatch<D>,
I,
O,
M extends Estimator.Model<I, O, B, M>> {
protected final Map<C, M> models = createMap();
protected final Map<C, B> batches = createMap();
Category,
Point extends Estimator.DataPoint<Category>,
Batch extends Estimator.DataBatch<Point>,
Input,
Output,
Model extends Estimator.Model<Input, Output, Batch, Model>> {
protected final Map<Category, Model> models = createMap();
protected final Map<Category, Batch> batches = createMap();

protected interface DataBatch<D> {
void addDataPoint(D input);
Expand All @@ -38,13 +38,13 @@ protected interface Model<I, O, B, M extends Model<I, O, B, M>> {
O predict(I input);
}

protected abstract B createNewDataBatch();
protected abstract Batch createNewDataBatch();

protected abstract M createNewModel();
protected abstract Model createNewModel();

protected abstract <T> Map<C, T> createMap();
protected abstract <T> Map<Category, T> createMap();

public void addData(D data) {
public void addData(Point data) {
var category = data.category();
var batch = this.batches.get(category);
if (batch == null) {
Expand All @@ -54,7 +54,7 @@ public void addData(D data) {
batch.addDataPoint(data);
}

private M ensureModel(C category) {
private Model ensureModel(Category category) {
var model = this.models.get(category);
if (model == null) {
model = this.createNewModel();
Expand All @@ -77,11 +77,11 @@ public void updateModels() {
});
}

public O predict(C category, I input) {
public Output predict(Category category, Input input) {
return this.ensureModel(category).predict(input);
}

public String toString(C category) {
public String toString(Category category) {
var model = this.models.get(category);
if (model == null) {
return "-";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.util.Locale;

public abstract class Linear2DEstimator<C> extends Estimator<C, Linear2DEstimator.DataPair<C>, Linear2DEstimator.LinearRegressionBatch<C>, Long, Long, Linear2DEstimator.LinearFunction<C>> {
public abstract class Linear2DEstimator<Category> extends Estimator<Category, Linear2DEstimator.DataPair<Category>, Linear2DEstimator.LinearRegressionBatch<Category>, Long, Long, Linear2DEstimator.LinearFunction<Category>> {
private final float newDataRatio;
private final int initialSampleTarget;
private final long initialOutput;
Expand Down Expand Up @@ -34,7 +34,7 @@ public void reset() {
}

@Override
protected LinearRegressionBatch<C> createNewDataBatch() {
protected LinearRegressionBatch<Category> createNewDataBatch() {
return new LinearRegressionBatch<>();
}

Expand Down Expand Up @@ -137,7 +137,7 @@ public String toString() {
}

@Override
protected LinearFunction<C> createNewModel() {
protected LinearFunction<Category> createNewModel() {
return new LinearFunction<>(this.newDataRatio, this.initialSampleTarget, this.initialOutput);
}
}

0 comments on commit a36c63a

Please sign in to comment.