All examples
Machine learning

Compare energy predictors on unseen buildings

Register a typed prediction function, fit two Ridge models and return paired energy predictions for held out buildings.

agent_energy_comparison.aner
// Run from the source root with local Ollama and qwen2.5:14b-instruct.
// The public fixture withholds energy for every observation in B25 through B30.
// %% prepare
import aner.agent
import aner.llm
import aner.data
import aner.ml
import aner.tensor

fn predict_energy(model: FittedRidge, observations: AdaptiveFrame) -> ContextPrediction {
    return model.predict(observations)
}

fn show_predictions(label: String, forecast: ContextPrediction) -> Unit {
    print(label)
    print(forecast.unit())
    let values = forecast.values()
    for index in Range(values.rows()) {
        print(forecast.row_id(index))
        print(values.value(index, 0))
    }
}

let schema = data.schema()
    .column("row_id", "Int64", false)
    .column("building_id", "String", false)
    .column("temperature", "Float64", false)
    .column("occupancy", "Float64", false)
    .column("heating_gap", "Float64", false)
    .column("energy", "Float64", true)
let table = data.scan_csv("examples/fixtures/contextual/energy_comparison.csv", schema, "NA").collect(400, 1048576, 16)
let frame = data.frame(table, "row_id", "building_id", "energy", List("", "", "degC", "1", "K", "kWh"))
let training = List("B01", "B02", "B03", "B04", "B05", "B06", "B07", "B08", "B09", "B10", "B11", "B12",
                    "B13", "B14", "B15", "B16", "B17", "B18", "B19", "B20", "B21", "B22", "B23", "B24")
let unseen = List("B25", "B26", "B27", "B28", "B29", "B30")
let weather = frame.select(List("temperature", "energy")).partition_groups(training, List(), unseen)
let occupancy = frame.select(List("temperature", "occupancy", "heating_gap", "energy")).partition_groups(training, List(), unseen)
let plan = ml.ridge(alpha: 1.0, standardize: true)
let weather_cv = plan.cross_validate(weather.train(), folds: 4, seed: 401)
let occupancy_cv = plan.cross_validate(occupancy.train(), folds: 4, seed: 401)
print("Grouped development RMSE (weather, occupancy)")
for fold in Range(4) {
    print(cast<Float64>(weather_cv.get(fold)))
    print(cast<Float64>(occupancy_cv.get(fold)))
}
let simple_fit = plan.fit(weather.train())
let richer_fit = plan.fit(occupancy.train())

// %% direct
let weather_direct = predict_energy(simple_fit, weather.test().features())
let occupancy_direct = predict_energy(richer_fit, occupancy.test().features())

// %% register
let tool = agent.register_tool(predict_energy, "read_only")
let client = llm.client(provider: "ollama", model: "qwen2.5:14b-instruct", endpoint: "http://127.0.0.1:11434", timeout_ms: 120000)

// %% propose_weather
let weather_turn = llm.tool_turn(client, tool, "unseen_weather", "Call predict_energy for the exact scope unseen_weather.")
print(weather_turn.text())

// %% dispatch_weather
let weather_agent = agent.call_tool(tool, weather_turn, "unseen_weather", simple_fit, weather.test().features())

// %% propose_occupancy
let occupancy_turn = llm.tool_turn(client, tool, "unseen_occupancy", "Call predict_energy for the exact scope unseen_occupancy.")
print(occupancy_turn.text())

// %% dispatch_occupancy
let occupancy_agent = agent.call_tool(tool, occupancy_turn, "unseen_occupancy", richer_fit, occupancy.test().features())

// %% observations
show_predictions("weather direct", weather_direct)
show_predictions("occupancy direct", occupancy_direct)
show_predictions("weather agent", weather_agent)
show_predictions("occupancy agent", occupancy_agent)

Make it your experiment.

Use Aner 0.1.2 or newer. Save this program as examples/agent_energy_comparison.aner inside a folder for your experiment. Open a terminal in that folder, then check and run the program.

Terminal
aner check examples/agent_energy_comparison.aner
aner run examples/agent_energy_comparison.aner

The aner command must be on your PATH. Follow the installation guide if your terminal cannot find it.

Use Aner 0.1.2 with the installed local Ollama model shown below. Save the public CSV as examples/fixtures/contextual/energy_comparison.csv and run from the project root. The final rows contain predictors and building identities only.

Credential setup
ollama show qwen2.5:14b-instruct
aner run examples/agent_energy_comparison.aner --prod

Bundled datasets retain their own source attribution and license notices. Example outcomes are not comparative benchmarks or evidence of clinical validity.

Dataset sources & attribution
Install Aner