Skip to content

Commit

Permalink
add correct debug presentation of the estimator models
Browse files Browse the repository at this point in the history
  • Loading branch information
douira committed Jan 5, 2025
1 parent 3a02c45 commit b863dc8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1208,15 +1208,15 @@ public Collection<String> getDebugStrings() {
);

if (PlatformRuntimeInformation.getInstance().isDevelopmentEnvironment()) {
var meshTaskDuration = this.jobDurationEstimator.estimateJobDuration(ChunkBuilderMeshingTask.class, 1);
var sortTaskDuration = this.jobDurationEstimator.estimateJobDuration(ChunkBuilderSortingTask.class, 1);
list.add(String.format("Duration: Mesh=%dns, Sort=%dns", meshTaskDuration, sortTaskDuration));
var meshTaskParameters = this.jobDurationEstimator.toString(ChunkBuilderMeshingTask.class);
var sortTaskParameters = this.jobDurationEstimator.toString(ChunkBuilderSortingTask.class);
list.add(String.format("Duration: Mesh %s, Sort %s", meshTaskParameters, sortTaskParameters));

var sizeEstimates = new StringBuilder();
var sizeEstimates = new ReferenceArrayList<String>();
for (var type : MeshResultSize.SectionCategory.values()) {
sizeEstimates.append(String.format("%s=%d, ", type, this.meshTaskSizeEstimator.predict(type)));
sizeEstimates.add(String.format("%s=%s", type, this.meshTaskSizeEstimator.toString(type)));
}
list.add(String.format("Size: %s", sizeEstimates));
list.add(String.format("Size: %s", String.join(", ", sizeEstimates)));
}

this.sortTriggering.addDebugStrings(list);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import net.caffeinemc.mods.sodium.client.util.MathUtil;

import java.util.Locale;

public abstract class Average1DEstimator<C> extends Estimator<C, Average1DEstimator.Value<C>, Average1DEstimator.ValueBatch<C>, Void, Long, Average1DEstimator.Average<C>> {
private final float newDataRatio;
private final long initialEstimate;
Expand Down Expand Up @@ -69,6 +71,11 @@ public Average<C> update(ValueBatch<C> batch) {
public Long predict(Void input) {
return (long) this.average;
}

@Override
public String toString() {
return String.format(Locale.US, "%.0f", this.average);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,12 @@ public void updateModels() {
public O predict(C category, I input) {
return this.ensureModel(category).predict(input);
}

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

import it.unimi.dsi.fastutil.objects.ObjectArrayList;

import java.util.Locale;

public abstract class Linear2DEstimator<C> extends Estimator<C, Linear2DEstimator.DataPair<C>, Linear2DEstimator.LinearRegressionBatch<C>, Long, Long, Linear2DEstimator.LinearFunction<C>> {
private final float newDataRatio;
private final int initialSampleTarget;
Expand Down Expand Up @@ -127,6 +129,11 @@ public Long predict(Long input) {

return (long) (this.yIntercept + this.slope * input);
}

@Override
public String toString() {
return String.format(Locale.US, "s=%.2f,y=%.0f", this.slope, this.yIntercept);
}
}

@Override
Expand Down

0 comments on commit b863dc8

Please sign in to comment.