|
1 |
| -# ApplicationDrivenLearning.jl |
| 1 | +# ApplicationDrivenLearning.jl |
| 2 | + |
| 3 | +ApplicationDrivenLearning.jl is a Julia package for training time series models using the application driven learning framework, that connects the optimization problem final cost with predictive model parameters in order to achieve the best model for a given application. |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +```julia |
| 8 | +import Pkg |
| 9 | + |
| 10 | +Pkg.add("ApplicationDrivenLearning") # not working yet! clone the repo instead |
| 11 | + |
| 12 | +using ApplicationDrivenLearning |
| 13 | + |
| 14 | +## Single power plan problem |
| 15 | + |
| 16 | +# data |
| 17 | +X = reshape([1 1], (2, 1)) |
| 18 | +Y = reshape([0 2], (2, 1)) |
| 19 | + |
| 20 | +# main model and policy / forecast variables |
| 21 | +model = ApplicationDrivenLearning.Model() |
| 22 | +@variables(model, begin |
| 23 | + z, ApplicationDrivenLearning.Policy |
| 24 | + θ, ApplicationDrivenLearning.Forecast |
| 25 | +end) |
| 26 | + |
| 27 | +# plan model |
| 28 | +@variables(ApplicationDrivenLearning.Plan(model), begin |
| 29 | + c1 ≥ 0 |
| 30 | + c2 ≥ 0 |
| 31 | +end) |
| 32 | +@constraints(ApplicationDrivenLearning.Plan(model), begin |
| 33 | + c1 ≥ 100 * (θ.plan-z.plan) |
| 34 | + c2 ≥ 20 * (z.plan-θ.plan) |
| 35 | +end) |
| 36 | +@objective(ApplicationDrivenLearning.Plan(model), Min, 10*z.plan + c1 + c2) |
| 37 | + |
| 38 | +# assess model |
| 39 | +@variables(ApplicationDrivenLearning.Assess(model), begin |
| 40 | + c1 ≥ 0 |
| 41 | + c2 ≥ 0 |
| 42 | +end) |
| 43 | +@constraints(ApplicationDrivenLearning.Assess(model), begin |
| 44 | + c1 ≥ 100 * (θ.assess-z.assess) |
| 45 | + c2 ≥ 20 * (z.assess-θ.assess) |
| 46 | +end) |
| 47 | +@objective(ApplicationDrivenLearning.Assess(model), Min, 10*z.assess + c1 + c2) |
| 48 | + |
| 49 | +# basic setting |
| 50 | +set_optimizer(model, HiGHS.Optimizer) |
| 51 | +set_silent(model) |
| 52 | + |
| 53 | +# forecast model |
| 54 | +nn = Chain(Dense(1 => 1; bias=false)) |
| 55 | +ApplicationDrivenLearning.set_forecast_model(model, nn) |
| 56 | + |
| 57 | +# training and getting solution |
| 58 | +solution = ApplicationDrivenLearning.train!( |
| 59 | + model, |
| 60 | + X, |
| 61 | + Y, |
| 62 | + ApplicationDrivenLearning.Options( |
| 63 | + ApplicationDrivenLearning.NelderMeadMode |
| 64 | + ) |
| 65 | +) |
| 66 | +print(solution.params) |
| 67 | +``` |
| 68 | + |
| 69 | +## Installation |
| 70 | + |
| 71 | +This package is **not yet** registered so if you want to use or test the code clone this repo and include source code from `src` directory. |
| 72 | + |
| 73 | +## Contributing |
| 74 | + |
| 75 | +* PRs such as adding new models and fixing bugs are very welcome! |
| 76 | +* For nontrivial changes, you'll probably want to first discuss the changes via issue. |
0 commit comments