Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Microsoft.ML.CpuMath/ProbabilityFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public static double Erfinv(double x)
/// <returns>One intepretation is, the value at which the standard normal CDF evaluates to p.</returns>
public static double Probit(double p)
{
Contracts.CheckParam(0 <= p && p <= 1, nameof(p), "Input probability should be in range 0 to 1.");

double q = p - 0.5;
double r = 0.0;
if (Math.Abs(q) <= 0.425)
Expand All @@ -135,8 +137,6 @@ public static double Probit(double p)
else
r = 1 - p;

Contracts.CheckParam(r >= 0, nameof(p), "Illegal input value");

r = Math.Sqrt(-Math.Log(r));
double retval = 0.0;
if (r < 5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public IDataView FilterByKeyColumnFraction(IDataView input, string columnName, d

var type = input.Schema[columnName].Type;
if (type.GetKeyCount() == 0)
throw Environment.ExceptSchemaMismatch(nameof(columnName), "filter", columnName, "a known cardinality key", type.ToString());
throw Environment.ExceptSchemaMismatch(nameof(columnName), "filter", columnName, "KeyType", type.ToString());
return new RangeFilter(Environment, input, columnName, lowerBound, upperBound, false);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.Data/DataView/TypedCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private TypedCursorable(IHostEnvironment env, IDataView data, bool ignoreMissing
{
if (ignoreMissingColumns)
continue;
throw _host.Except("Column '{0}' not found in the data view", col.ColumnName);
throw _host.ExceptSchemaMismatch(nameof(_data.Schema), "", col.ColumnName);
}
var realColType = _data.Schema[colIndex].Type;
if (!IsCompatibleType(realColType, col.MemberInfo))
Expand Down
12 changes: 6 additions & 6 deletions src/Microsoft.ML.Data/Evaluators/AnomalyDetectionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
var t = score.Type;
if (t != NumberType.Float)
throw Host.Except("Score column '{0}' has type '{1}' but must be R4", score, t).MarkSensitive(MessageSensitivity.Schema);
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "float", t.ToString());
Host.Check(schema.Label.HasValue, "Could not find the label column");
t = schema.Label.Value.Type;
if (t != NumberType.Float && t.GetKeyCount() != 2)
throw Host.Except("Label column '{0}' has type '{1}' but must be R4 or a 2-value key", schema.Label.Value.Name, t).MarkSensitive(MessageSensitivity.Schema);
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float or a KeyType with cardinality 2", t.ToString());
}

private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)
Expand Down Expand Up @@ -631,13 +631,13 @@ private protected override void PrintFoldResultsCore(IChannel ch, Dictionary<str
{
int index;
if (!top.Schema.TryGetColumnIndex(AnomalyDetectionEvaluator.TopKResultsColumns.Instance, out index))
throw Host.Except("Data view does not contain the 'Instance' column");
throw Host.ExceptSchemaMismatch(nameof(top.Schema), "instance", AnomalyDetectionEvaluator.TopKResultsColumns.Instance);
var instanceGetter = cursor.GetGetter<ReadOnlyMemory<char>>(index);
if (!top.Schema.TryGetColumnIndex(AnomalyDetectionEvaluator.TopKResultsColumns.AnomalyScore, out index))
throw Host.Except("Data view does not contain the 'Anomaly Score' column");
Copy link
Member

@sfilipi sfilipi Jan 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anomaly Score' [](start = 71, length = 14)

some people would get picky about the capitalization :)
Does the exception handler change everything to lowercase? #Pending

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it changes to lowercase.

However, the second argument of ExceptSchemaMismatch is string columnRole and the message becomes:
return $"Could not find {columnRole} column '{columnName}'";

So columnRole only serves the purpose of qualifying "column", while the parameter columnName will give the exact name. That's why I have made it lowercase everywhere.


In reply to: 250474268 [](ancestors = 250474268)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference would be to leave the column names as-is unless we are updating this everywhere (everywhere being any place that we refer to a specific column name.)


In reply to: 250823347 [](ancestors = 250823347,250474268)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the column does not include a space, so the current parameter columnRole is already not matching the actual column name. As you see in my version, I include both the parameter column role which is a description of the role of the column "anomaly score", and the actual column name AnomalyDetectionEvaluator.TopKResultsColumns.AnomalyScore as part of the exception message.


In reply to: 251125939 [](ancestors = 251125939,250823347,250474268)

Copy link
Contributor

@TomFinley TomFinley Jan 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this is meant to be human readable. What @Zruty0 was doing was trying to unify the error messages, I believe. And they were things like "the label column named 'Bubba' should be like this" or "the score column named 'Bizblam' should be like that," and whatnot. So I think the lowercase names for these roles specifically is appropriate, since it is just meant to be a textual message read and understood by a human.

For that same reason, I'm not too worried about these little strings everywhere. Considering that we have hundreds, possibly thousands of hand-written error messages, this seems fairly minor. So I'm not sure the situation requires something as elaborate as yet-another-static-class-full-of-strings. (I feel differently about something like MetadataUtils.Kinds where correctness of algorithms is at stake if we get those wrong.) At a certain point these things lend less clarity, not more, I think? #Resolved

throw Host.ExceptSchemaMismatch(nameof(top.Schema), "anomaly score", AnomalyDetectionEvaluator.TopKResultsColumns.AnomalyScore);
var scoreGetter = cursor.GetGetter<Single>(index);
if (!top.Schema.TryGetColumnIndex(AnomalyDetectionEvaluator.TopKResultsColumns.Label, out index))
throw Host.Except("Data view does not contain the 'Label' column");
throw Host.ExceptSchemaMismatch(nameof(top.Schema), "label", AnomalyDetectionEvaluator.TopKResultsColumns.Label);
var labelGetter = cursor.GetGetter<Single>(index);

bool hasRows = false;
Expand Down Expand Up @@ -671,7 +671,7 @@ private protected override void PrintFoldResultsCore(IChannel ch, Dictionary<str
// Find the number of anomalies, and the thresholds.
int numAnomIndex;
if (!overall.Schema.TryGetColumnIndex(AnomalyDetectionEvaluator.OverallMetrics.NumAnomalies, out numAnomIndex))
throw Host.Except("Could not find the 'NumAnomalies' column");
throw Host.ExceptSchemaMismatch(nameof(overall.Schema), "number of anomalies", AnomalyDetectionEvaluator.OverallMetrics.NumAnomalies);

int stratCol;
var hasStrat = overall.Schema.TryGetColumnIndex(MetricKinds.ColumnNames.StratCol, out stratCol);
Expand Down
12 changes: 6 additions & 6 deletions src/Microsoft.ML.Data/Evaluators/BinaryClassifierEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
var host = Host.SchemaSensitive();
var t = score.Type;
if (t != NumberType.Float)
throw host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "R4", t.ToString());
throw host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "float", t.ToString());
host.Check(schema.Label.HasValue, "Could not find the label column");
t = schema.Label.Value.Type;
if (t != NumberType.R4 && t != NumberType.R8 && t != BoolType.Instance && t.GetKeyCount() != 2)
throw host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "R4, R8, BL or a 2-value key", t.ToString());
throw host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float, double, bool, or a KeyType with cardinality 2", t.ToString());
}

