コード例 #1
0
import matplotlib.pyplot as plt
from Timer import Timer
import lmfit

# Construct discretized domain object for hybrid model
domain = Domain(name='Domain')
domain.add_axis(x_min=5,
                x_max=100,
                m=30,
                disc_by='FeretMean',
                name='FeretMean')

# Create data-set and set up data-shuffler
data = Data(case_id='Laboratory lactose case study')
data.load_from_pickle(
    'C:/Users/rfjoni/PycharmProjects/ParticleModel/projects/CACE_cases/CACE_lactose_study/lactose'
)
data.batches[2].batch_id = 'Batch 1'
data.batches[3].batch_id = 'Batch 2'

# Convert time and temperature data to polynomial fit
# Batch 1
t_batch1 = [
    (measurement.time - data.batches[2].measurements[0].time).total_seconds()
    for measurement in data.batches[2].measurements
]
T_batch1 = [
    measurement.external_sensors[2].value
    for measurement in data.batches[2].measurements
]
Tfunc_batch1 = np.polyfit(t_batch1, T_batch1, deg=3)
コード例 #2
0
# Define model system
system = System(case="Laboratory lactose case study", domain=domain, ode_settings=ode_settings,
                loss_settings=loss_settings, rate_settings=rate_settings, dilution=False,
                regularization=1, normalize=True)

# Adding sensors
system.add_sensor(name='Temperature', measured=True, controlled=True, unit='C')
system.add_sensor(name='Concentration', measured=True, controlled=False, unit='g/µL')

# Activate phenomena
system.activate_phenomena(['nucleation', 'growth'])

# Create data-set and set up data-shuffler
data = Data(case_id='Demo data')
data.load_from_pickle('demo_data')
time_series_pair = TimeSeriesPair(data=data, system=system)

# Split training and validation data
data.set_batch_pool(pool_batch_id=['Demo batch 0', 'Demo batch 1', 'Demo batch 2', 'Demo batch 3'], pool_type='Training')
data.set_batch_pool(pool_batch_id=['Demo batch 4', 'Demo batch 5', 'Demo batch 6', 'Demo batch 7', 'Demo batch 8', 'Demo batch 9'], pool_type='Validation')
data.set_batch_pool(pool_batch_id=['Demo batch 4'], pool_type='Test')

# Set up hybrid training model
hybrid_model = HybridModel(system=system)

# Compile hybrid model
hybrid_model.training_model.compile(loss=hybrid_model.loss_model.loss, optimizer='Adam')

# Generate shuffled training and evaluation data
training_data = time_series_pair.shuffle(pool_type=['Training'], delta_t_critical=20*60)