Skip to content

Commit 2d41039

Browse files
committed
#1 Face lifting
1 parent 0f97fe6 commit 2d41039

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

src/main/java/org/scaleborn/elasticsearch/linreg/LinearRegressionPlugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import org.scaleborn.elasticsearch.linreg.aggregation.stats.StatsAggregationBuilder;
2828
import org.scaleborn.elasticsearch.linreg.aggregation.stats.StatsAggregationParser;
2929

30+
/**
31+
* Plugin definition for linear regression aggregations.
32+
*/
3033
public class LinearRegressionPlugin extends Plugin implements SearchPlugin {
3134

3235
@Override

src/main/java/org/scaleborn/elasticsearch/linreg/aggregation/predict/InternalPrediction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.scaleborn.elasticsearch.linreg.aggregation.predict;
1818

1919
import java.io.IOException;
20-
import java.util.Arrays;
2120
import java.util.List;
2221
import java.util.Map;
2322
import org.apache.logging.log4j.Logger;
@@ -93,7 +92,7 @@ protected InternalPrediction buildInternalAggregation(final String name, final i
9392
protected PredictionResults buildResults(final PredictionSampling composedSampling,
9493
final SlopeCoefficients slopeCoefficients, final double intercept) {
9594
double predictedValue = intercept;
96-
LOGGER.info("Predicting values for inputs: {}", Arrays.toString(this.inputs));
95+
LOGGER.debug("Predicting values for inputs: {}", this.inputs);
9796
for (int i = 0; i < this.featuresCount; i++) {
9897
predictedValue += slopeCoefficients.getCoefficients()[i] * this.inputs[i];
9998
}

src/main/java/org/scaleborn/elasticsearch/linreg/aggregation/predict/PredictionAggregationParser.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020
import java.util.ArrayList;
2121
import java.util.List;
2222
import java.util.Map;
23-
import org.apache.logging.log4j.Logger;
2423
import org.elasticsearch.common.ParseField;
2524
import org.elasticsearch.common.ParsingException;
26-
import org.elasticsearch.common.logging.Loggers;
2725
import org.elasticsearch.common.xcontent.XContentParser;
2826
import org.elasticsearch.common.xcontent.XContentParser.Token;
2927
import org.scaleborn.elasticsearch.linreg.aggregation.support.BaseParser;
@@ -33,7 +31,6 @@
3331
*/
3432
public class PredictionAggregationParser extends BaseParser<PredictionAggregationBuilder> {
3533

36-
private static final Logger LOGGER = Loggers.getLogger(PredictionAggregationParser.class);
3734
private static final ParseField INPUTS = new ParseField("inputs");
3835

3936

@@ -73,7 +70,6 @@ protected boolean token(final String aggregationName, final String currentFieldN
7370
}
7471
}
7572
otherOptions.put(INPUTS, inputFields);
76-
LOGGER.info("Parsed input fields: {}", inputFields);
7773
return true;
7874
}
7975
return false;

src/main/java/org/scaleborn/elasticsearch/linreg/aggregation/support/BaseInternalAggregation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ public InternalAggregation doReduce(final List<InternalAggregation> aggregations
149149

150150
final S composedSampling = buildSampling(this.featuresCount);
151151
for (int i = 0; i < aggs.size(); ++i) {
152-
LOGGER.info("Merging sampling={}: {}", i, ((BaseInternalAggregation) aggs.get(i)).sampling);
152+
LOGGER.debug("Merging sampling={}: {}", i, ((BaseInternalAggregation) aggs.get(i)).sampling);
153153
//noinspection unchecked
154154
composedSampling.merge((S) ((BaseInternalAggregation) aggs.get(i)).sampling);
155155
}
156156

157157
final M evaluatedResults = evaluateResults(composedSampling);
158158

159-
LOGGER.info("Evaluated results: {}", evaluatedResults);
159+
LOGGER.debug("Evaluated results: {}", evaluatedResults);
160160
return buildInternalAggregation(this.name, this.featuresCount, composedSampling,
161161
evaluatedResults,
162162
pipelineAggregators(), getMetaData());

src/main/java/org/scaleborn/elasticsearch/linreg/aggregation/support/BaseSamplingAggregator.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public abstract class BaseSamplingAggregator<S extends BaseSampling<S>> extends
5151

5252
protected ObjectArray<S> samplings;
5353

54+
private int fieldsCount;
55+
5456
public BaseSamplingAggregator(final String name,
5557
final List<NamedValuesSourceSpec<Numeric>> valuesSources,
5658
final SearchContext context,
@@ -61,6 +63,7 @@ public BaseSamplingAggregator(final String name,
6163
if (valuesSources != null && !valuesSources.isEmpty()) {
6264
this.valuesSources = new NumericMultiValuesSource(valuesSources, multiValueMode);
6365
this.samplings = context.bigArrays().newObjectArray(1);
66+
this.fieldsCount = this.valuesSources.fieldNames().length;
6467
} else {
6568
this.valuesSources = null;
6669
}
@@ -78,15 +81,13 @@ public LeafBucketCollector getLeafCollector(final LeafReaderContext ctx,
7881
return LeafBucketCollector.NO_OP_COLLECTOR;
7982
}
8083
final BigArrays bigArrays = this.context.bigArrays();
81-
final NumericDoubleValues[] values = new NumericDoubleValues[this.valuesSources
82-
.fieldNames().length];
83-
for (int i = 0; i < values.length; ++i) {
84+
final NumericDoubleValues[] values = new NumericDoubleValues[this.fieldsCount];
85+
for (int i = 0; i < this.fieldsCount; ++i) {
8486
values[i] = this.valuesSources.getField(i, ctx);
8587
}
8688

8789
return new LeafBucketCollectorBase(sub, values) {
88-
final String[] fieldNames = BaseSamplingAggregator.this.valuesSources.fieldNames();
89-
final double[] fieldVals = new double[this.fieldNames.length];
90+
final double[] fieldVals = new double[BaseSamplingAggregator.this.fieldsCount];
9091

9192
@Override
9293
public void collect(final int doc, final long bucket) throws IOException {
@@ -97,13 +98,14 @@ public void collect(final int doc, final long bucket) throws IOException {
9798
S sampling = BaseSamplingAggregator.this.samplings.get(bucket);
9899
// add document fields to correlation stats
99100
if (sampling == null) {
100-
sampling = buildSampling(this.fieldNames.length - 1);
101+
sampling = buildSampling(BaseSamplingAggregator.this.fieldsCount - 1);
101102
BaseSamplingAggregator.this.samplings.set(bucket, sampling);
102103
}
103-
LOGGER.info("Sampling for bucket={}, fields={}", bucket, this.fieldVals);
104-
sampling.sample(this.fieldVals, this.fieldVals[this.fieldVals.length - 1]);
104+
// LOGGER.info("Sampling for bucket={}, fields={}", bucket, this.fieldVals);
105+
sampling
106+
.sample(this.fieldVals, this.fieldVals[BaseSamplingAggregator.this.fieldsCount - 1]);
105107
} else {
106-
LOGGER.warn("Skipped bucket={}, fields={}", bucket, this.fieldVals);
108+
// LOGGER.warn("Skipped bucket={}, fields={}", bucket, this.fieldVals);
107109
}
108110
}
109111

@@ -112,7 +114,7 @@ public void collect(final int doc, final long bucket) throws IOException {
112114
*/
113115
private boolean includeDocument(final int doc) {
114116
// loop over fields
115-
for (int i = 0; i < this.fieldVals.length; ++i) {
117+
for (int i = 0; i < BaseSamplingAggregator.this.fieldsCount; ++i) {
116118
final NumericDoubleValues doubleValues = values[i];
117119
final double value = doubleValues.get(doc);
118120
// skip if value is missing

0 commit comments

Comments
 (0)