private protected override void CheckCustomColumnTypesCore(RoleMappedSchema schema)
Expand All @@ -145,7 +145,7 @@ private protected override void CheckCustomColumnTypesCore(RoleMappedSchema sche
host.CheckParam(prob.Count == 1, nameof(schema), "Cannot have multiple probability columns");
var probType = prob[0].Type;
if (probType != NumberType.Float)
throw host.ExceptSchemaMismatch(nameof(schema), "probability", prob[0].Name, "R4", probType.ToString());
throw host.ExceptSchemaMismatch(nameof(schema), "probability", prob[0].Name, "float", probType.ToString());
}
else if (!_useRaw)
{
Expand Down Expand Up @@ -1098,18 +1098,18 @@ private void CheckInputColumnTypes(Schema schema)

var t = schema[(int)LabelIndex].Type;
if (t != NumberType.R4 && t != NumberType.R8 && t != BoolType.Instance && t.GetKeyCount() != 2)
throw Host.Except("Label column '{0}' has type '{1}' but must be R4, R8, BL or a 2-value key", LabelCol, t);
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "float, double, bool or a KeyType with cardinality 2", t.ToString());

t = schema[ScoreIndex].Type;
if (t != NumberType.Float)
throw Host.Except("Score column '{0}' has type '{1}' but must be R4", ScoreCol, t);
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "float", t.ToString());

