60
60
import com .amazon .randomcutforest .returntypes .Neighbor ;
61
61
import com .amazon .randomcutforest .returntypes .OneSidedConvergingDiVectorAccumulator ;
62
62
import com .amazon .randomcutforest .returntypes .OneSidedConvergingDoubleAccumulator ;
63
+ import com .amazon .randomcutforest .returntypes .RangeVector ;
63
64
import com .amazon .randomcutforest .returntypes .SampleSummary ;
64
65
import com .amazon .randomcutforest .sampler .CompactSampler ;
65
66
import com .amazon .randomcutforest .sampler .IStreamSampler ;
@@ -568,10 +569,11 @@ public float[] lastShingledPoint() {
568
569
569
570
/**
570
571
*
571
- * @return the sequence index of the last known shingled point
572
+ * @return the sequence index of the last known shingled point. If internal
573
+ * shingling is not enabled, then this would correspond to the number of
574
+ * updates
572
575
*/
573
576
public long nextSequenceIndex () {
574
- checkArgument (internalShinglingEnabled , "incorrect use" );
575
577
return stateCoordinator .getStore ().getNextSequenceIndex ();
576
578
}
577
579
@@ -1001,7 +1003,8 @@ public List<ConditionalTreeSample> getConditionalField(float[] point, int number
1001
1003
1002
1004
int [] liftedIndices = transformIndices (missingIndexes , point .length );
1003
1005
IMultiVisitorFactory <ConditionalTreeSample > visitorFactory = (tree , y ) -> new ImputeVisitor (y ,
1004
- tree .projectToTree (y ), liftedIndices , tree .projectMissingIndices (liftedIndices ), centrality );
1006
+ tree .projectToTree (y ), liftedIndices , tree .projectMissingIndices (liftedIndices ), centrality ,
1007
+ tree .getRandomSeed ());
1005
1008
return traverseForestMulti (transformToShingledPoint (point ), visitorFactory , ConditionalTreeSample .collector );
1006
1009
}
1007
1010
@@ -1072,25 +1075,41 @@ public double[] extrapolateBasic(double[] point, int horizon, int blockSize, boo
1072
1075
}
1073
1076
1074
1077
public float [] extrapolateBasic (float [] point , int horizon , int blockSize , boolean cyclic , int shingleIndex ) {
1078
+ return extrapolateWithRanges (point , horizon , blockSize , cyclic , shingleIndex , 1.0 ).values ;
1079
+ }
1080
+
1081
+ // the following is provided for maximum flexibilty from the calling entity;
1082
+ // but likely use is extrapolateFromShingle(), which abstracts away rotation
1083
+ // etc.
1084
+ public RangeVector extrapolateWithRanges (float [] point , int horizon , int blockSize , boolean cyclic ,
1085
+ int shingleIndex , double centrality ) {
1075
1086
checkArgument (0 < blockSize && blockSize < dimensions ,
1076
1087
"blockSize must be between 0 and dimensions (exclusive)" );
1077
1088
checkArgument (dimensions % blockSize == 0 , "dimensions must be evenly divisible by blockSize" );
1078
1089
checkArgument (0 <= shingleIndex && shingleIndex < dimensions / blockSize ,
1079
1090
"shingleIndex must be between 0 (inclusive) and dimensions / blockSize" );
1080
1091
1081
- float [] result = new float [ blockSize * horizon ] ;
1092
+ RangeVector result = new RangeVector ( blockSize * horizon ) ;
1082
1093
int [] missingIndexes = new int [blockSize ];
1083
1094
float [] queryPoint = Arrays .copyOf (point , dimensions );
1084
1095
1085
1096
if (cyclic ) {
1086
- extrapolateBasicCyclic (result , horizon , blockSize , shingleIndex , queryPoint , missingIndexes );
1097
+ extrapolateBasicCyclic (result , horizon , blockSize , shingleIndex , queryPoint , missingIndexes , centrality );
1087
1098
} else {
1088
- extrapolateBasicSliding (result , horizon , blockSize , queryPoint , missingIndexes );
1099
+ extrapolateBasicSliding (result , horizon , blockSize , queryPoint , missingIndexes , centrality );
1089
1100
}
1090
1101
1091
1102
return result ;
1092
1103
}
1093
1104
1105
+ // external management of shingle; can function for both internal and external
1106
+ // shingling
1107
+ // however blocksize has to be externally managed
1108
+ public RangeVector extrapolateFromShingle (float [] shingle , int horizon , int blockSize , double centrality ) {
1109
+ return extrapolateWithRanges (shingle , horizon , blockSize , isRotationEnabled (),
1110
+ ((int ) nextSequenceIndex ()) % shingleSize , centrality );
1111
+ }
1112
+
1094
1113
/**
1095
1114
* Given an initial shingled point, extrapolate the stream into the future to
1096
1115
* produce a forecast. This method is intended to be called when the input data
@@ -1130,7 +1149,8 @@ public double[] extrapolateBasic(ShingleBuilder builder, int horizon) {
1130
1149
builder .getShingleIndex ());
1131
1150
}
1132
1151
1133
- void extrapolateBasicSliding (float [] result , int horizon , int blockSize , float [] queryPoint , int [] missingIndexes ) {
1152
+ void extrapolateBasicSliding (RangeVector result , int horizon , int blockSize , float [] queryPoint ,
1153
+ int [] missingIndexes , double centrality ) {
1134
1154
int resultIndex = 0 ;
1135
1155
1136
1156
Arrays .fill (missingIndexes , 0 );
@@ -1142,16 +1162,20 @@ void extrapolateBasicSliding(float[] result, int horizon, int blockSize, float[]
1142
1162
// shift all entries in the query point left by 1 block
1143
1163
System .arraycopy (queryPoint , blockSize , queryPoint , 0 , dimensions - blockSize );
1144
1164
1145
- float [] imputedPoint = imputeMissingValues (queryPoint , blockSize , missingIndexes );
1165
+ SampleSummary imputedSummary = getConditionalFieldSummary (queryPoint , blockSize , missingIndexes ,
1166
+ centrality );
1146
1167
for (int y = 0 ; y < blockSize ; y ++) {
1147
- result [resultIndex ++] = queryPoint [dimensions - blockSize + y ] = imputedPoint [dimensions - blockSize
1148
- + y ];
1168
+ result .values [resultIndex ] = queryPoint [dimensions - blockSize + y ] = imputedSummary .median [dimensions
1169
+ - blockSize + y ];
1170
+ result .lower [resultIndex ] = imputedSummary .lower [dimensions - blockSize + y ];
1171
+ result .upper [resultIndex ] = imputedSummary .upper [dimensions - blockSize + y ];
1172
+ resultIndex ++;
1149
1173
}
1150
1174
}
1151
1175
}
1152
1176
1153
- void extrapolateBasicCyclic (float [] result , int horizon , int blockSize , int shingleIndex , float [] queryPoint ,
1154
- int [] missingIndexes ) {
1177
+ void extrapolateBasicCyclic (RangeVector result , int horizon , int blockSize , int shingleIndex , float [] queryPoint ,
1178
+ int [] missingIndexes , double centrality ) {
1155
1179
1156
1180
int resultIndex = 0 ;
1157
1181
int currentPosition = shingleIndex ;
@@ -1162,11 +1186,15 @@ void extrapolateBasicCyclic(float[] result, int horizon, int blockSize, int shin
1162
1186
missingIndexes [y ] = (currentPosition + y ) % dimensions ;
1163
1187
}
1164
1188
1165
- float [] imputedPoint = imputeMissingValues (queryPoint , blockSize , missingIndexes );
1189
+ SampleSummary imputedSummary = getConditionalFieldSummary (queryPoint , blockSize , missingIndexes ,
1190
+ centrality );
1166
1191
1167
1192
for (int y = 0 ; y < blockSize ; y ++) {
1168
- result [resultIndex ++] = queryPoint [(currentPosition + y )
1169
- % dimensions ] = imputedPoint [(currentPosition + y ) % dimensions ];
1193
+ result .values [resultIndex ] = queryPoint [(currentPosition + y )
1194
+ % dimensions ] = imputedSummary .median [(currentPosition + y ) % dimensions ];
1195
+ result .lower [resultIndex ] = imputedSummary .lower [(currentPosition + y ) % dimensions ];
1196
+ result .upper [resultIndex ] = imputedSummary .upper [(currentPosition + y ) % dimensions ];
1197
+ resultIndex ++;
1170
1198
}
1171
1199
1172
1200
currentPosition = (currentPosition + blockSize ) % dimensions ;
0 commit comments