Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/LoopAlgorithm/AlgorithmInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public protocol AlgorithmInput {
var emulation: AlgorithmEmulationOptions? { get } // Defaults to nil (no emulation)
/// Optional algorithm experiments; the empty set is standard LoopAlgorithm. Conforming types that do
/// not provide it get the empty set.
var experiments: Set<AlgorithmExperiment> { get }
var experiments: Set<ExperimentOption> { get }
/// The person's volatility baseline for the `guardAndRunway` experiment's volatility band: the median
/// σ5 (mg/dL per 5 min) over their last four weeks of glucose, from `GlucoseVolatility.baseline(_:)`.
/// When nil it is computed from `glucoseHistory` if that holds at least a day of readings; otherwise
Expand All @@ -47,6 +47,6 @@ public protocol AlgorithmInput {

public extension AlgorithmInput {
var emulation: AlgorithmEmulationOptions? { nil }
var experiments: Set<AlgorithmExperiment> { [] }
var experiments: Set<ExperimentOption> { [] }
var volatilityBaseline: Double? { nil }
}
4 changes: 2 additions & 2 deletions Sources/LoopAlgorithm/AlgorithmInputFixture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public struct AlgorithmInputFixture: AlgorithmInput {
public var gradualTransitionsThreshold: Double?
public var emulation: AlgorithmEmulationOptions?
/// Optional experiments; absent in existing fixtures, which therefore run standard LoopAlgorithm.
public var experiments: Set<AlgorithmExperiment> = []
public var experiments: Set<ExperimentOption> = []
public var volatilityBaseline: Double?

public var recommendationInsulinModel: InsulinModel {
Expand Down Expand Up @@ -155,7 +155,7 @@ extension AlgorithmInputFixture: Codable {
self.automaticBolusApplicationFactor = try container.decodeIfPresent(Double.self, forKey: .automaticBolusApplicationFactor)
self.gradualTransitionsThreshold = try container.decodeIfPresent(Double.self, forKey: .gradualTransitionsThreshold) ?? 40.0
self.emulation = try container.decodeIfPresent(AlgorithmEmulationOptions.self, forKey: .emulation)
self.experiments = Set(try container.decodeIfPresent([AlgorithmExperiment].self, forKey: .experiments) ?? [])
self.experiments = Set(try container.decodeIfPresent([ExperimentOption].self, forKey: .experiments) ?? [])
self.volatilityBaseline = try container.decodeIfPresent(Double.self, forKey: .volatilityBaseline)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/LoopAlgorithm/Experiments/AlgorithmExperiments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
/// Each experiment is an on/off switch with no tunable parameters, so that people who choose the same
/// switches pool into one group whose results can be compared. Experiments combine: each acts on its own
/// part of the algorithm, and a combination is its own group.
public enum AlgorithmExperiment: String, Codable, CaseIterable, Sendable {
public enum ExperimentOption: String, Codable, CaseIterable, Sendable {

/// LoopEval guard + runway (C20 + C29 + C40). A lows guard, plus a little more correction when there
/// is room for it:
Expand Down Expand Up @@ -71,7 +71,7 @@ struct ExperimentParameters: Equatable {

/// `volatilityBaseline` is the person's median σ5 (mg/dL per 5 min); only the band uses it.
/// Integral RC and the glucose-based application factor are switched where they act, not here.
init(experiments: Set<AlgorithmExperiment>, volatilityBaseline: Double?) {
init(experiments: Set<ExperimentOption>, volatilityBaseline: Double?) {
if experiments.contains(.guardAndRunway) {
postLowRiseCut = PostLowRiseCut()
runwayReserve = RunwayReserve()
Expand Down
2 changes: 1 addition & 1 deletion Sources/LoopAlgorithm/LoopAlgorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public struct LoopAlgorithm {
gradualTransitionsThreshold: Double? = 40.0,
momentumVelocityMaximum: LoopQuantity? = nil,
emulation: AlgorithmEmulationOptions = AlgorithmEmulationOptions(),
experiments: Set<AlgorithmExperiment> = []
experiments: Set<ExperimentOption> = []
) -> LoopPrediction<CarbType> where CarbType: CarbEntry, GlucoseType: GlucoseSampleValue, InsulinDoseType: InsulinDose {

var prediction: [PredictedGlucoseValue] = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class IntegralRetrospectiveCorrection: RetrospectiveCorrection {
var currentDate: Date = Date()

/// Experimental weight on the correction while the current discrepancy is positive (rising), set by
/// the post-low rise-cut (see `AlgorithmExperiment`). 1.0 is standard IRC.
/// the post-low rise-cut (see `ExperimentOption`). 1.0 is standard IRC.
let riseScale: Double

public init(effectDuration: TimeInterval,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class StandardRetrospectiveCorrection: RetrospectiveCorrection {
private let unit = LoopUnit.milligramsPerDeciliter

/// Experimental weight on a positive (rising) discrepancy, set by the post-low rise-cut (see
/// `AlgorithmExperiment`). 1.0 is standard RC.
/// `ExperimentOption`). 1.0 is standard RC.
let riseScale: Double

public init(effectDuration: TimeInterval, useLegacyDecay: Bool = false, riseScale: Double = 1.0) {
Expand Down
2 changes: 1 addition & 1 deletion Tests/LoopAlgorithmTests/AlgorithmExperimentsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ final class AlgorithmExperimentsTests: XCTestCase {
let back = try decoder.decode(AlgorithmInputFixture.self, from: encoder.encode(input))
XCTAssertEqual(back.experiments, [.guardAndRunway])
XCTAssertEqual(back.volatilityBaseline, 4.2)
XCTAssertEqual(AlgorithmExperiment.allCases, [.guardAndRunway, .integralRetrospectiveCorrection, .glucoseBasedApplicationFactor])
XCTAssertEqual(ExperimentOption.allCases, [.guardAndRunway, .integralRetrospectiveCorrection, .glucoseBasedApplicationFactor])
}

func testFixtureRoundTripCarriesACombination() throws {
Expand Down