Skip to content

Commit 7721195

Browse files
committed
replace single-letter type variable names with more descriptive ones
1 parent d36fc88 commit 7721195

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/estimation/Average1DEstimator.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import java.util.Locale;
66

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

@@ -13,16 +13,16 @@ public Average1DEstimator(float newDataRatio, long initialEstimate) {
1313
this.initialEstimate = initialEstimate;
1414
}
1515

16-
public interface Value<C> extends DataPoint<C> {
16+
public interface Value<PointCategory> extends DataPoint<PointCategory> {
1717
long value();
1818
}
1919

20-
protected static class ValueBatch<C> implements Estimator.DataBatch<Value<C>> {
20+
protected static class ValueBatch<BatchCategory> implements Estimator.DataBatch<Value<BatchCategory>> {
2121
private long valueSum;
2222
private long count;
2323

2424
@Override
25-
public void addDataPoint(Value<C> input) {
25+
public void addDataPoint(Value<BatchCategory> input) {
2626
this.valueSum += input.value();
2727
this.count++;
2828
}
@@ -39,11 +39,11 @@ public float getAverage() {
3939
}
4040

4141
@Override
42-
protected ValueBatch<C> createNewDataBatch() {
42+
protected ValueBatch<Category> createNewDataBatch() {
4343
return new ValueBatch<>();
4444
}
4545

46-
protected static class Average<C> implements Estimator.Model<Void, Long, ValueBatch<C>, Average<C>> {
46+
protected static class Average<ModelCategory> implements Estimator.Model<Void, Long, ValueBatch<ModelCategory>, Average<ModelCategory>> {
4747
private final float newDataRatio;
4848
private boolean hasRealData = false;
4949
private float average;
@@ -54,7 +54,7 @@ public Average(float newDataRatio, float initialValue) {
5454
}
5555

5656
@Override
57-
public Average<C> update(ValueBatch<C> batch) {
57+
public Average<ModelCategory> update(ValueBatch<ModelCategory> batch) {
5858
if (batch.count > 0) {
5959
if (this.hasRealData) {
6060
this.average = MathUtil.exponentialMovingAverage(this.average, batch.getAverage(), this.newDataRatio);
@@ -79,11 +79,11 @@ public String toString() {
7979
}
8080

8181
@Override
82-
protected Average<C> createNewModel() {
82+
protected Average<Category> createNewModel() {
8383
return new Average<>(this.newDataRatio, this.initialEstimate);
8484
}
8585

86-
public Long predict(C category) {
86+
public Long predict(Category category) {
8787
return super.predict(category, null);
8888
}
8989
}

common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/estimation/Estimator.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,46 @@
55
/**
66
* 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.
77
*
8-
* @param <C> The type of the category key
9-
* @param <D> A data point contains a category and one piece of data
10-
* @param <B> A data batch contains multiple data points
11-
* @param <I> The input to the model
12-
* @param <O> The output of the model
13-
* @param <M> The model that is used to predict values
8+
* @param <Category> The type of the category key
9+
* @param <Point> A data point contains a category and one piece of data
10+
* @param <Batch> A data batch contains multiple data points
11+
* @param <Input> The input to the model
12+
* @param <Output> The output of the model
13+
* @param <Model> The model that is used to predict values
1414
*/
1515
public abstract class Estimator<
16-
C,
17-
D extends Estimator.DataPoint<C>,
18-
B extends Estimator.DataBatch<D>,
19-
I,
20-
O,
21-
M extends Estimator.Model<I, O, B, M>> {
22-
protected final Map<C, M> models = createMap();
23-
protected final Map<C, B> batches = createMap();
24-
25-
protected interface DataBatch<D> {
26-
void addDataPoint(D input);
16+
Category,
17+
Point extends Estimator.DataPoint<Category>,
18+
Batch extends Estimator.DataBatch<Point>,
19+
Input,
20+
Output,
21+
Model extends Estimator.Model<Input, Output, Batch, Model>> {
22+
protected final Map<Category, Model> models = createMap();
23+
protected final Map<Category, Batch> batches = createMap();
24+
25+
protected interface DataBatch<BatchPoint> {
26+
void addDataPoint(BatchPoint input);
2727

2828
void reset();
2929
}
3030

31-
protected interface DataPoint<C> {
32-
C category();
31+
protected interface DataPoint<PointCategory> {
32+
PointCategory category();
3333
}
3434

35-
protected interface Model<I, O, B, M extends Model<I, O, B, M>> {
36-
M update(B batch);
35+
protected interface Model<ModelInput, ModelOutput, ModelBatch, ModelSelf extends Model<ModelInput, ModelOutput, ModelBatch, ModelSelf>> {
36+
ModelSelf update(ModelBatch batch);
3737

38-
O predict(I input);
38+
ModelOutput predict(ModelInput input);
3939
}
4040

41-
protected abstract B createNewDataBatch();
41+
protected abstract Batch createNewDataBatch();
4242

43-
protected abstract M createNewModel();
43+
protected abstract Model createNewModel();
4444

45-
protected abstract <T> Map<C, T> createMap();
45+
protected abstract <T> Map<Category, T> createMap();
4646

47-
public void addData(D data) {
47+
public void addData(Point data) {
4848
var category = data.category();
4949
var batch = this.batches.get(category);
5050
if (batch == null) {
@@ -54,7 +54,7 @@ public void addData(D data) {
5454
batch.addDataPoint(data);
5555
}
5656

57-
private M ensureModel(C category) {
57+
private Model ensureModel(Category category) {
5858
var model = this.models.get(category);
5959
if (model == null) {
6060
model = this.createNewModel();
@@ -77,11 +77,11 @@ public void updateModels() {
7777
});
7878
}
7979

80-
public O predict(C category, I input) {
81-
return this.ensureModel(category).predict(input);
80+
public Output predict(Category category, Input input) {
81+
return (Output) this.ensureModel(category).predict(input);
8282
}
8383

84-
public String toString(C category) {
84+
public String toString(Category category) {
8585
var model = this.models.get(category);
8686
if (model == null) {
8787
return "-";

common/src/main/java/net/caffeinemc/mods/sodium/client/render/chunk/compile/estimation/Linear2DEstimator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import java.util.Locale;
66

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

3636
@Override
37-
protected LinearRegressionBatch<C> createNewDataBatch() {
37+
protected LinearRegressionBatch<Category> createNewDataBatch() {
3838
return new LinearRegressionBatch<>();
3939
}
4040

@@ -137,7 +137,7 @@ public String toString() {
137137
}
138138

139139
@Override
140-
protected LinearFunction<C> createNewModel() {
140+
protected LinearFunction<Category> createNewModel() {
141141
return new LinearFunction<>(this.newDataRatio, this.initialSampleTarget, this.initialOutput);
142142
}
143143
}

0 commit comments

Comments
 (0)