anomed_challenge.challenge_server
This module provides means to create web applications that host challenges at and integrates well with the AnoMed competition platform.
Your first goal should be to make use of a web app factory, e.g.
supervised_learning_MIA_challenge_server_factory, to avoid dealing with web
programming issues. If this does not suit your use case, have a look at the more
basic resource building block (e.g. StaticNumpyDataResource or
UtilityResource.)
Module Contents
Classes
A dynamic NumPy dataset resource, i.e. the specific dataset content depends on GET request parameters. |
|
Any JSON serializable object, representing a “static” resource (i.e. a resource that does not depend on request parameters). |
|
A static NumPy dataset resource, responding to GET requests. |
|
Evaluate the prediction of an estimator with respect to the ground truth and report the result statistics as a JSON string. |
Functions
A factory to create a web application object which hosts a
|
|
A factory to create a web application object which hosts a
|
API
- class anomed_challenge.challenge_server.DataReconstructionPrivacyResource(challenge_obj: anomed_challenge.challenge.TabularDataReconstructionChallenge, evaluation_submitter: Callable[[falcon.Request, dict[str, float]], None])
Initialization
- on_post(req: falcon.Request, resp: falcon.Response) None
- class anomed_challenge.challenge_server.DataReconstructionUtilityResource(challenge_obj: anomed_challenge.challenge.TabularDataReconstructionChallenge, evaluation_submitter: Callable[[falcon.Request, dict[str, float]], None])
Initialization
- on_post(req: falcon.Request, resp: falcon.Response) None
- class anomed_challenge.challenge_server.DynamicNumpyDataResource(individual_data_provider: Callable[[falcon.Request], anomed_challenge.challenge.NumpyDataset])
A dynamic NumPy dataset resource, i.e. the specific dataset content depends on GET request parameters.
The arrays (features and targets) will be serialized using
anomed_utils.named_ndarrays_to_bytesand may be de-serialized usinganomed_utils.bytes_to_named_ndarrays. The names of the arrays are ‘X’ for the features and ‘y’ for the targets.Initialization
- Parameters:
individual_data_provider (Callable[[falcon.Request], NumpyDataset]) – A function that, based on the GET request, returns a specific
NumpyDataset.
- on_get(req, resp: falcon.Response) None
- class anomed_challenge.challenge_server.StaticJSONResource(obj: Any)
Any JSON serializable object, representing a “static” resource (i.e. a resource that does not depend on request parameters).
The object will be represented as a plain JSON string, when a GET request is invoked.
Initialization
- Parameters:
obj (Any) – A JSON serializable object, i.e. is should be compatible with
json.dumps.
- on_get(_, resp: falcon.Response)
- class anomed_challenge.challenge_server.StaticNumpyDataResource(data: anomed_challenge.challenge.NumpyDataset)
A static NumPy dataset resource, responding to GET requests.
The arrays (features and targets) will be serialized using
anomed_utils.named_ndarrays_to_bytesand may be de-serialized usinganomed_utils.bytes_to_named_ndarrays. The names of the arrays are ‘X’ for the features and ‘y’ for the targets.Initialization
- on_get(_, resp: falcon.Response) None
- anomed_challenge.challenge_server.supervised_learning_MIA_challenge_server_factory(challenge_obj: anomed_challenge.challenge.SupervisedLearningMIAChallenge) falcon.App
A factory to create a web application object which hosts a
challenge.SupervisedLearningMIAChallenge, currently the most basic use case of challenges for the AnoMed competition platform.By using this factory, you don’t have to worry any web-programming issues, as they are hidden from you. The generated web app will feature the following routes:
[GET]
/[GET]
/data/anonymizer/training[GET]
/data/anonymizer/tuning[GET]
/data/anonymizer/validation[GET]
/data/deanonymizer/members[GET]
/data/deanonymizer/non-members[GET]
/data/attack-success-evaluation[POST]
/utility/anonymizer[POST]
/utility/deanonymizer
- Parameters:
challenge_obj (challenge.SupervisedLearningMIAChallenge) – A supervised learning, MIA threat model challenge object providing the necessary data and means of utility and privacy evaluation.
- Returns:
A web application object based on the falcon web framework.
- Return type:
falcon.App
- anomed_challenge.challenge_server.tabular_data_reconstruction_challenge_server_factory(challenge_obj: anomed_challenge.challenge.TabularDataReconstructionChallenge) falcon.App
A factory to create a web application object which hosts a
challenge.TabularDataReconstructionChallenge.By using this factory, you don’t have to worry any web-programming issues, as they are hidden from you. The generated web app will feature the following routes:
[GET]
/[GET]
/data/anonymizer/leaky[GET]
/data/anonymizer/background-knowledge[POST]
/utility/anonymizer[POST]
/utility/deanonymizer
- Parameters:
challenge_obj (challenge.TabularDataReconstructionChallenge) – The data reconstruction challenge to lift to a web application.
- Returns:
A web application object based on the falcon web framework, which features the supplied
challenge_obj.- Return type:
falcon.App
- class anomed_challenge.challenge_server.UtilityResource(target_data_provider: Callable[[falcon.Request], numpy.ndarray], evaluator: Callable[[numpy.ndarray, numpy.ndarray], dict[str, float]], submitter: Callable[[falcon.Request, dict[str, float]], None])
Evaluate the prediction of an estimator with respect to the ground truth and report the result statistics as a JSON string.
When receiving a POST request, extract a prediction array from the request’s body, compare it to the ground truth and report the evaluation results. The prediction array must be byte encoded compatible with
anomed_utils.bytes_to_named_ndarraysand have the name ‘prediction’. The ground truth may depend on request parameters. The evaluation metrics used, are defined at runtime.Initialization
- Parameters:
target_data_provider (Callable[[falcon.Request], np.ndarray]) – A callable returning a reference array (ground truth), depending on the request parameters. It is expected that this callable takes care of request (parameter) validation and raises a
falcon.HTTPBadRequestin case there areevaluator (Callable[[np.ndarray, np.ndarray], dict[str, float]]) – A callable comparing the prediction (first argument, extracted from the POST request) with the ground truth (second argument, provided by
target_data_provider), generating evaluation statistics (a dictionary of float values). That dictionary will be the JSON string response.submitter (Callable[falcon.Request, [dict[str, float]], None]) – A callable which will submit the statistics generated by
evaluatorto the AnoMed competition platform (where it will be persisted). It may obtain submission-critical information from the request. It is expected that the this callable raises anfalcon.HTTPInternalServerError, if the submission fails.
- on_post(req: falcon.Request, resp: falcon.Response) None
- Raises:
falcon.HTTPBadRequest – If extracting an array with name ‘prediction’ from the POST request body fails.