Skip to content

feat: support starting index in CultivationPropagationModel prediction - #10

Merged
tc-mateus merged 1 commit into
DataHow:mainfrom
wclaus22:feat/starting-index
May 9, 2025
Merged

tc-mateus merged 1 commit into
DataHow:mainfrom
wclaus22:feat/starting-index

Conversation

@wclaus22

@wclaus22 wclaus22 commented Feb 6, 2025

Copy link
Copy Markdown

Overview

To enable the prediction using the startingIndex functionality, I needed to add the steps to the prediction request formatted in the CultivationPropagationPreprocessor, the steps are simply generated from the timestamps

the validations stay the same, ultimately the users only have to specify the starting_index in the PredictionConfig that is an input to the model.predict method:

key = APIKeyAuthentication(API_KEY)
client = DataHowLabClient(
    auth_key=key, base_url="https://dev.datahowlab.ch/", verify_ssl=False
)

projects = client.get_projects(name="testytest")
project = next(projects)

models = project.get_models(name="Model #1", model_type="propagation")
model = next(models)

# prepare the inputs, timestamps and so on, in the same way as before

# starting index will place the defined starting values for the X variables at the right timestamp
response = model.predict(
    timestamps=timestamps, inputs=inputs, config=PredictionConfig(starting_index=9)
)

in the returned dict from the predict function, the timestamps will be listed and where no prediction happened null will appear, while after the defined starting_index the predicted X variables will start to appear:

{
  "VCD": {
          "values": [
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              2.879112482070923,
              2.4005997326441006,
              1.9871806082628867,
              1.681387192593827,
              1.4050851085900333,
              1.194962512785351
          ],
          "upperBound": [
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              2.879112482070923,
              2.493029799377218,
              2.120593437479122,
              1.8562090157041424,
              1.6714378289059812,
              1.4606777007638796
          ],
          "lowerBound": [
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              null,
              2.879112482070923,
              2.3057709871156935,
              1.8248368874560694,
              1.4678880165432826,
              1.1231916636850299,
              0.8331586939798415
          ]
      }
}

Main Changes

_input_processing.CultivationPropagationPreprocessor

  • validate: I had to introduce in the validation for cultivation propagation models a check that the starting_index is within the length of the defined timestamps
  • format: here is the arguably largest change: include a step for each timestamp (its just needed to align the initial X variables with the correct timestamp) and differentiate between non-X variables and X variables to make that alignment using the self.prediction_config.starting_index

_utils.Instance

  • I had to enable the presence of nulls in the parsed instance data (specifically inside values) to allow all the resulting X variable outputs to be null before the starting index (otherwise we can also find a way to truncate this output but this is a first proposition which I find quite elegant)

entities.CultivationPropagationModel

  • I added the starting_index coming from the PredictionConfig to the PredictionRequestConfig.new constructor s.t. everything is properly hooked up on the frontend of the SDK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants