Interface Layer
Users will create Task
s and Metric
s (M:M relationship). An example of a Task
might be high_tip_prediction. An example of a Metric
might be accuracy. The user's code might look like this to define a Metric:
class Accuracy(Metric): # Metric is an mltrace abstract class that has abstract method compute
def __init__(self, window_size, compute_frequency):
super().__init__(name="accuracy", window_size=window_size, compute_frequency=compute_frequency)
# Stateful vars here
self.numerator = 0.0
self.denominator = 0.0
def compute(self, new_outputs, new_feedback):
self.numerator += sum(new_outputs == new_feedback)
self.denominator += len(new_outputs)
To define a Task
:
t = Task("high_tip_prediction")
t.registerMetric(Accuracy(30, 1))
t.registerMetric(Accuracy(7, 1))
""" prediction code """
t.logOutput(prediction, output_id)
t.logFeedback(label, output_id)
Execution Layer
Each metric will have a new materialized view. When a materialized view is updated, we will run the user's metric computation function and output the value to the metric_history_table
.
Storage Layer
On our end, we have 2 tables: one for outputs and one for feedback. The schema is as follows (feedback table is the same schema):
output_table = Table(
"outputs",
Base.metadata,
Column("timestamp", DateTime),
Column("identifier", String),
Column("task_name", String),
Column("value", Numeric),
Index("outputs_ts_name_asc", "timestamp", "task_name"),
Index(
"outputs_ts_name_desc",
text("timestamp DESC"),
"task_name",
),
)
We want to create triggers to these tables create materialized views to hold the relevant history for each metric. Then we need triggers that actually compute the metrics. We probably need a table to store metric values, with the following schema:
metric_history_table = Table(
"metric_history",
Base.metadata,
Column("timestamp", DateTime),
Column("metric_name", String),
Column("task_name", String),
Column("value", Numeric),
Index("ts_task_metric_asc", "timestamp", "task_name", "metric_name"),
Index(
"ts_task_metric_desc",
text("timestamp DESC"),
"task_name",
"metric_name"
),
)