if (_probIndex >= 0)
{
Host.Assert(!string.IsNullOrEmpty(_probCol));
t = schema[_probIndex].Type;
if (t != NumberType.Float)
throw Host.Except("Probability column '{0}' has type '{1}' but must be R4", _probCol, t);
throw Host.ExceptSchemaMismatch(nameof(schema), "probability", _probCol, "float", t.ToString());
}
else if (!_useRaw)
throw Host.Except("Cannot compute the predicted label from the probability column because it does not exist");
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.ML.Data/Evaluators/ClusteringEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
if (type != null && type != NumberType.Float && !(type is KeyType keyType && keyType.Count > 0))
{
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name,
"R4 or key of known cardinality", type.ToString());
"float or KeyType", type.ToString());
}

var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
type = score.Type;
if (!(type is VectorType vectorType) || !vectorType.IsKnownSize || vectorType.ItemType != NumberType.Float)
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "R4 vector of known size", type.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "known-size vector of float", type.ToString());
}

private protected override void CheckCustomColumnTypesCore(RoleMappedSchema schema)
Expand Down Expand Up @@ -754,7 +754,7 @@ private void CheckInputColumnTypes(Schema schema)

var type = schema[(int) ScoreIndex].Type;
if (!(type is VectorType vectorType) || !vectorType.IsKnownSize || vectorType.ItemType != NumberType.Float)
throw Host.Except("Score column '{0}' has type {1}, but must be a float vector of known-size", ScoreCol, type);
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "known-size vector of float", type.ToString());
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.ML.Data/Evaluators/EvaluatorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ protected PerInstanceEvaluatorBase(IHostEnvironment env, Schema schema, string s
LabelCol = labelCol;

if (!string.IsNullOrEmpty(LabelCol) && !schema.TryGetColumnIndex(LabelCol, out LabelIndex))
throw Host.Except("Did not find the label column '{0}'", LabelCol);
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol);
if (!schema.TryGetColumnIndex(ScoreCol, out ScoreIndex))
throw Host.Except("Did not find column '{0}'", ScoreCol);
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol);
}

protected PerInstanceEvaluatorBase(IHostEnvironment env, ModelLoadContext ctx, Schema schema)
Expand All @@ -502,9 +502,9 @@ protected PerInstanceEvaluatorBase(IHostEnvironment env, ModelLoadContext ctx,
ScoreCol = ctx.LoadNonEmptyString();
LabelCol = ctx.LoadStringOrNull();
if (!string.IsNullOrEmpty(LabelCol) && !schema.TryGetColumnIndex(LabelCol, out LabelIndex))
throw Host.Except($"Did not find the label column '{LabelCol}'");
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol);
if (!schema.TryGetColumnIndex(ScoreCol, out ScoreIndex))
throw Host.Except($"Did not find column '{ScoreCol}'");
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol);
}

public virtual void Save(ModelSaveContext ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
var scoreType = score.Type as VectorType;
if (scoreType == null || scoreType.Size < 2 || scoreType.ItemType != NumberType.Float)
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "vector of two or more items of type R4", scoreType.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "vector of two or more items of type float", scoreType.ToString());
Host.CheckParam(schema.Label.HasValue, nameof(schema), "Could not find the label column");
var labelType = schema.Label.Value.Type;
if (labelType != NumberType.Float && labelType.GetKeyCount() <= 0)
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float or a known-cardinality key", labelType.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float or KeyType", labelType.ToString());
}

private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)
Expand Down Expand Up @@ -815,10 +815,10 @@ private void CheckInputColumnTypes(Schema schema)

var scoreType = schema[ScoreIndex].Type as VectorType;
if (scoreType == null || scoreType.Size < 2 || scoreType.ItemType != NumberType.Float)
throw Host.Except("Score column '{0}' has type '{1}' but must be a vector of two or more items of type R4", ScoreCol, scoreType);
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "vector of two or more items of type float", scoreType.ToString());
var labelType = schema[LabelIndex].Type;
if (labelType != NumberType.Float && labelType.GetKeyCount() <= 0)
throw Host.Except("Label column '{0}' has type '{1}' but must be a float or a known-cardinality key", LabelCol, labelType);
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "float or KeyType", labelType.ToString());
}
}

