@@ -89,6 +89,7 @@ private protected GamModelParametersBase(IHostEnvironment env, string name,
89
89
// Check data validity
90
90
Host . CheckValue ( binEffects [ i ] , nameof ( binEffects ) , "Array contained null entries" ) ;
91
91
Host . CheckParam ( binUpperBounds [ i ] . Length == binEffects [ i ] . Length , nameof ( binEffects ) , "Array contained wrong number of effect values" ) ;
92
+ Host . CheckParam ( Utils . IsMonotonicallyIncreasing ( binUpperBounds [ i ] ) , nameof ( binUpperBounds ) , "Array must be monotonically increasing" ) ;
92
93
93
94
// Update the value at zero
94
95
_valueAtAllZero += GetBinEffect ( i , 0 , out _binsAtAllZero [ i ] ) ;
@@ -282,44 +283,74 @@ private double GetBinEffect(int featureIndex, double featureValue, out int binIn
282
283
/// Get the bin upper bounds for each feature.
283
284
/// </summary>
284
285
/// <param name="featureIndex">The index of the feature (in the training vector) to get.</param>
285
- /// <returns>The bin upper bounds. May be null if this feature has no bins.</returns>
286
- public double [ ] GetFeatureBinUpperBounds ( int featureIndex )
286
+ /// <returns>The bin upper bounds. May be zero length if this feature has no bins.</returns>
287
+ public double [ ] GetBinUpperBounds ( int featureIndex )
287
288
{
288
289
Host . Check ( 0 <= featureIndex && featureIndex < NumShapeFunctions , "Index out of range." ) ;
289
- double [ ] featureBins ;
290
- if ( _inputFeatureToShapeFunctionMap . TryGetValue ( featureIndex , out int j ) )
291
- {
292
- featureBins = new double [ _binUpperBounds [ j ] . Length ] ;
293
- _binUpperBounds [ j ] . CopyTo ( featureBins , 0 ) ;
294
- }
295
- else
290
+ if ( ! _inputFeatureToShapeFunctionMap . TryGetValue ( featureIndex , out int j ) )
291
+ return new double [ 0 ] ;
292
+
293
+ var binUpperBounds = new double [ _binUpperBounds [ j ] . Length ] ;
294
+ _binUpperBounds [ j ] . CopyTo ( binUpperBounds , 0 ) ;
295
+ return binUpperBounds ;
296
+ }
297
+
298
+ /// <summary>
299
+ /// Get all the bin upper bounds.
300
+ /// </summary>
301
+ public double [ ] [ ] GetBinUpperBounds ( )
302
+ {
303
+ double [ ] [ ] binUpperBounds = new double [ NumShapeFunctions ] [ ] ;
304
+ for ( int i = 0 ; i < NumShapeFunctions ; i ++ )
296
305
{
297
- featureBins = new double [ 0 ] ;
306
+ if ( _inputFeatureToShapeFunctionMap . TryGetValue ( i , out int j ) )
307
+ {
308
+ binUpperBounds [ i ] = new double [ _binUpperBounds [ j ] . Length ] ;
309
+ _binUpperBounds [ j ] . CopyTo ( binUpperBounds [ i ] , 0 ) ;
310
+ }
311
+ else
312
+ {
313
+ binUpperBounds [ i ] = new double [ 0 ] ;
314
+ }
298
315
}
299
-
300
- return featureBins ;
316
+ return binUpperBounds ;
301
317
}
302
318
303
319
/// <summary>
304
320
/// Get the binned weights for each feature.
305
321
/// </summary>
306
322
/// <param name="featureIndex">The index of the feature (in the training vector) to get.</param>
307
- /// <returns>The binned weights for each feature.</returns>
308
- public double [ ] GetFeatureWeights ( int featureIndex )
323
+ /// <returns>The binned effects for each feature. May be zero length if this feature has no bins .</returns>
324
+ public double [ ] GetBinEffects ( int featureIndex )
309
325
{
310
326
Host . Check ( 0 <= featureIndex && featureIndex < NumShapeFunctions , "Index out of range." ) ;
311
- double [ ] featureWeights ;
312
- if ( _inputFeatureToShapeFunctionMap . TryGetValue ( featureIndex , out int j ) )
313
- {
314
- featureWeights = new double [ _binEffects [ j ] . Length ] ;
315
- _binEffects [ j ] . CopyTo ( featureWeights , 0 ) ;
316
- }
317
- else
327
+ if ( ! _inputFeatureToShapeFunctionMap . TryGetValue ( featureIndex , out int j ) )
328
+ return new double [ 0 ] ;
329
+
330
+ var binEffects = new double [ _binEffects [ j ] . Length ] ;
331
+ _binEffects [ j ] . CopyTo ( binEffects , 0 ) ;
332
+ return binEffects ;
333
+ }
334
+
335
+ /// <summary>
336
+ /// Get all the binned effects.
337
+ /// </summary>
338
+ public double [ ] [ ] GetBinEffects ( )
339
+ {
340
+ double [ ] [ ] binEffects = new double [ NumShapeFunctions ] [ ] ;
341
+ for ( int i = 0 ; i < NumShapeFunctions ; i ++ )
318
342
{
319
- featureWeights = new double [ 0 ] ;
343
+ if ( _inputFeatureToShapeFunctionMap . TryGetValue ( i , out int j ) )
344
+ {
345
+ binEffects [ i ] = new double [ _binEffects [ j ] . Length ] ;
346
+ _binEffects [ j ] . CopyTo ( binEffects [ i ] , 0 ) ;
347
+ }
348
+ else
349
+ {
350
+ binEffects [ i ] = new double [ 0 ] ;
351
+ }
320
352
}
321
-
322
- return featureWeights ;
353
+ return binEffects ;
323
354
}
324
355
325
356
void ICanSaveInTextFormat . SaveAsText ( TextWriter writer , RoleMappedSchema schema )
0 commit comments