Expand Down Expand Up @@ -1000,7 +1000,7 @@ private protected override IDataView GetPerInstanceMetricsCore(IDataView perInst
// text file, since if there are different key counts the columns cannot be appended.
string labelName = schema.Label.Value.Name;
if (!perInst.Schema.TryGetColumnIndex(labelName, out int labelCol))
throw Host.Except("Could not find column '{0}'", labelName);
throw Host.ExceptSchemaMismatch(nameof(schema), "label", labelName);
var labelType = perInst.Schema[labelCol].Type;
if (labelType is KeyType keyType && (!perInst.Schema[labelCol].HasKeyValues(keyType) || labelType.RawType != typeof(uint)))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
var t = score.Type as VectorType;
if (t == null || !t.IsKnownSize || t.ItemType != NumberType.Float)
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "known size vector of R4", t.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "known-size vector of float", t.ToString());
Host.Check(schema.Label.HasValue, "Could not find the label column");
t = schema.Label.Value.Type as VectorType;
if (t == null || !t.IsKnownSize || (t.ItemType != NumberType.R4 && t.ItemType != NumberType.R8))
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "known size vector of R4 or R8", t.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "known-size vector of float or double", t.ToString());
}

private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)
Expand Down Expand Up @@ -548,7 +548,7 @@ private void CheckInputColumnTypes(Schema schema, out VectorType labelType, out

var t = schema[LabelIndex].Type as VectorType;
if (t == null || !t.IsKnownSize || (t.ItemType != NumberType.R4 && t.ItemType != NumberType.R8))
throw Host.Except("Label column '{0}' has type '{1}' but must be a known-size vector of R4 or R8", LabelCol, t);
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "known-size vector of float or double", t.ToString());
labelType = new VectorType((PrimitiveType)t.ItemType, t.Size);
var slotNamesType = new VectorType(TextType.Instance, t.Size);
var builder = new MetadataBuilder();
Expand All @@ -557,7 +557,7 @@ private void CheckInputColumnTypes(Schema schema, out VectorType labelType, out

t = schema[ScoreIndex].Type as VectorType;
if (t == null || !t.IsKnownSize || t.ItemType != NumberType.Float)
throw Host.Except("Score column '{0}' has type '{1}' but must be a known length vector of type R4", ScoreCol, t);
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "known-size vector of float", t.ToString());
scoreType = new VectorType((PrimitiveType)t.ItemType, t.Size);
builder = new MetadataBuilder();
builder.AddSlotNames(t.Size, CreateSlotNamesGetter(schema, ScoreIndex, scoreType.Size, "Predicted"));
Expand Down
10 changes: 5 additions & 5 deletions src/Microsoft.ML.Data/Evaluators/QuantileRegressionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
var t = score.Type as VectorType;
if (t == null || t.Size == 0 || (t.ItemType != NumberType.R4 && t.ItemType != NumberType.R8))
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "vector of type R4 or R8", t.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "vector of float or double", t.ToString());
Host.CheckParam(schema.Label.HasValue, nameof(schema), "Must contain a label column");
var labelType = schema.Label.Value.Type;
if (labelType != NumberType.R4)
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "R4", t.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float", t.ToString());
}

private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)
Expand Down Expand Up @@ -446,13 +446,13 @@ private void CheckInputColumnTypes(Schema schema)

var t = schema[(int)LabelIndex].Type;
if (t != NumberType.R4)
throw Host.Except("Label column '{0}' has type '{1}' but must be R4", LabelCol, t);
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "float", t.ToString());

VectorType scoreType = schema[ScoreIndex].Type as VectorType;
if (scoreType == null || scoreType.Size == 0 || (scoreType.ItemType != NumberType.R4 && scoreType.ItemType != NumberType.R8))
{
throw Host.Except(
"Score column '{0}' has type '{1}' but must be a known length vector of type R4 or R8", ScoreCol, t);
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "known-size vector of float or double", t.ToString());

}
}
}
Expand Down
Loading